http://subversivebytes.wordpress.com/2013/10/07/java-iso-3166-java-enum/
http://www.skyebook.net/blog/2011/02/iso-country-codes-in-java/
https://github.com/TakahikoKawasaki/CountryCode/blob/master/CountryCode/src/CountryCode.java
http://lfhck.com/question/189249/is-there-an-open-source-java-enum-of-iso-3166-1-country-codes
https://code.google.com/p/gbif-common-resources/source/browse/gbif-api/trunk/src/main/java/org/gbif/api/vocabulary/Country.java
Having worked software development in a bank before I know how important it is to work with proper data structures and enumerations.
I had a program I needed to write where I had to utilize ISO country codes and there was a lot of interoperability work that needed to be done. So I tried looking for some basic library that had the standard ISO-3166 country codes. Couldn’t find any. I really just needed something I could look up a country code quickly and get its description. Like saving “SLV” or “222″ as a key in a database for El Salvador’s currency. Then I can retrieve it and do a look up on a table to get the country name. Or even vice-versa.
So I went “knee deep in the dead” and coded an enum for this. I used some online resources to make this work such as http://en.wikipedia.org/wiki/ISO_3166 andhttp://www.iso.org/iso/home/standards/country_codes.htm
I thought I’d share it here under BSD License so that others may find it useful.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 | /* * Copyright 2011 George El-Haddad. All rights reserved. * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, this list * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY GEORGE EL-HADDAD ''AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GEORGE EL-HADDAD OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * The views and conclusions contained in the software and documentation are those of the * authors and should not be interpreted as representing official policies, either expressed * or implied, of George El-Haddad. */ public enum ISO_3166_CountryCode { AALAND_ISLANDS("Aaland Islands", "AX", "ALA", "248"), AFGHANISTAN("Afghanistan", "AF", "AFG", "004"), ALBANIA("Albania", "AL", "ALB", "008"), ALGERIA("Algeria", "DZ", "DZA", "012"), AMERICAN_SAMOA("American Samoa", "AS", "ASM", "016"), ANDORRA("Andorra", "AD", "AND", "020"), ANGOLA("Angola", "AO", "AGO", "024"), ANGUILLA("Anguilla", "AI", "AIA", "660"), ANTARCTICA("Antarctica", "AQ", "ATA", "010"), ANTIGUA_AND_BARBUDA("Antigua and Barbuda", "AG", "ATG", "028"), ARGENTINA("Argentina", "AR", "ARG", "032"), ARMENIA("Armenia", "AM", "ARM", "051"), ARUBA("Aruba", "AW", "ABW", "533"), AUSTRALIA("Australia", "AU", "AUS", "036"), AUSTRIA("Austria", "AT", "AUT", "040"), AZERBAIJAN("Azerbaijan", "AZ", "AZE", "031"), BAHAMAS("Bahamas", "BS", "BHS", "044"), BAHRAIN("Bahrain", "BH", "BHR", "048"), BANGLADESH("Bangladesh", "BD", "BGD", "050"), BARBADOS("Barbados", "BB", "BRB", "052"), BELARUS("Belarus", "BY", "BLR", "112"), BELGIUM("Belgium", "BE", "BEL", "056"), BELIZE("Belize", "BZ", "BLZ", "084"), BENIN("Benin", "BJ", "BEN", "204"), BERMUDA("Bermuda", "BM", "BMU", "060"), BHUTAN("Bhutan", "BT", "BTN", "064"), BOLIVIA("Boliva", "BO", "BOL", "068"), BOSNIA_AND_HERZEGOWINA("Bosnia and Herzegowina", "BA", "BIH", "070"), BOTSWANA("Botswana", "BW", "BWA", "072"), BOUVET_ISLAND("Bouvet Island", "BV", "BVT", "074"), BRAZIL("Brazil", "BR", "BRA", "076"), BRITISH_INDIAN_OCEAN_TERRITORY("British Indian Ocean Territory", "IO", "IOT", "086"), BRUNEI_DARUSSALAM("Brunei Darussalam", "BN", "BRN", "096"), BULGARIA("Bulgaria", "BG", "BGR", "100"), BURKINA_FASO("Burkina Faso", "BF", "BFA", "854"), BURUNDI("Burundi", "BI", "BDI", "108"), CAMBODIA("Cambodia", "KH", "KHM", "116"), CAMEROON("Cameroon", "CM", "CMR", "120"), CANADA("Canada", "CA", "CAN", "124"), CAPE_VERDE("Cape Verde", "CV", "CPV", "132"), CAYMAN_ISLANDS("Cayman Islands", "KY", "CYM", "136"), CENTRAL_AFRICAN_REPUBLIC("Central African Republic", "CF", "CAF", "140"), CHAD("Chad", "TD", "TCD", "TCD"), CHILE("Chile", "CL", "CHL", "152"), CHINA("China", "CN", "CHN", "156"), CHRISTMAS_ISLAND("Christmas Island", "CX", "CXR", "162"), COCOS_KEELING_ISLANDS("Cocos Keeling Ilands", "CC", "CCK", "166"), COLOMBIA("Colombia", "CO", "COL", "170"), COMOROS("Comoros", "KM", "COM", "174"), CONGO("Congo", "CG", "COG", "178"), COOK_ISLANDS("Cook Islands", "CK", "COK", "184"), COSTA_RICA("Costa Rica", "CR", "CRI", "188"), COTE_DIVOIRE("Cote D'Ivoire", "CI", "CIV", "384"), CROATIA("Croatia", "HR", "HRV", "191"), CUBA("Cuba", "CU", "CUB", "192"), CYPRUS("Cyprus", "CY", "CYP", "196"), CZECH_REPUBLIC("Czech Republic", "CZ", "CZE", "203"), DENMARK("Denmark", "DK", "DNK", "208"), DJIBOUTI("Djibouti", "DJ", "DJI", "262"), DOMINICA("Dominica", "DM", "DMA", "212"), DOMINICAN_REPUBLIC("Dominican Republic", "DO", "DOM", "214"), EAST_TIMOR("East Timor", "TP", "TMP", "626"), ECUADOR("Ecuador", "EC", "ECU", "218"), EGYPT("Egypt", "EG", "EGY", "818"), EL_SALVADOR("El Salvador", "SV", "SLV", "222"), EQUATORIAL_GUINEA("Equatorial Guinea", "GQ", "GNQ", "226"), ERITREA("Eritera", "ER", "ERI", "232"), ESTONIA("Estonia", "EE", "EST", "233"), ETHIOPIA("Ethiopia", "ET", "ETH", "210"), FALKLAND_ISLANDS("Falkland Islands", "FK", "FLK", "238"), FAROE_ISLANDS("Faroe Islands", "FO", "FRO", "234"), FIJI("Fiji", "FJ", "FJI", "242"), FINLAND("Finland", "FI", "FIN", "246"), FRANCE("France", "FR", "FRA", "250"), FRANCE_METROPOLITAN("France Metropolitan", "FX", "FXX", "249"), FRENCH_GUIANA("French Guiana", "GF", "GUF", "254"), FRENCH_POLYNESIA("French Polynesia", "PF", "PYF", "258"), FRENCH_SOUTHERN_TERRITORIES("French Southern Territories", "TF", "ATF", "260"), GABON("Gabon", "GA", "GAB", "266"), GAMBIA("Gambia", "GM", "GMB", "270"), GEORGIA("Georgia", "GE", "GEO", "268"), GERMANY("Germany", "DE", "DE", "276"), GHANA("Ghana", "GH", "GHA", "288"), GIBRALTAR("Gibraltar", "GI", "GIB", "292"), GREECE("Greece", "GR", "GRC", "300"), GREENLAND("Greenland", "GL", "GRL", "304"), GRENADA("Grenada", "GD", "GRD", "308"), GUADELOUPE("Guadeloupe", "GP", "GLP", "312"), GUAM("Guam", "GU", "GUM", "316"), GUATEMALA("Guatemala", "GT", "GTM", "320"), GUINEA("Guinea", "GN", "GIN", "324"), GUINEA_BISSAU("Guinea Bissau", "GW", "GNB", "624"), GUYANA("Guyana", "GY", "GUY", "328"), HAITI("Haiti", "HT", "HTI", "332"), HEARD_AND_MC_DONALD_ISLANDS("Heard and Mc'Donald Islands", "HM", "HMD", "334"), HONDURAS("Honduras", "HN", "HND", "340"), HONG_KONG("Hong Kong", "HK", "HKG", "344"), HUNGARY("Hungary", "HU", "HUN", "348"), ICELAND("Iceland", "IS", "ISL", "352"), INDIA("India", "IN", "IND", "356"), INDONESIA("Indonesia", "ID", "IDN", "360"), IRAN_ISLAMIC_REPUBLIC_OF("Iran, Islamic Republic of", "IR", "IRN", "364"), IRAQ("Iraq", "IQ", "IRQ", "368"), IRELAND("Ireland", "IE", "IRL", "372"), ITALY("Italy", "IT", "ITA", "380"), JAMAICA("Jamaica", "JM", "JAM", "388"), JAPAN("Japan", "JP", "JPN", "392"), JORDAN("Jordan", "JO", "JOR", "400"), KAZAKHSTAN("Kazakhstan", "KZ", "KAZ", "398"), KENYA("Kenya", "KE", "KEN", "404"), KIRIBATI("Kiribati", "KI", "KIR", "296"), KOREA_DEMOCRATIC_PEOPLES_REPUBLIC_OF("Korea, Democratic People's Republic of", "KP", "PRK", "408"), KOREA_REPUBLIC_OF("Korea, Republic of", "KR", "KOR", "410"), KUWAIT("Kuwait", "KW", "KWT", "414"), KYRGYZSTAN("Kyrgyzstan", "KG", "KGZ", "417"), LAO_PEOPLES_DEMOCRATIC_REPUBLIC("Lao, People's Democratic Republic", "LA", "LAO", "418"), LATVIA("Latvia", "LV", "LVA", "428"), LEBANON("Lebanon", "LB", "LBN", "422"), LESOTHO("Lesotho", "LS", "LSO", "426"), LIBERIA("Liberia", "LR", "LBR", "430"), LIBYAN_ARAB_JAMAHIRIYA("Libyan Arab Jamahiriya", "LY", "LBY", "434"), LIECHTENSTEIN("Liechtenstein", "LI", "LIE", "438"), LITHUANIA("Lithuania", "LT", "LTU", "440"), LUXEMBOURG("Luxembourg", "LU", "LUX", "442"), MACAU("Macau", "MO", "MAC", "446"), MACEDONIA_THE_FORMER_YUGOSLAV_REPUBLIC_OF("Macedonia, The Former Yugoslav Republic of", "MK", "MKD", "807"), MADAGASCAR("Madagascar", "MG", "MDG", "450"), MALAWI("Malawi", "MW", "MWI", "454"), MALAYSIA("Malaysia", "MY", "MYS", "458"), MALDIVES("Maldives", "MV", "MDV", "462"), MALI("Mali", "ML", "MLI", "466"), MALTA("Malta", "MT", "MLT", "470"), MARSHALL_ISLANDS("Marshall Islands", "MH", "MHL", "584"), MARTINIQUE("Martinique", "MQ", "MTQ", "474"), MAURITANIA("Mauritania", "MR", "MRT", "478"), MAURITIUS("Mauritius", "MU", "MUS", "480"), MAYOTTE("Mayotte", "YT", "MYT", "175"), MEXICO("Mexico", "MX", "MEX", "484"), MICRONESIA_FEDERATED_STATES_OF("Micronesia, Federated States of", "FM", "FSM", "583"), MOLDOVA_REPUBLIC_OF("Moldova, Republic of", "MD", "MDA", "498"), MONACO("Monaco", "MC", "MCO", "492"), MONGOLIA("Mongolia", "MN", "MNG", "496"), MONTSERRAT("Montserrat", "MS", "MSR", "500"), MOROCCO("Morocco", "MA", "MAR", "504"), MOZAMBIQUE("Mozambique", "MZ", "MOZ", "508"), MYANMAR("Myanmar", "MM", "MMR", "104"), NAMIBIA("Namibia", "NA", "NAM", "516"), NAURU("Nauru", "NR", "NRU", "520"), NEPAL("Nepal", "NP", "NPL", "524"), NETHERLANDS("Netherlands", "NL", "NLD", "528"), NETHERLANDS_ANTILLES("Netherlands Antilles", "AN", "ANT", "530"), NEW_CALEDONIA("New Caledonia", "NC", "NCL", "540"), NEW_ZEALAND("New Zealand", "NZ", "NZL", "554"), NICARAGUA("Nicaragua", "NI", "NIC", "558"), NIGER("Niger", "NE", "NER", "562"), NIGERIA("Nigeria", "NG", "NGA", "566"), NIUE("Niue", "NU", "NIU", "570"), NORFOLK_ISLAND("Norfolk Island", "NF", "NFK", "574"), NORTHERN_MARIANA_ISLANDS("Northern Mariana Islands", "MP", "MNP", "580"), NORWAY("Norway", "NO", "NO", "578"), OMAN("Oman", "OM", "OMN", "512"), PAKISTAN("Pakistan", "PK", "PAK", "586"), PALAU("Palau", "PW", "PLW", "585"), PANAMA("Panama", "PA", "PAN", "PAN"), PAPUA_NEW_GUINEA("Papua New Guinea", "PG", "PG", "598"), PARAGUAY("Paraguay", "PY", "PRY", "PRY"), PERU("Peru", "PE", "PER", "604"), PHILIPPINES("Philippines", "PH", "PH", "608"), PITCAIRN("Pitcairn", "PN", "PCN", "612"), POLAND("Poland", "PL", "PL", "616"), PORTUGAL("Portugal", "PT", "PRT", "620"), PUERTO_RICO("Puerto Rico", "PR", "PRI", "630"), QATAR("Qatar", "QA", "QA", "634"), REUNION("Reunion", "634", "REU", "638"), ROMANIA("Romania", "RO", "ROM", "642"), RUSSIAN_FEDERATION("Russian Federation", "RU", "RUS", "643"), RWANDA("Rawanda", "RW", "RWA", "646"), SAINT_KITTS_AND_NEVIS("Saint Kitts and Nevis", "KN", "KNA", "659"), SAINT_LUCIA("Saint Lucia", "LC", "LCA", "662"), SAINT_VINCENT_AND_THE_GRENADINES("Saint Vincent and the Grenadines", "VC", "VCT", "670"), SAMOA("Samoa", "WS", "WSM", "882"), SAN_MARINO("San Marino", "SM", "SMR", "674"), SAO_TOME_AND_PRINCIPE("Sao Tome and Principe", "ST", "STP", "678"), SAUDI_ARABIA("Saudi Arabia", "SA", "SAU", "682"), SENEGAL("Senegal", "SN", "SEN", "686"), SEYCHELLES("Seychelles", "SC", "SYC", "690"), SIERRA_LEONE("Sierral Leone", "SL", "SLE", "694"), SINGAPORE("Singapore", "SG", "SGP", "702"), SLOVAKIA("Slovakia", "SK", "SVK", "703"), SLOVENIA("Slovenia", "SI", "SVN", "705"), SOLOMON_ISLANDS("Solomon Islands", "SB", "SLB", "090"), SOMALIA("Somalia", "SO", "SOM", "706"), SOUTH_AFRICA("South Africa", "ZA", "ZAF", "710"), SPAIN("Spain", "ES", "ESP", "724"), SRI_LANKA("Sri Lanka", "LK", "LKA", "144"), ST_HELENA("St. Helena", "SH", "SHN", "654"), ST_PIERRE_AND_MIQUELON("St. Pierre and Miquelon", "PM", "SPM", "666"), SUDAN("Sudan", "SD", "SDN", "736"), SURINAME("Suriname", "SR", "SUR", "740"), SVALBARD_AND_JAN_MAYEN_ISLANDS("Svalbard and Jan Mayen Islands", "SJ", "SJM", "744"), SWAZILAND("Swaziland", "SZ", "SWZ", "748"), SWEDEN("Sweden", "SE", "SWE", "752"), SWITZERLAND("Switzerland", "CH", "CHE", "756"), SYRIAN_ARAB_REPUBLIC("Syrian Arab Republic", "SY", "SYR", "760"), TAIWAN_PROVINCE_OF_CHINA("Taiwan, Province of China", "TW", "TWN", "158"), TAJIKISTAN("Tajikistan", "TJ", "TJK", "762"), TANZANIA_UNITED_REPUBLIC_OF("Tanzania, United Republic of", "TZ", "TZA", "834"), THAILAND("Thailand", "TH", "THA", "764"), TOGO("Togo", "TG", "TGO", "768"), TOKELAU("Tokelau", "TK", "TKL", "772"), TONGA("Tonga", "TO", "TON", "776"), TRINIDAD_AND_TOBAGO("Trinidad and Tobago", "TT", "TTO", "780"), TUNISIA("Tunisia", "TN", "TUN", "788"), TURKEY("Turkey", "TR", "TUR", "792"), TURKMENISTAN("Turkmenistan", "TM", "TKM", "795"), |