|
| 1 | +package appDomain; |
| 2 | + |
| 3 | +import org.apache.commons.lang3.builder.ToStringBuilder; |
| 4 | + |
| 5 | +import java.util.Locale; |
| 6 | + |
| 7 | +public enum AppDomain { |
| 8 | + |
| 9 | + DE("de", 17, new Locale("de")), |
| 10 | + UK("uk", 43, new Locale("en")), |
| 11 | + FR("fr", 18, new Locale("fr")), |
| 12 | + NL("nl", 35, new Locale("nl")), |
| 13 | + BE("be", 36, new Locale("nl", "BE")), |
| 14 | + BEFR("befr", 37, new Locale("fr", "BE")), |
| 15 | + COM("com", 38, new Locale("en")), |
| 16 | + AT("at", 39, new Locale("de", "AT")), |
| 17 | + CH("ch", 40, new Locale("de", "CH")), |
| 18 | + CHFR("chfr", 41, new Locale("fr", "CH")), |
| 19 | + IT("it", 44, new Locale("it")), |
| 20 | + PL("pl", 45, new Locale("pl")), |
| 21 | + DEV("dev", 17, new Locale("dev")); |
| 22 | + |
| 23 | + |
| 24 | + private final String countryCode; |
| 25 | + private final Locale locale; |
| 26 | + private final int appDomainId; |
| 27 | + |
| 28 | + |
| 29 | + AppDomain(String countyCode, int appDomainId, Locale locale) { |
| 30 | + |
| 31 | + this.appDomainId = appDomainId; |
| 32 | + this.countryCode = countyCode; |
| 33 | + this.locale = locale; |
| 34 | + } |
| 35 | + |
| 36 | + public String getCountryCode() { |
| 37 | + return countryCode; |
| 38 | + } |
| 39 | + |
| 40 | + public Locale getLocale() { |
| 41 | + return locale; |
| 42 | + } |
| 43 | + |
| 44 | + public static AppDomain fromCountryCode(final String countryCode) { |
| 45 | + for (final AppDomain tld : AppDomain.values()) { |
| 46 | + if (tld.getCountryCode().equalsIgnoreCase(countryCode)) { |
| 47 | + return tld; |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + switch (countryCode) { |
| 52 | + |
| 53 | + case "co.uk": |
| 54 | + case "gb": |
| 55 | + return UK; |
| 56 | + |
| 57 | + default: |
| 58 | + throw new IllegalArgumentException("No constant with countryCode" + countryCode + "found"); |
| 59 | + } |
| 60 | + } |
| 61 | + |
| 62 | + @Override |
| 63 | + public String toString() { |
| 64 | + return new ToStringBuilder(this) |
| 65 | + .append("countryCode", countryCode) |
| 66 | + .append("locale", locale) |
| 67 | + .append("appDomainID", appDomainId) |
| 68 | + .toString(); |
| 69 | + } |
| 70 | +} |
0 commit comments