Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dev.sorn.fmp4j.exceptions;

public class FmpInvalidCountryException extends FmpException {
public FmpInvalidCountryException(String message, Object... args) {
super(message, args);
}
}
295 changes: 295 additions & 0 deletions src/main/java/dev/sorn/fmp4j/types/FmpCountry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,295 @@
package dev.sorn.fmp4j.types;

import dev.sorn.fmp4j.exceptions.FmpInvalidCountryException;
import org.apache.commons.lang3.StringUtils;

public enum FmpCountry implements FmpValueObject<String> {
AD("AND", "020", "Andorra"),
AE("ARE", "784", "United Arab Emirates (the)"),
AF("AFG", "004", "Afghanistan"),
AG("ATG", "028", "Antigua and Barbuda"),
AI("AIA", "660", "Anguilla"),
AL("ALB", "008", "Albania"),
AM("ARM", "051", "Armenia"),
AO("AGO", "024", "Angola"),
AQ("ATA", "010", "Antarctica"),
AR("ARG", "032", "Argentina"),
AS("ASM", "016", "American Samoa"),
AT("AUT", "040", "Austria"),
AU("AUS", "036", "Australia"),
AW("ABW", "533", "Aruba"),
AX("ALA", "248", "Åland Islands"),
AZ("AZE", "031", "Azerbaijan"),
BA("BIH", "070", "Bosnia and Herzegovina"),
BB("BRB", "052", "Barbados"),
BD("BGD", "050", "Bangladesh"),
BE("BEL", "056", "Belgium"),
BF("BFA", "854", "Burkina Faso"),
BG("BGR", "100", "Bulgaria"),
BH("BHR", "048", "Bahrain"),
BI("BDI", "108", "Burundi"),
BJ("BEN", "204", "Benin"),
BL("BLM", "652", "Saint Barthélemy"),
BM("BMU", "060", "Bermuda"),
BN("BRN", "096", "Brunei Darussalam"),
BO("BOL", "068", "Bolivia (Plurinational State of)"),
BQ("BES", "535", "Bonaire, Sint Eustatius and Saba"),
BR("BRA", "076", "Brazil"),
BS("BHS", "044", "Bahamas (the)"),
BT("BTN", "064", "Bhutan"),
BV("BVT", "074", "Bouvet Island"),
BW("BWA", "072", "Botswana"),
BY("BLR", "112", "Belarus"),
BZ("BLZ", "084", "Belize"),
CA("CAN", "124", "Canada"),
CC("CCK", "166", "Cocos (Keeling) Islands (the)"),
CD("COD", "180", "Congo (the Democratic Republic of the)"),
CF("CAF", "140", "Central African Republic (the)"),
CG("COG", "178", "Congo (the)"),
CH("CHE", "756", "Switzerland"),
CI("CIV", "384", "Côte d'Ivoire"),
CK("COK", "184", "Cook Islands (the)"),
CL("CHL", "152", "Chile"),
CM("CMR", "120", "Cameroon"),
CN("CHN", "156", "China"),
CO("COL", "170", "Colombia"),
CR("CRI", "188", "Costa Rica"),
CU("CUB", "192", "Cuba"),
CV("CPV", "132", "Cabo Verde"),
CW("CUW", "531", "Curaçao"),
CX("CXR", "162", "Christmas Island"),
CY("CYP", "196", "Cyprus"),
CZ("CZE", "203", "Czechia"),
DE("DEU", "276", "Germany"),
DJ("DJI", "262", "Djibouti"),
DK("DNK", "208", "Denmark"),
DM("DMA", "212", "Dominica"),
DO("DOM", "214", "Dominican Republic (the)"),
DZ("DZA", "012", "Algeria"),
EC("ECU", "218", "Ecuador"),
EE("EST", "233", "Estonia"),
EG("EGY", "818", "Egypt"),
EH("ESH", "732", "Western Sahara"),
ER("ERI", "232", "Eritrea"),
ES("ESP", "724", "Spain"),
ET("ETH", "231", "Ethiopia"),
FI("FIN", "246", "Finland"),
FJ("FJI", "242", "Fiji"),
FK("FLK", "238", "Falkland Islands (the) [Malvinas]"),
FM("FSM", "583", "Micronesia (Federated States of)"),
FO("FRO", "234", "Faroe Islands (the)"),
FR("FRA", "250", "France"),
GA("GAB", "266", "Gabon"),
GB("GBR", "826", "United Kingdom of Great Britain and Northern Ireland (the)"),
GD("GRD", "308", "Grenada"),
GE("GEO", "268", "Georgia"),
GF("GUF", "254", "French Guiana"),
GG("GGY", "831", "Guernsey"),
GH("GHA", "288", "Ghana"),
GI("GIB", "292", "Gibraltar"),
GL("GRL", "304", "Greenland"),
GM("GMB", "270", "Gambia (the)"),
GN("GIN", "324", "Guinea"),
GP("GLP", "312", "Guadeloupe"),
GQ("GNQ", "226", "Equatorial Guinea"),
GR("GRC", "300", "Greece"),
GS("SGS", "239", "South Georgia and the South Sandwich Islands"),
GT("GTM", "320", "Guatemala"),
GU("GUM", "316", "Guam"),
GW("GNB", "624", "Guinea-Bissau"),
GY("GUY", "328", "Guyana"),
HK("HKG", "344", "Hong Kong"),
HM("HMD", "334", "Heard Island and McDonald Islands"),
HN("HND", "340", "Honduras"),
HR("HRV", "191", "Croatia"),
HT("HTI", "332", "Haiti"),
HU("HUN", "348", "Hungary"),
ID("IDN", "360", "Indonesia"),
IE("IRL", "372", "Ireland"),
IL("ISR", "376", "Israel"),
IM("IMN", "833", "Isle of Man"),
IN("IND", "356", "India"),
IO("IOT", "086", "British Indian Ocean Territory (the)"),
IQ("IRQ", "368", "Iraq"),
IR("IRN", "364", "Iran (Islamic Republic of)"),
IS("ISL", "352", "Iceland"),
IT("ITA", "380", "Italy"),
JE("JEY", "832", "Jersey"),
JM("JAM", "388", "Jamaica"),
JO("JOR", "400", "Jordan"),
JP("JPN", "392", "Japan"),
KE("KEN", "404", "Kenya"),
KG("KGZ", "417", "Kyrgyzstan"),
KH("KHM", "116", "Cambodia"),
KI("KIR", "296", "Kiribati"),
KM("COM", "174", "Comoros (the)"),
KN("KNA", "659", "Saint Kitts and Nevis"),
KP("PRK", "408", "Korea (the Democratic People's Republic of)"),
KR("KOR", "410", "Korea (the Republic of)"),
KW("KWT", "414", "Kuwait"),
KY("CYM", "136", "Cayman Islands (the)"),
KZ("KAZ", "398", "Kazakhstan"),
LA("LAO", "418", "Lao People's Democratic Republic (the)"),
LB("LBN", "422", "Lebanon"),
LC("LCA", "662", "Saint Lucia"),
LI("LIE", "438", "Liechtenstein"),
LK("LKA", "144", "Sri Lanka"),
LR("LBR", "430", "Liberia"),
LS("LSO", "426", "Lesotho"),
LT("LTU", "440", "Lithuania"),
LU("LUX", "442", "Luxembourg"),
LV("LVA", "428", "Latvia"),
LY("LBY", "434", "Libya"),
MA("MAR", "504", "Morocco"),
MC("MCO", "492", "Monaco"),
MD("MDA", "498", "Moldova (the Republic of)"),
ME("MNE", "499", "Montenegro"),
MF("MAF", "663", "Saint Martin (French part)"),
MG("MDG", "450", "Madagascar"),
MH("MHL", "584", "Marshall Islands (the)"),
MK("MKD", "807", "North Macedonia"),
ML("MLI", "466", "Mali"),
MM("MMR", "104", "Myanmar"),
MN("MNG", "496", "Mongolia"),
MO("MAC", "446", "Macao"),
MP("MNP", "580", "Northern Mariana Islands (the)"),
MQ("MTQ", "474", "Martinique"),
MR("MRT", "478", "Mauritania"),
MS("MSR", "500", "Montserrat"),
MT("MLT", "470", "Malta"),
MU("MUS", "480", "Mauritus"),
MV("MDV", "462", "Maldives"),
MW("MWI", "454", "Malawi"),
MX("MEX", "484", "Mexico"),
MY("MYS", "458", "Malaysia"),
MZ("MOZ", "508", "Mozambique"),
NA("NAM", "516", "Namibia"),
NC("NCL", "540", "New Caledonia"),
NE("NER", "562", "Niger (the)"),
NF("NFK", "574", "Norfolk Island"),
NG("NGA", "566", "Nigeria"),
NI("NIC", "558", "Nicaragua"),
NL("NLD", "528", "Netherlands (Kingdom of the)"),
NO("NOR", "578", "Norway"),
NP("NPL", "524", "Nepal"),
NR("NRU", "520", "Nauru"),
NU("NIU", "570", "Niue"),
NZ("NZL", "554", "New Zealand"),
OM("OMN", "512", "Oman"),
PA("PAN", "591", "Panama"),
PE("PER", "604", "Peru"),
PF("PYF", "258", "French Polynesia"),
PG("PNG", "598", "Papua New Guinea"),
PH("PHL", "608", "Philippines (the)"),
PK("PAK", "586", "Pakistan"),
PL("POL", "616", "Poland"),
PM("SPM", "666", "Saint Pierre and Miquelon"),
PN("PCN", "612", "Pitcairn"),
PR("PRI", "630", "Puerto Rico"),
PS("PSE", "275", "Palestine, State of"),
PT("PRT", "620", "Portugal"),
PW("PLW", "585", "Palau"),
PY("PRY", "600", "Paraguay"),
QA("QAT", "634", "Qatar"),
RE("REU", "638", "Réunion"),
RO("ROU", "642", "Romania"),
RS("SRB", "688", "Serbia"),
RU("RUS", "643", "Russian Federation (the)"),
RW("RWA", "646", "Rwanda"),
SA("SAU", "682", "Saudi Arabia"),
SB("SLB", "090", "Solomon Islands"),
SC("SYC", "690", "Seychelles"),
SD("SDN", "729", "Sudan (the)"),
SE("SWE", "752", "Sweden"),
SG("SGP", "702", "Singapore"),
SH("SHN", "654", "Saint Helena, Ascension and Tristan da Cunha"),
SI("SVN", "705", "Slovenia"),
SJ("SJM", "744", "Svalbard and Jan Mayen"),
SK("SVK", "703", "Slovakia"),
SL("SLE", "694", "Sierra Leone"),
SM("SMR", "674", "San Marino"),
SN("SEN", "686", "Senegal"),
SO("SOM", "706", "Somalia"),
SR("SUR", "740", "Suriname"),
SS("SSD", "728", "South Sudan"),
ST("STP", "678", "Sao Tome and Principe"),
SV("SLV", "222", "El Salvador"),
SX("SXM", "534", "Sint Maarten (Dutch part)"),
SY("SYR", "760", "Syrian Arab Republic (the)"),
SZ("SWZ", "748", "Eswatini"),
TC("TCA", "796", "Turks and Caicos Islands (the)"),
TD("TCD", "148", "Chad"),
TF("ATF", "260", "French Southern Territories (the)"),
TG("TGO", "768", "Togo"),
TH("THA", "764", "Thailand"),
TJ("TJK", "762", "Tajikistan"),
TK("TKL", "772", "Tokelau"),
TL("TLS", "626", "Timor-Leste"),
TM("TKM", "795", "Turkmenistan"),
TN("TUN", "788", "Tunisia"),
TO("TON", "776", "Tonga"),
TR("TUR", "792", "Türkiye"),
TT("TTO", "780", "Trinidad and Tobago"),
TV("TUV", "798", "Tuvalu"),
TW("TWN", "158", "Taiwan (Province of China)"),
TZ("TZA", "834", "Tanzania, the United Republic of"),
UA("UKR", "804", "Ukraine"),
UG("UGA", "800", "Uganda"),
UM("UMI", "581", "United States Minor Outlying Islands (the)"),
US("USA", "840", "United States of America (the)"),
UY("URY", "858", "Uruguay"),
UZ("UZB", "860", "Uzbekistan"),
VA("VAT", "336", "Holy See (the)"),
VC("VCT", "670", "Saint Vincent and the Grenadines"),
VE("VEN", "862", "Venezuela (Bolivarian Republic of)"),
VG("VGB", "092", "Virgin Islands (British)"),
VI("VIR", "850", "Virgin Islands (U.S.)"),
VN("VNM", "704", "Viet Nam"),
VU("VUT", "548", "Vanuatu"),
WF("WLF", "876", "Wallis and Futuna"),
WS("WSM", "882", "Samoa"),
YE("YEM", "887", "Yemen"),
YT("MYT", "175", "Mayotte"),
ZA("ZAF", "710", "South Africa"),
ZM("ZMB", "894", "Zambia"),
ZW("ZWE", "716", "Zimbabwe");

private final String alpha3;
private final String numeric;
private final String isoName;

FmpCountry(String alpha3, String numeric, String isoName) {
this.alpha3 = alpha3;
this.numeric = numeric;
this.isoName = isoName;
}

public static FmpCountry country(String alpha2) {
try {
return FmpCountry.valueOf(StringUtils.upperCase(alpha2));
} catch (IllegalArgumentException e) {
throw new FmpInvalidCountryException("[%s] is not a valid country", alpha2);
}
}

@Override
public String value() {
return name();
}

public String alpha2() {
return name();
}

public String alpha3() {
return alpha3;
}

public String numeric() {
return numeric;
}

public String isoName() {
return isoName;
}
}
55 changes: 55 additions & 0 deletions src/test/java/dev/sorn/fmp4j/types/FmpCountryTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package dev.sorn.fmp4j.types;

import static dev.sorn.fmp4j.types.FmpCountry.US;
import static dev.sorn.fmp4j.types.FmpCountry.country;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.util.stream.Stream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

class FmpCountryTest {
@ParameterizedTest
@MethodSource("countries")
void valid_country(String code) {
// given // when
var country = country(code);

// then
assertEquals(code, country.name());
assertNotNull(country.alpha2());
assertNotNull(country.alpha3());
assertNotNull(country.numeric());
assertNotNull(country.name());
}

@Test
void lower_case_code_country() {
// given // when
var country = country("us");

// then
assertEquals(US.name(), country.name());
}

private static Stream<String> countries() {
return Stream.of(
"AD", "AE", "AF", "AG", "AI", "AL", "AM", "AO", "AQ", "AR", "AS", "AT", "AU", "AW", "AX", "AZ", "BA",
"BB", "BD", "BE", "BF", "BG", "BH", "BI", "BJ", "BL", "BM", "BN", "BO", "BQ", "BR", "BS", "BT", "BV",
"BW", "BY", "BZ", "CA", "CC", "CD", "CF", "CG", "CH", "CI", "CK", "CL", "CM", "CN", "CO", "CR", "CU",
"CV", "CW", "CX", "CY", "CZ", "DE", "DJ", "DK", "DM", "DO", "DZ", "EC", "EE", "EG", "EH", "ER", "ES",
"ET", "FI", "FJ", "FK", "FM", "FO", "FR", "GA", "GB", "GD", "GE", "GF", "GG", "GH", "GI", "GL", "GM",
"GN", "GP", "GQ", "GR", "GS", "GT", "GU", "GW", "GY", "HK", "HM", "HN", "HR", "HT", "HU", "ID", "IE",
"IL", "IM", "IN", "IO", "IQ", "IR", "IS", "IT", "JE", "JM", "JO", "JP", "KE", "KG", "KH", "KI", "KM",
"KN", "KP", "KR", "KW", "KY", "KZ", "LA", "LB", "LC", "LI", "LK", "LR", "LS", "LT", "LU", "LV", "LY",
"MA", "MC", "MD", "ME", "MF", "MG", "MH", "MK", "ML", "MM", "MN", "MO", "MP", "MQ", "MR", "MS", "MT",
"MU", "MV", "MW", "MX", "MY", "MZ", "NA", "NC", "NE", "NF", "NG", "NI", "NL", "NO", "NP", "NR", "NU",
"NZ", "OM", "PA", "PE", "PF", "PG", "PH", "PK", "PL", "PM", "PN", "PR", "PS", "PT", "PW", "PY", "QA",
"RE", "RO", "RS", "RU", "RW", "SA", "SB", "SC", "SD", "SE", "SG", "SH", "SI", "SJ", "SK", "SL", "SM",
"SN", "SO", "SR", "SS", "ST", "SV", "SX", "SY", "SZ", "TC", "TD", "TF", "TG", "TH", "TJ", "TK", "TL",
"TM", "TN", "TO", "TR", "TT", "TV", "TW", "TZ", "UA", "UG", "UM", "US", "UY", "UZ", "VA", "VC", "VE",
"VG", "VI", "VN", "VU", "WF", "WS", "YE", "YT", "ZA", "ZM", "ZW");
}
}
4 changes: 2 additions & 2 deletions src/test/java/dev/sorn/fmp4j/types/FmpExchangeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class FmpExchangeTest {
@ParameterizedTest
@MethodSource
void valid_exchange(String shortName) {
// when
// given // when
var p = exchange(shortName);

// then
Expand Down Expand Up @@ -103,7 +103,7 @@ private static Stream<String> valid_exchange() {

@Test
void lower_case_code_exchange() {
// when
// given // when
var p = exchange("two");

// then
Expand Down
Loading