java.util.Locale#getISOCountries ( )源码实例Demo

下面列出了java.util.Locale#getISOCountries ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: OpenEstate-IO   文件: LocaleUtils.java
/**
 * Translate a country name into another language.
 *
 * @param country  country name
 * @param language language to translate
 * @return translated country name or null, if no translation was found
 */
public static String translateCountryName(String country, Locale language) {
    country = StringUtils.trimToNull(country);
    if (country == null) return null;
    for (String iso2Code : Locale.getISOCountries()) {
        Locale countryLocale = new Locale(iso2Code, iso2Code);
        for (Locale translationLocale : LocaleUtils.availableLocaleList()) {
            String name = StringUtils.trimToNull(countryLocale.getDisplayCountry(translationLocale));
            if (name != null && name.equalsIgnoreCase(country)) {
                name = StringUtils.trimToNull(countryLocale.getDisplayCountry(language));
                if (name != null) return name;
            }
        }
    }
    return null;
}
 
源代码2 项目: TencentKona-8   文件: LocaleTest.java
/**
 * @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!");
}
 
源代码3 项目: jdk8u60   文件: LocaleTest.java
/**
 * @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!");
}
 
源代码4 项目: openjdk-jdk8u   文件: LocaleTest.java
/**
 * @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!");
}
 
源代码5 项目: CountryCurrencyPicker   文件: Country.java
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;
    }
}
 
源代码6 项目: j2objc   文件: LocaleTest.java
/**
 * java.util.Locale#getISOCountries()
 */
public void test_getISOCountries() {
    // Test for method java.lang.String []
    // java.util.Locale.getISOCountries()
    // Assumes all countries are 2 digits, and that there will always be
    // 230 countries on the list...
    String[] isoCountries = Locale.getISOCountries();
    int length = isoCountries.length;
    int familiarCount = 0;
    for (int i = 0; i < length; i++) {
        if (isoCountries[i].length() != 2) {
            fail("Wrong format for ISOCountries.");
        }
        if (isoCountries[i].equals("CA") || isoCountries[i].equals("BB")
                || isoCountries[i].equals("US")
                || isoCountries[i].equals("KR"))
            familiarCount++;
    }
    assertTrue("ISOCountries missing.", familiarCount == 4 && length > 230);
}
 
源代码7 项目: openjdk-8   文件: LocaleTest.java
/**
 * @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!");
}
 
源代码8 项目: jdk8u-dev-jdk   文件: LocaleTest.java
/**
 * @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!");
}
 
源代码9 项目: EasyVPN-Free   文件: CountriesNames.java
public static Map<String, String> getCountries() {
    Map<String, String> countries = new HashMap<String, String>();

    String[] isoCountries = Locale.getISOCountries();
    for (String country : isoCountries) {
        Locale locale = new Locale("", country);
        String iso = locale.getISO3Country();
        String code = locale.getCountry();
        String name = locale.getDisplayCountry();

        if (!"".equals(iso) && !"".equals(code)
                && !"".equals(name)) {
            countries.put(code, name);
        }
    }

    return countries;
}
 
源代码10 项目: OpenEstate-IO   文件: LocaleUtils.java
/**
 * Return an ISO-3 country code from a country name.
 *
 * @param country country name
 * @return ISO-3 country code or null, if no code was found
 */
public static String getCountryISO3(String country) {
    country = StringUtils.trimToNull(country);
    if (country == null)
        return null;
    if (country.length() == 3)
        return country;

    String[] iso2Codes = Locale.getISOCountries();
    if (country.length() == 2) {
        String iso3code = LocaleUtils.getCountryISO3FromISO2(country);
        if (iso3code != null) return iso3code;
    }

    for (String iso2Code : iso2Codes) {
        Locale countryLocale = new Locale(iso2Code, iso2Code);
        String iso3Code = StringUtils.trimToNull(countryLocale.getISO3Country());
        if (iso3Code == null) continue;
        for (Locale translationLocale : LocaleUtils.availableLocaleList()) {
            String name = StringUtils.trimToNull(countryLocale.getDisplayCountry(translationLocale));
            if (name != null && name.equalsIgnoreCase(country)) return iso3Code;
        }
    }
    return null;
}
 
源代码11 项目: smartcoins-wallet   文件: Helper.java
public static String getCountryCode(String spinnerText) {
    String[] locales = Locale.getISOCountries();
    ArrayList<String> countries = new ArrayList<>();
    for (String countryCode : locales) {

        Locale locale = new Locale("", countryCode);
        try {
            Currency currency = Currency.getInstance(locale);
            String proposedSpinnerText = locale.getDisplayCountry() + " (" + currency.getCurrencyCode() + ")";

            if (proposedSpinnerText.equals(spinnerText)) {
                return countryCode;
            }
        } catch (Exception e) {

        }
    }
    return "";
}
 
源代码12 项目: development   文件: CountryBean.java
/**
 * 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;
}
 
源代码13 项目: CountryPicker   文件: CountryPicker.java
private static List<Country> getAllCountries(List<String> userCountryCodes) {
  List<Country> countries = new ArrayList<Country>();

  for (String countryCode : Locale.getISOCountries()) {
    if (userCountryCodes.contains(countryCode)) {
      Country country = new Country();
      country.code = countryCode;
      country.name = new Locale("", countryCode).getDisplayCountry();
      countries.add(country);
    }
  }

  return countries;
}
 
源代码14 项目: development   文件: Organizations.java
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);
        }
    }
}
 
源代码15 项目: openjdk-jdk9   文件: Bug8071929.java
/**
 * 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);
    }
}
 
源代码16 项目: openjdk-jdk9   文件: Bug8071929.java
/**
 * 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);
    }
}
 
源代码17 项目: openjdk-jdk9   文件: Bug8071929.java
/**
 * 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);
    }
}
 
源代码18 项目: OpenEstate-IO   文件: LocaleUtils.java
/**
 * Create an ISO-2 country code from an ISO-3 country code.
 *
 * @param iso3Code ISO-3 country code
 * @return ISO-2 country code or null, if no code was found
 */
public static String getCountryISO2FromISO3(String iso3Code) {
    iso3Code = StringUtils.trimToNull(iso3Code);
    if (iso3Code == null) return null;
    if (iso3Code.length() == 3) {
        for (String iso2Code : Locale.getISOCountries()) {
            Locale countryLocale = new Locale(iso2Code, iso2Code);
            String countryISO3 = StringUtils.trimToNull(countryLocale.getISO3Country());
            if (countryISO3 != null && countryISO3.equalsIgnoreCase(iso3Code)) {
                return iso2Code;
            }
        }
    }
    return null;
}
 
源代码19 项目: edx-app-android   文件: LocaleUtils.java
/**
 * Provides the list of countries fetched from the system.
 *
 * @return A list of {@link FormOption} containing country names and their codes.
 */
public static List<FormOption> getCountries() {
    final List<FormOption> countries = new ArrayList<>();
    for (String countryCode : Locale.getISOCountries()) {
        try {
            countries.add(new FormOption(getCountryNameFromCode(countryCode), countryCode));
        } catch (InvalidLocaleException e) {
            e.printStackTrace();
        }
    }
    sortBasedOnLocale(countries);
    return countries;
}
 
源代码20 项目: development   文件: SupportedCountries.java
/**
 * 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);
    }
}