Skip to content

Commit

Permalink
send 2-letter country abbreviation, not display name (redhat-develope…
Browse files Browse the repository at this point in the history
…r#30)

Signed-off-by: Andre Dietisheim <adietish@redhat.com>
  • Loading branch information
adietish committed Sep 2, 2021
1 parent a6c56e2 commit 7468124
Showing 1 changed file with 9 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class Country {
private static final Logger LOGGER = Logger.getInstance(Country.class);

private static final String TIMEZONES = "/timezones.json";
private static final String COUNTRIES = "/countries.json";
private static final String KEY_COUNTRY = "c";
private static final String KEY_ALTERNATIVE = "a";

Expand All @@ -41,8 +40,7 @@ public static Country getInstance() {
return INSTANCE;
}

private Lazy<Map<String, Map<String, String>>> timezones = new Lazy<>(() -> deserialize(TIMEZONES));
private Lazy<Map<String, String>> countries = new Lazy<>(() -> deserialize(COUNTRIES));
private final Lazy<Map<String, Map<String, String>>> timezones = new Lazy<>(() -> deserialize(TIMEZONES));

protected Country() {
// for testing purposes
Expand All @@ -58,21 +56,17 @@ public String get(TimeZone timeZone) {
private String get(String timezoneId) {
Map<String, String> timezone = timezones.get().get(timezoneId);
if (timezone == null) {
return timezoneId;
return null;
}
String abbreviation = timezone.get(KEY_COUNTRY);
if (abbreviation == null) {
String alternative = timezone.get(KEY_ALTERNATIVE);
if (alternative == null) {
return timezoneId;
}
return get(alternative);
if (abbreviation != null) {
return abbreviation;
}
return getDisplayName(abbreviation);
}

private String getDisplayName(String abbreviation) {
return countries.get().get(abbreviation);
String alternative = timezone.get(KEY_ALTERNATIVE);
if (alternative == null) {
return null;
}
return get(alternative);
}

private <V> Map<String, V> deserialize(String file) {
Expand Down

0 comments on commit 7468124

Please sign in to comment.