/** * Gets a country by a locale. * * @param locale The locale. * @return The country from the giben locale or <code>null</code> if unknown country or * if the locale does not contain a country. */ public static Country byLocale(Locale locale) { return byIsoTag(locale.getCountry()); }
@Override protected JsonObject getChartData() { JsonObject data = new JsonObject(); JsonObject values = new JsonObject(); HashMap<Country, Integer> map = getValues(new HashMap<Country, Integer>()); if (map == null || map.isEmpty()) { // Null = skip the chart return null; } boolean allSkipped = true; for (Map.Entry<Country, Integer> entry : map.entrySet()) { if (entry.getValue() == 0) { continue; // Skip this invalid } allSkipped = false; values.addProperty(entry.getKey().getCountryIsoTag(), entry.getValue()); } if (allSkipped) { // Null = skip the chart return null; } data.add("values", values); return data; }
/** * Gets a country by it's iso tag. * * @param isoTag The iso tag of the county. * @return The country with the given iso tag or <code>null</code> if unknown. */ public static Country byIsoTag(String isoTag) { for (Country country : Country.values()) { if (country.getCountryIsoTag().equals(isoTag)) { return country; } } return null; }
@Override protected JsonObject getChartData() { JsonObject data = new JsonObject(); Country value = getValue(); if (value == null) { // Null = skip the chart return null; } data.addProperty("value", value.getCountryIsoTag()); return data; }