Java Code Examples for java.util.Locale.getISOCountries()

The following are Jave code examples for showing how to use getISOCountries() of the java.util.Locale class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: VASSAL-src   File: LocaleConfigurer.java   View Source Code Vote up 7 votes
protected String[] getCountryList() {
  if (countryList == null) {
    String[] c = Locale.getISOCountries();
    ArrayList<String> sortedCountries = new ArrayList<String>();
    for (int i = 0; i < c.length; i++) {
      String country =
        (new Locale("en", c[i])).getDisplayCountry(Locale.getDefault());
      countries.put(country, c[i]);
      sortedCountries.add(country);
    }
    Collections.sort(sortedCountries,
                     Collator.getInstance(Locale.getDefault()));
    countries.put(ANY_COUNTRY, "");
    sortedCountries.add(0, ANY_COUNTRY);
    countryList = sortedCountries.toArray(new String[sortedCountries.size()]);
  }
  return countryList;
}
 
Example 2
Project: GitTalent   File: CountryList.java   View Source Code Vote up 6 votes
public CountryList() {
    // A collection to store our country object
    this.countries = new ArrayList<String>();

    // Get ISO countries, create Country object and
    // store in the collection.
    String[] isoCountries = Locale.getISOCountries();
    for (String country : isoCountries) {
        Locale locale = new Locale("en", country);
        String name = locale.getDisplayCountry();

        if (!"".equals(name)) {
            this.countries.add(name);
        }
    }
    this.countryListSize = countries.size();
    this.random = new Random();
}
 
Example 3
Project: jdk8u-jdk   File: LocaleTest.java   View Source Code Vote up 6 votes
/**
 * @bug 4126880
 */
void Test4126880() {
    String[] test;

    test = Locale.getISOCountries();
    test[0] = "SUCKER!!!";
    test = Locale.getISOCountries();
    if (test[0].equals("SUCKER!!!"))
        errln("Changed internal country code list!");

    test = Locale.getISOLanguages();
    test[0] = "HAHAHAHA!!!";
    test = Locale.getISOLanguages();
    if (test[0].equals("HAHAHAHA!!!")) // Fixed typo
        errln("Changes internal language code list!");
}
 
Example 4
Project: CountryCurrencyPicker   File: Country.java   View Source Code Vote up 6 votes
public static ArrayList<Country> listAll(Context context, final String filter) {
    ArrayList<Country> list = new ArrayList<>();

    for (String countryCode : Locale.getISOCountries()) {
        Country country = getCountry(countryCode, context);

        list.add(country);
    }

    sortList(list);

    if (filter != null && filter.length() > 0) {
        return new ArrayList<>(Collections2.filter(list, new Predicate<Country>() {
            @Override
            public boolean apply(Country input) {
                return input.getName().toLowerCase().contains(filter.toLowerCase());
            }
        }));
    } else {
        return list;
    }
}
 
Example 5
Project: openjdk-jdk10   File: LocaleTest.java   View Source Code Vote up 6 votes
/**
 * @bug 4126880
 */
void Test4126880() {
    String[] test;

    test = Locale.getISOCountries();
    test[0] = "SUCKER!!!";
    test = Locale.getISOCountries();
    if (test[0].equals("SUCKER!!!")) {
        errln("Changed internal country code list!");
    }

    test = Locale.getISOLanguages();
    test[0] = "HAHAHAHA!!!";
    test = Locale.getISOLanguages();
    if (test[0].equals("HAHAHAHA!!!")) { // Fixed typo
        errln("Changes internal language code list!");
    }
}
 
Example 6
Project: Viajes   File: Utils.java   View Source Code Vote up 5 votes
public static List<String> getCountriesList() {
    List<String> countriesList = new ArrayList<>();

    String[] locales = Locale.getISOCountries();

    for (String countryCode : locales) {

        Locale obj = new Locale("", countryCode);
        countriesList.add(obj.getDisplayCountry(Locale.ENGLISH));

    }
    Collections.sort(countriesList);
    return countriesList;
}
 
Example 7
Project: oscm   File: SupportedCountries.java   View Source Code Vote up 5 votes
/**
 * Creates all SupportedCountry objects. Normally all SupportedCountry
 * objects are created during DB setup. Creating all countries is slow and
 * should be done only if needed.
 */
public static void createAllSupportedCountries(DataService mgr)
        throws NonUniqueBusinessKeyException {
    for (String countryCode : Locale.getISOCountries()) {
        findOrCreate(mgr, countryCode);
    }
}
 
Example 8
Project: oscm   File: Organizations.java   View Source Code Vote up 5 votes
public static void supportAllCountries(DataService mgr, Organization org) {
    for (String countryCode : Locale.getISOCountries()) {
        SupportedCountry country = SupportedCountries
                .find(mgr, countryCode);
        if (country != null) {
            org.setSupportedCountry(country);
        }
    }
}
 
Example 9
Project: oscm   File: CountryBean.java   View Source Code Vote up 5 votes
/**
 * Returns a mapping from country codes in ISO 3166 to localized country
 * names.
 */
public Map<String, String> getDisplayCountries() {
    if (hasLocaleChanged()) {
        reset();
    }
    if (displayCountries.isEmpty()) {
        Locale userLocale = getCurrentUserLocale();
        for (String code : Locale.getISOCountries()) {
            String country = getDisplayCountry(code, userLocale);
            displayCountries.put(code, country);
        }
    }
    return displayCountries;
}
 
Example 10
Project: convertigo-engine   File: XMLDateTimeStep.java   View Source Code Vote up 5 votes
@Override
public String[] getTagsForProperty(String propertyName) {
	if(propertyName.equals("outputLocale") || propertyName.equals("inputLocale")){
		return Locale.getISOCountries();
	}
	return super.getTagsForProperty(propertyName);
}
 
Example 11
Project: convertigo-engine   File: XMLGenerateDatesStep.java   View Source Code Vote up 5 votes
@Override
public String[] getTagsForProperty(String propertyName) {
	if(propertyName.equals("inputLocale") ||
		propertyName.equals("outputLocale")) {
		return Locale.getISOCountries();
	}
	return super.getTagsForProperty(propertyName);
}
 
Example 12
Project: c4sg-services   File: CountryCodeConverterUtil.java   View Source Code Vote up 5 votes
public static String convertToIso2(String iso3code) {

        String[] countries = Locale.getISOCountries();

        HashMap<String, Locale> localeMap = new HashMap<>(countries.length);
        for (String country : countries) {
            Locale locale = new Locale("", country);
            localeMap.put(locale.getISO3Country().toUpperCase(), locale);
        }

        return localeMap.get(iso3code).getCountry();
    }
 
Example 13
Project: CountryCurrencyPicker   File: Country.java   View Source Code Vote up 5 votes
public static ArrayList<Country> listAllWithCurrencies(Context context, final String filter) {
    ArrayList<Country> list = new ArrayList<>();

    for (String countryCode : Locale.getISOCountries()) {
        Country country = getCountryWithCurrency(countryCode, context);

        if (country != null) {
            //z.B. Antarktis is null -> keine Währung
            list.add(country);
        }
    }

    sortList(list);

    if (filter != null && filter.length() > 0) {
        return new ArrayList<>(Collections2.filter(list, new Predicate<Country>() {
            @Override
            public boolean apply(Country input) {
                return input.getName().toLowerCase().contains(filter.toLowerCase()) ||
                        input.getCurrency().getName().toLowerCase().contains(filter.toLowerCase()) ||
                        input.getCurrency().getSymbol().toLowerCase().contains(filter.toLowerCase());
            }
        }));
    } else {
        return list;
    }
}
 
Example 14
Project: openjdk-jdk10   File: Bug8071929.java   View Source Code Vote up 5 votes
/**
 * This method checks that ISO3166-3 country codes which are PART3 of
 * IsoCountryCode enum, are retrieved correctly.
 */
private static void checkISO3166_3Codes() {
    Set<String> iso3166_3Codes = Locale.getISOCountries(IsoCountryCode.PART3);
    if (!iso3166_3Codes.equals(ISO3166_3EXPECTED)) {
        reportDifference(iso3166_3Codes, ISO3166_3EXPECTED);
    }
}
 
Example 15
Project: openjdk-jdk10   File: Bug8071929.java   View Source Code Vote up 5 votes
/**
 * This method checks that ISO3166-1 alpha-3 country codes which are
 * PART1_ALPHA3 of IsoCountryCode enum, are retrieved correctly.
 */
private static void checkISO3166_1_Alpha3Codes() {
    Set<String> iso3166_1_Alpha3Codes = Locale.getISOCountries(IsoCountryCode.PART1_ALPHA3);
    if (!iso3166_1_Alpha3Codes.equals(ISO3166_1_ALPHA3_EXPECTED)) {
        reportDifference(iso3166_1_Alpha3Codes, ISO3166_1_ALPHA3_EXPECTED);
    }
}
 
Example 16
Project: openjdk-jdk10   File: Bug8071929.java   View Source Code Vote up 5 votes
/**
 * This method checks that ISO3166-1 alpha-2 country codes, which are
 * PART1_ALPHA2 of IsoCountryCode enum, are retrieved correctly.
 */
private static void checkISO3166_1_Alpha2Codes() {
    Set<String> iso3166_1_Alpha2Codes = Locale.getISOCountries(IsoCountryCode.PART1_ALPHA2);
    Set<String> ISO3166_1_ALPHA2_EXPECTED = Set.of(Locale.getISOCountries());
    if (!iso3166_1_Alpha2Codes.equals(ISO3166_1_ALPHA2_EXPECTED)) {
        reportDifference(iso3166_1_Alpha2Codes, ISO3166_1_ALPHA2_EXPECTED);
    }
}
 
Example 17
Project: trading-network   File: CountryLookupCall.java   View Source Code Vote up 5 votes
@Override
protected List<LookupRow<String>> execCreateLookupRows() { // <2>
  List<LookupRow<String>> rows = new ArrayList<>();

  for (String countryCode : Locale.getISOCountries()) {
    Locale country = new Locale("", countryCode);
    rows.add(new LookupRow<>(countryCode, country.getDisplayCountry())); // <3>
  }

  return rows;
}