Java Code Examples for sun.util.locale.provider.LocaleProviderAdapter#forType()

The following examples show how to use sun.util.locale.provider.LocaleProviderAdapter#forType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocaleData.java    From Bytecoder with Apache License 2.0 6 votes vote down vote up
@Override
public List<Locale> getCandidateLocales(String baseName, Locale locale) {
    String key = baseName + '-' + locale.toLanguageTag();
    List<Locale> candidates = CANDIDATES_MAP.get(key);
    if (candidates == null) {
        LocaleProviderAdapter.Type type = baseName.contains(DOTCLDR) ? CLDR : JRE;
        LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
        candidates = adapter instanceof ResourceBundleBasedAdapter ?
            ((ResourceBundleBasedAdapter)adapter).getCandidateLocales(baseName, locale) :
            defaultControl.getCandidateLocales(baseName, locale);

        // Weed out Locales which are known to have no resource bundles
        int lastDot = baseName.lastIndexOf('.');
        String category = (lastDot >= 0) ? baseName.substring(lastDot + 1) : baseName;
        Set<String> langtags = ((JRELocaleProviderAdapter)adapter).getLanguageTagSet(category);
        if (!langtags.isEmpty()) {
            for (Iterator<Locale> itr = candidates.iterator(); itr.hasNext();) {
                if (!adapter.isSupportedProviderLocale(itr.next(), langtags)) {
                    itr.remove();
                }
            }
        }
        CANDIDATES_MAP.putIfAbsent(key, candidates);
    }
    return candidates;
}
 
Example 2
Source File: LocaleProviders.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
static void adapterTest(String expected, String lang, String ctry) {
    Locale testLocale = new Locale(lang, ctry);
    LocaleProviderAdapter ldaExpected =
        LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.valueOf(expected));
    if (!ldaExpected.getDateFormatProvider().isSupportedLocale(testLocale)) {
        System.out.println("test locale: "+testLocale+" is not supported by the expected provider: "+ldaExpected+". Ignoring the test.");
        return;
    }
    String preference = System.getProperty("java.locale.providers", "");
    LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale);
    LocaleProviderAdapter.Type type = lda.getAdapterType();
    System.out.printf("testLocale: %s, got: %s, expected: %s\n", testLocale, type, expected);
    if (!type.toString().equals(expected)) {
        throw new RuntimeException("Returned locale data adapter is not correct.");
    }
}
 
Example 3
Source File: LocaleProviders.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static void adapterTest(String expected, String lang, String ctry) {
    Locale testLocale = new Locale(lang, ctry);
    LocaleProviderAdapter ldaExpected =
        LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.valueOf(expected));
    if (!ldaExpected.getDateFormatProvider().isSupportedLocale(testLocale)) {
        System.out.println("test locale: "+testLocale+" is not supported by the expected provider: "+ldaExpected+". Ignoring the test.");
        return;
    }
    String preference = System.getProperty("java.locale.providers", "");
    LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale);
    LocaleProviderAdapter.Type type = lda.getAdapterType();
    System.out.printf("testLocale: %s, got: %s, expected: %s\n", testLocale, type, expected);
    if (!type.toString().equals(expected)) {
        throw new RuntimeException("Returned locale data adapter is not correct.");
    }
}
 
Example 4
Source File: LocaleData.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Override
 public List<Locale> getCandidateLocales(String baseName, Locale locale) {
    List<Locale> candidates = super.getCandidateLocales(baseName, locale);
    // Weed out Locales which are known to have no resource bundles
    int lastDot = baseName.lastIndexOf('.');
    String category = (lastDot >= 0) ? baseName.substring(lastDot + 1) : baseName;
    LocaleProviderAdapter.Type type = baseName.contains(DOTCLDR) ? CLDR : JRE;
    LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
    Set<String> langtags = ((JRELocaleProviderAdapter)adapter).getLanguageTagSet(category);
    if (!langtags.isEmpty()) {
        for (Iterator<Locale> itr = candidates.iterator(); itr.hasNext();) {
            if (!LocaleProviderAdapter.isSupportedLocale(itr.next(), type, langtags)) {
                itr.remove();
            }
        }
    }

    // Force fallback to Locale.ENGLISH for CLDR time zone names support
    if (locale.getLanguage() != "en"
            && type == CLDR && category.equals("TimeZoneNames")) {
        candidates.add(candidates.size() - 1, Locale.ENGLISH);
    }
    return candidates;
}
 
Example 5
Source File: LocaleProviders.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static void adapterTest(String expected, String lang, String ctry) {
    Locale testLocale = new Locale(lang, ctry);
    LocaleProviderAdapter ldaExpected =
        LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.valueOf(expected));
    if (!ldaExpected.getDateFormatProvider().isSupportedLocale(testLocale)) {
        System.out.println("test locale: "+testLocale+" is not supported by the expected provider: "+ldaExpected+". Ignoring the test.");
        return;
    }
    String preference = System.getProperty("java.locale.providers", "");
    LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale);
    LocaleProviderAdapter.Type type = lda.getAdapterType();
    System.out.printf("testLocale: %s, got: %s, expected: %s\n", testLocale, type, expected);
    if (!type.toString().equals(expected)) {
        throw new RuntimeException("Returned locale data adapter is not correct.");
    }
}
 
Example 6
Source File: LocaleProviders.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
static void adapterTest(String expected, String lang, String ctry) {
    Locale testLocale = new Locale(lang, ctry);
    LocaleProviderAdapter ldaExpected =
        LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.valueOf(expected));
    if (!ldaExpected.getDateFormatProvider().isSupportedLocale(testLocale)) {
        System.out.println("test locale: "+testLocale+" is not supported by the expected provider: "+ldaExpected+". Ignoring the test.");
        return;
    }
    String preference = System.getProperty("java.locale.providers", "");
    LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale);
    LocaleProviderAdapter.Type type = lda.getAdapterType();
    System.out.printf("testLocale: %s, got: %s, expected: %s\n", testLocale, type, expected);
    if (!type.toString().equals(expected)) {
        throw new RuntimeException("Returned locale data adapter is not correct.");
    }
}
 
Example 7
Source File: LocaleProviders.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
static void adapterTest(String expected, String lang, String ctry) {
    Locale testLocale = new Locale(lang, ctry);
    LocaleProviderAdapter ldaExpected =
        LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.valueOf(expected));
    if (!ldaExpected.getDateFormatProvider().isSupportedLocale(testLocale)) {
        System.out.println("test locale: "+testLocale+" is not supported by the expected provider: "+ldaExpected+". Ignoring the test.");
        return;
    }
    String preference = System.getProperty("java.locale.providers", "");
    LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale);
    LocaleProviderAdapter.Type type = lda.getAdapterType();
    System.out.printf("testLocale: %s, got: %s, expected: %s\n", testLocale, type, expected);
    if (!type.toString().equals(expected)) {
        throw new RuntimeException("Returned locale data adapter is not correct.");
    }
}
 
Example 8
Source File: LocaleProviders.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
static void adapterTest(String expected, String lang, String ctry) {
    Locale testLocale = new Locale(lang, ctry);
    LocaleProviderAdapter ldaExpected =
        LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.valueOf(expected));
    if (!ldaExpected.getDateFormatProvider().isSupportedLocale(testLocale)) {
        System.out.println("test locale: "+testLocale+" is not supported by the expected provider: "+ldaExpected+". Ignoring the test.");
        return;
    }
    String preference = System.getProperty("java.locale.providers", "");
    LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale);
    LocaleProviderAdapter.Type type = lda.getAdapterType();
    System.out.printf("testLocale: %s, got: %s, expected: %s\n", testLocale, type, expected);
    if (!type.toString().equals(expected)) {
        throw new RuntimeException("Returned locale data adapter is not correct.");
    }
}
 
Example 9
Source File: LocaleProviders.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
static void adapterTest(String expected, String lang, String ctry) {
    Locale testLocale = new Locale(lang, ctry);
    LocaleProviderAdapter ldaExpected =
        LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.valueOf(expected));
    if (!ldaExpected.getDateFormatProvider().isSupportedLocale(testLocale)) {
        System.out.println("test locale: "+testLocale+" is not supported by the expected provider: "+ldaExpected+". Ignoring the test.");
        return;
    }
    String preference = System.getProperty("java.locale.providers", "");
    LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale);
    LocaleProviderAdapter.Type type = lda.getAdapterType();
    System.out.printf("testLocale: %s, got: %s, expected: %s\n", testLocale, type, expected);
    if (!type.toString().equals(expected)) {
        throw new RuntimeException("Returned locale data adapter is not correct.");
    }
}
 
Example 10
Source File: LocaleData.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
 public List<Locale> getCandidateLocales(String baseName, Locale locale) {
    List<Locale> candidates = super.getCandidateLocales(baseName, locale);
    // Weed out Locales which are known to have no resource bundles
    int lastDot = baseName.lastIndexOf('.');
    String category = (lastDot >= 0) ? baseName.substring(lastDot + 1) : baseName;
    LocaleProviderAdapter.Type type = baseName.contains(DOTCLDR) ? CLDR : JRE;
    LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
    Set<String> langtags = ((JRELocaleProviderAdapter)adapter).getLanguageTagSet(category);
    if (!langtags.isEmpty()) {
        for (Iterator<Locale> itr = candidates.iterator(); itr.hasNext();) {
            if (!LocaleProviderAdapter.isSupportedLocale(itr.next(), type, langtags)) {
                itr.remove();
            }
        }
    }

    // Force fallback to Locale.ENGLISH for CLDR time zone names support
    if (locale.getLanguage() != "en"
            && type == CLDR && category.equals("TimeZoneNames")) {
        candidates.add(candidates.size() - 1, Locale.ENGLISH);
    }
    return candidates;
}
 
Example 11
Source File: LocaleProviders.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
static void adapterTest(String expected, String lang, String ctry) {
    Locale testLocale = new Locale(lang, ctry);
    LocaleProviderAdapter ldaExpected =
        LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.valueOf(expected));
    if (!ldaExpected.getDateFormatProvider().isSupportedLocale(testLocale)) {
        System.out.println("test locale: "+testLocale+" is not supported by the expected provider: "+ldaExpected+". Ignoring the test.");
        return;
    }
    String preference = System.getProperty("java.locale.providers", "");
    LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale);
    LocaleProviderAdapter.Type type = lda.getAdapterType();
    System.out.printf("testLocale: %s, got: %s, expected: %s\n", testLocale, type, expected);
    if (!type.toString().equals(expected)) {
        throw new RuntimeException("Returned locale data adapter is not correct.");
    }
}
 
Example 12
Source File: LocaleData.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
 public List<Locale> getCandidateLocales(String baseName, Locale locale) {
    List<Locale> candidates = super.getCandidateLocales(baseName, locale);
    // Weed out Locales which are known to have no resource bundles
    int lastDot = baseName.lastIndexOf('.');
    String category = (lastDot >= 0) ? baseName.substring(lastDot + 1) : baseName;
    LocaleProviderAdapter.Type type = baseName.contains(DOTCLDR) ? CLDR : JRE;
    LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
    Set<String> langtags = ((JRELocaleProviderAdapter)adapter).getLanguageTagSet(category);
    if (!langtags.isEmpty()) {
        for (Iterator<Locale> itr = candidates.iterator(); itr.hasNext();) {
            if (!LocaleProviderAdapter.isSupportedLocale(itr.next(), type, langtags)) {
                itr.remove();
            }
        }
    }

    // Force fallback to Locale.ENGLISH for CLDR time zone names support
    if (locale.getLanguage() != "en"
            && type == CLDR && category.equals("TimeZoneNames")) {
        candidates.add(candidates.size() - 1, Locale.ENGLISH);
    }
    return candidates;
}
 
Example 13
Source File: LocaleProviders.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
static void adapterTest(String expected, String lang, String ctry) {
    Locale testLocale = new Locale(lang, ctry);
    LocaleProviderAdapter ldaExpected =
        LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.valueOf(expected));
    if (!ldaExpected.getDateFormatProvider().isSupportedLocale(testLocale)) {
        System.out.println("test locale: "+testLocale+" is not supported by the expected provider: "+ldaExpected+". Ignoring the test.");
        return;
    }
    String preference = System.getProperty("java.locale.providers", "");
    LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale);
    LocaleProviderAdapter.Type type = lda.getAdapterType();
    System.out.printf("testLocale: %s, got: %s, expected: %s\n", testLocale, type, expected);
    if (!type.toString().equals(expected)) {
        throw new RuntimeException("Returned locale data adapter is not correct.");
    }
}
 
Example 14
Source File: LocaleData.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
 public List<Locale> getCandidateLocales(String baseName, Locale locale) {
    List<Locale> candidates = super.getCandidateLocales(baseName, locale);
    // Weed out Locales which are known to have no resource bundles
    int lastDot = baseName.lastIndexOf('.');
    String category = (lastDot >= 0) ? baseName.substring(lastDot + 1) : baseName;
    LocaleProviderAdapter.Type type = baseName.contains(DOTCLDR) ? CLDR : JRE;
    LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
    Set<String> langtags = ((JRELocaleProviderAdapter)adapter).getLanguageTagSet(category);
    if (!langtags.isEmpty()) {
        for (Iterator<Locale> itr = candidates.iterator(); itr.hasNext();) {
            if (!LocaleProviderAdapter.isSupportedLocale(itr.next(), type, langtags)) {
                itr.remove();
            }
        }
    }

    // Force fallback to Locale.ENGLISH for CLDR time zone names support
    if (locale.getLanguage() != "en"
            && type == CLDR && category.equals("TimeZoneNames")) {
        candidates.add(candidates.size() - 1, Locale.ENGLISH);
    }
    return candidates;
}
 
Example 15
Source File: LocaleProviders.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
static void adapterTest(String expected, String lang, String ctry) {
    Locale testLocale = new Locale(lang, ctry);
    LocaleProviderAdapter ldaExpected =
        LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.valueOf(expected));
    if (!ldaExpected.getDateFormatProvider().isSupportedLocale(testLocale)) {
        System.out.println("test locale: "+testLocale+" is not supported by the expected provider: "+ldaExpected+". Ignoring the test.");
        return;
    }
    String preference = System.getProperty("java.locale.providers", "");
    LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale);
    LocaleProviderAdapter.Type type = lda.getAdapterType();
    System.out.printf("testLocale: %s, got: %s, expected: %s\n", testLocale, type, expected);
    if (!type.toString().equals(expected)) {
        throw new RuntimeException("Returned locale data adapter is not correct.");
    }
}
 
Example 16
Source File: LocaleData.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Override
 public List<Locale> getCandidateLocales(String baseName, Locale locale) {
    List<Locale> candidates = super.getCandidateLocales(baseName, locale);
    // Weed out Locales which are known to have no resource bundles
    int lastDot = baseName.lastIndexOf('.');
    String category = (lastDot >= 0) ? baseName.substring(lastDot + 1) : baseName;
    LocaleProviderAdapter.Type type = baseName.contains(DOTCLDR) ? CLDR : JRE;
    LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
    Set<String> langtags = ((JRELocaleProviderAdapter)adapter).getLanguageTagSet(category);
    if (!langtags.isEmpty()) {
        for (Iterator<Locale> itr = candidates.iterator(); itr.hasNext();) {
            if (!LocaleProviderAdapter.isSupportedLocale(itr.next(), type, langtags)) {
                itr.remove();
            }
        }
    }

    // Force fallback to Locale.ENGLISH for CLDR time zone names support
    if (locale.getLanguage() != "en"
            && type == CLDR && category.equals("TimeZoneNames")) {
        candidates.add(candidates.size() - 1, Locale.ENGLISH);
    }
    return candidates;
}
 
Example 17
Source File: LocaleProviders.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static void adapterTest(String expected, String lang, String ctry) {
    Locale testLocale = new Locale(lang, ctry);
    LocaleProviderAdapter ldaExpected =
        LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.valueOf(expected));
    if (!ldaExpected.getDateFormatProvider().isSupportedLocale(testLocale)) {
        System.out.println("test locale: "+testLocale+" is not supported by the expected provider: "+ldaExpected+". Ignoring the test.");
        return;
    }
    String preference = System.getProperty("java.locale.providers", "");
    LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale);
    LocaleProviderAdapter.Type type = lda.getAdapterType();
    System.out.printf("testLocale: %s, got: %s, expected: %s\n", testLocale, type, expected);
    if (!type.toString().equals(expected)) {
        throw new RuntimeException("Returned locale data adapter is not correct.");
    }
}
 
Example 18
Source File: LocaleData.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
 public List<Locale> getCandidateLocales(String baseName, Locale locale) {
    List<Locale> candidates = super.getCandidateLocales(baseName, locale);
    // Weed out Locales which are known to have no resource bundles
    int lastDot = baseName.lastIndexOf('.');
    String category = (lastDot >= 0) ? baseName.substring(lastDot + 1) : baseName;
    LocaleProviderAdapter.Type type = baseName.contains(DOTCLDR) ? CLDR : JRE;
    LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
    Set<String> langtags = ((JRELocaleProviderAdapter)adapter).getLanguageTagSet(category);
    if (!langtags.isEmpty()) {
        for (Iterator<Locale> itr = candidates.iterator(); itr.hasNext();) {
            if (!LocaleProviderAdapter.isSupportedLocale(itr.next(), type, langtags)) {
                itr.remove();
            }
        }
    }

    // Force fallback to Locale.ENGLISH for CLDR time zone names support
    if (locale.getLanguage() != "en"
            && type == CLDR && category.equals("TimeZoneNames")) {
        candidates.add(candidates.size() - 1, Locale.ENGLISH);
    }
    return candidates;
}
 
Example 19
Source File: LocaleProviders.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
static void adapterTest(String expected, String lang, String ctry) {
    Locale testLocale = new Locale(lang, ctry);
    LocaleProviderAdapter ldaExpected =
        LocaleProviderAdapter.forType(LocaleProviderAdapter.Type.valueOf(expected));
    if (!ldaExpected.getDateFormatProvider().isSupportedLocale(testLocale)) {
        System.out.println("test locale: "+testLocale+" is not supported by the expected provider: "+ldaExpected+". Ignoring the test.");
        return;
    }
    String preference = System.getProperty("java.locale.providers", "");
    LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, testLocale);
    LocaleProviderAdapter.Type type = lda.getAdapterType();
    System.out.printf("testLocale: %s, got: %s, expected: %s\n", testLocale, type, expected);
    if (!type.toString().equals(expected)) {
        throw new RuntimeException("Returned locale data adapter is not correct.");
    }
}
 
Example 20
Source File: LocaleData.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public List<Locale> getCandidateLocales(String baseName, Locale locale) {
    String key = baseName + '-' + locale.toLanguageTag();
    List<Locale> candidates = CANDIDATES_MAP.get(key);
    if (candidates == null) {
        LocaleProviderAdapter.Type type = baseName.contains(DOTCLDR) ? CLDR : JRE;
        LocaleProviderAdapter adapter = LocaleProviderAdapter.forType(type);
        candidates = adapter instanceof ResourceBundleBasedAdapter ?
            ((ResourceBundleBasedAdapter)adapter).getCandidateLocales(baseName, locale) :
            defaultControl.getCandidateLocales(baseName, locale);

        // Weed out Locales which are known to have no resource bundles
        int lastDot = baseName.lastIndexOf('.');
        String category = (lastDot >= 0) ? baseName.substring(lastDot + 1) : baseName;
        Set<String> langtags = ((JRELocaleProviderAdapter)adapter).getLanguageTagSet(category);
        if (!langtags.isEmpty()) {
            for (Iterator<Locale> itr = candidates.iterator(); itr.hasNext();) {
                if (!adapter.isSupportedProviderLocale(itr.next(), langtags)) {
                    itr.remove();
                }
            }
        }
        // Force fallback to Locale.ENGLISH for CLDR time zone names support
        if (locale.getLanguage() != "en"
                && type == CLDR && category.equals("TimeZoneNames")) {
            candidates.add(candidates.size() - 1, Locale.ENGLISH);
        }
        CANDIDATES_MAP.putIfAbsent(key, candidates);
    }
    return candidates;
}