Does anyone know of a freely available java 1.5 package that provides a list of ISO 3166-1 country codes as a enum or EnumMap? Specifically I need the "ISO 3166-1-alpha-2 code elements", i.e. the 2 character country code like "us", "uk", "de", etc. Creating one is simple enough (although tedious), but if there's a standard one already out there in apache land or the like it would save a little time.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
Here's how I generated an enum with country code + country name:
This still does not answer the question. I was also looking for a kind of enumerator for this, and did not find anything. Some examples using hashtable here, but represent the same as the built-in get
I would go for a different approach. So I created a script in python to automatically generate the list in Java:
where the data.txt file is a simple copy&paste from Wikipedia table (just remove all extra lines, making sure you have a country code and country name per line).
Then just place this into your static class:
There is an easy way to generate this enum with the language name. Execute this code to generate the list of enum fields to paste :
Not a java enum, but a JSON version of this is available at http://country.io/names.json
I didn't know about this question till I had just recently open-sourced my Java enum for exactly this purpose! Amazing coincidence!
I put the whole source code on my blog with BSD caluse 3 license so I don't think anyone would have any beefs about it.
Can be found here. https://subversivebytes.wordpress.com/2013/10/07/java-iso-3166-java-enum/
Hope it is useful and eases development pains.
Now an implementation of country code (ISO 3166-1 alpha-2/alpha-3/numeric) list as Java enum is available at GitHub under Apache License version 2.0.
Example:
Last Edit 2016-Jun-09
CountryCode enum was packaged into com.neovisionaries.i18n with other Java enums, LanguageCode (ISO 639-1), LanguageAlpha3Code (ISO 639-2), LocaleCode, ScriptCode (ISO 15924) and CurrencyCode (ISO 4217) and registered into the Maven Central Repository.
Maven
Gradle
GitHub
https://github.com/TakahikoKawasaki/nv-i18n
Javadoc
http://takahikokawasaki.github.com/nv-i18n/
OSGi