sun.util.locale.provider.LocaleProviderAdapter Java Examples

The following examples show how to use sun.util.locale.provider.LocaleProviderAdapter. 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 Project: Bytecoder   Author: mirkosertic   File: DateFormat.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates a DateFormat with the given time and/or date style in the given
 * locale.
 * @param timeStyle a value from 0 to 3 indicating the time format,
 * ignored if flags is 2
 * @param dateStyle a value from 0 to 3 indicating the time format,
 * ignored if flags is 1
 * @param flags either 1 for a time format, 2 for a date format,
 * or 3 for a date/time format
 * @param loc the locale for the format
 */
private static DateFormat get(int timeStyle, int dateStyle,
                              int flags, Locale loc) {
    if ((flags & 1) != 0) {
        if (timeStyle < 0 || timeStyle > 3) {
            throw new IllegalArgumentException("Illegal time style " + timeStyle);
        }
    } else {
        timeStyle = -1;
    }
    if ((flags & 2) != 0) {
        if (dateStyle < 0 || dateStyle > 3) {
            throw new IllegalArgumentException("Illegal date style " + dateStyle);
        }
    } else {
        dateStyle = -1;
    }

    LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, loc);
    DateFormat dateFormat = get(adapter, timeStyle, dateStyle, loc);
    if (dateFormat == null) {
        dateFormat = get(LocaleProviderAdapter.forJRE(), timeStyle, dateStyle, loc);
    }
    return dateFormat;
}
 
Example #2
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: BreakIterator.java    License: Apache License 2.0 6 votes vote down vote up
private static BreakIterator createBreakInstance(LocaleProviderAdapter adapter, Locale locale, int type) {
    BreakIteratorProvider breakIteratorProvider = adapter.getBreakIteratorProvider();
    BreakIterator iterator = null;
    switch (type) {
    case CHARACTER_INDEX:
        iterator = breakIteratorProvider.getCharacterInstance(locale);
        break;
    case WORD_INDEX:
        iterator = breakIteratorProvider.getWordInstance(locale);
        break;
    case LINE_INDEX:
        iterator = breakIteratorProvider.getLineInstance(locale);
        break;
    case SENTENCE_INDEX:
        iterator = breakIteratorProvider.getSentenceInstance(locale);
        break;
    }
    return iterator;
}
 
Example #3
Source Project: jdk8u60   Author: chenghanpeng   File: LocaleData.java    License: 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 #4
Source Project: jdk8u-dev-jdk   Author: frohoff   File: LocaleProviders.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void bug8013903Test() {
    if (System.getProperty("os.name").startsWith("Windows")) {
        Date sampleDate = new Date(0x10000000000L);
        String fallbackResult = "Heisei 16.Nov.03 (Wed) AM 11:53:47";
        String jreResult = "\u5e73\u6210 16.11.03 (\u6c34) \u5348\u524d 11:53:47";
        Locale l = new Locale("ja", "JP", "JP");
        SimpleDateFormat sdf = new SimpleDateFormat("GGGG yyyy.MMM.dd '('E')' a hh:mm:ss", l);
        sdf.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
        String result = sdf.format(sampleDate);
        System.out.println(result);
        if (LocaleProviderAdapter.getAdapterPreference()
            .contains(LocaleProviderAdapter.Type.JRE)) {
            if (!jreResult.equals(result)) {
                throw new RuntimeException("Format failed. result: \"" +
                    result + "\", expected: \"" + jreResult);
            }
        } else {
            // should be FALLBACK, as Windows HOST does not return
            // display names
            if (!fallbackResult.equals(result)) {
                throw new RuntimeException("Format failed. result: \"" +
                    result + "\", expected: \"" + fallbackResult);
            }
        }
    }
}
 
Example #5
Source Project: Bytecoder   Author: mirkosertic   File: CLDRCalendarNameProviderImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean isSupportedLocale(Locale locale) {
    if (Locale.ROOT.equals(locale)) {
        return true;
    }
    String calendarType = null;
    if (locale.hasExtensions()) {
        calendarType = locale.getUnicodeLocaleType("ca");
        locale = locale.stripExtensions();
    }
    if (calendarType != null) {
        switch (calendarType) {
            case "buddhist":
            case "japanese":
            case "gregory":
            case "islamic":
            case "roc":
                break;
            default:
                // Unknown calendar type
                return false;
        }
    }
    return LocaleProviderAdapter.forType(Type.CLDR).isSupportedProviderLocale(locale, langtags);
}
 
Example #6
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: LocaleProviders.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void bug8013903Test() {
    if (System.getProperty("os.name").startsWith("Windows")) {
        Date sampleDate = new Date(0x10000000000L);
        String hostResult = "\u5e73\u6210 16.11.03 (Wed) AM 11:53:47";
        String jreResult = "\u5e73\u6210 16.11.03 (\u6c34) \u5348\u524d 11:53:47";
        Locale l = new Locale("ja", "JP", "JP");
        SimpleDateFormat sdf = new SimpleDateFormat("GGGG yyyy.MMM.dd '('E')' a hh:mm:ss", l);
        sdf.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
        String result = sdf.format(sampleDate);
        System.out.println(result);
        if (LocaleProviderAdapter.getAdapterPreference()
            .contains(LocaleProviderAdapter.Type.JRE)) {
            if (!jreResult.equals(result)) {
                throw new RuntimeException("Format failed. result: \"" +
                    result + "\", expected: \"" + jreResult);
            }
        } else {
            // Windows display names. Subject to change if Windows changes its format.
            if (!hostResult.equals(result)) {
                throw new RuntimeException("Format failed. result: \"" +
                    result + "\", expected: \"" + hostResult);
            }
        }
    }
}
 
Example #7
Source Project: jdk8u_jdk   Author: JetBrains   File: LocaleData.java    License: 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 #8
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: LocaleProviders.java    License: GNU General Public License v2.0 6 votes vote down vote up
static void bug8013903Test() {
    if (System.getProperty("os.name").startsWith("Windows")) {
        Date sampleDate = new Date(0x10000000000L);
        String fallbackResult = "Heisei 16.Nov.03 (Wed) AM 11:53:47";
        String jreResult = "\u5e73\u6210 16.11.03 (\u6c34) \u5348\u524d 11:53:47";
        Locale l = new Locale("ja", "JP", "JP");
        SimpleDateFormat sdf = new SimpleDateFormat("GGGG yyyy.MMM.dd '('E')' a hh:mm:ss", l);
        sdf.setTimeZone(TimeZone.getTimeZone("America/Los_Angeles"));
        String result = sdf.format(sampleDate);
        System.out.println(result);
        if (LocaleProviderAdapter.getAdapterPreference()
            .contains(LocaleProviderAdapter.Type.JRE)) {
            if (!jreResult.equals(result)) {
                throw new RuntimeException("Format failed. result: \"" +
                    result + "\", expected: \"" + jreResult);
            }
        } else {
            // should be FALLBACK, as Windows HOST does not return
            // display names
            if (!fallbackResult.equals(result)) {
                throw new RuntimeException("Format failed. result: \"" +
                    result + "\", expected: \"" + fallbackResult);
            }
        }
    }
}
 
Example #9
Source Project: jdk8u60   Author: chenghanpeng   File: LocaleProviders.java    License: 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 Project: jdk8u-dev-jdk   Author: frohoff   File: LocaleProviders.java    License: 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 #11
Source Project: TencentKona-8   Author: Tencent   File: BreakIterator.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static BreakIterator createBreakInstance(LocaleProviderAdapter adapter, Locale locale, int type) {
    BreakIteratorProvider breakIteratorProvider = adapter.getBreakIteratorProvider();
    BreakIterator iterator = null;
    switch (type) {
    case CHARACTER_INDEX:
        iterator = breakIteratorProvider.getCharacterInstance(locale);
        break;
    case WORD_INDEX:
        iterator = breakIteratorProvider.getWordInstance(locale);
        break;
    case LINE_INDEX:
        iterator = breakIteratorProvider.getLineInstance(locale);
        break;
    case SENTENCE_INDEX:
        iterator = breakIteratorProvider.getSentenceInstance(locale);
        break;
    }
    return iterator;
}
 
Example #12
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: CLDRLocaleProviderAdapter.java    License: GNU General Public License v2.0 6 votes vote down vote up
public CLDRLocaleProviderAdapter() {
    LocaleDataMetaInfo nbmi = null;

    try {
        nbmi = AccessController.doPrivileged(new PrivilegedExceptionAction<LocaleDataMetaInfo>() {
            @Override
            public LocaleDataMetaInfo run() {
                for (LocaleDataMetaInfo ldmi : ServiceLoader.loadInstalled(LocaleDataMetaInfo.class)) {
                    if (ldmi.getType() == LocaleProviderAdapter.Type.CLDR) {
                        return ldmi;
                    }
                }
                return null;
            }
        });
    }  catch (Exception e) {
        // Catch any exception, and continue as if only CLDR's base locales exist.
    }

    nonBaseMetaInfo = nbmi;
}
 
Example #13
Source Project: openjdk-8   Author: bpupadhyaya   File: BreakIterator.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static BreakIterator createBreakInstance(LocaleProviderAdapter adapter, Locale locale, int type) {
    BreakIteratorProvider breakIteratorProvider = adapter.getBreakIteratorProvider();
    BreakIterator iterator = null;
    switch (type) {
    case CHARACTER_INDEX:
        iterator = breakIteratorProvider.getCharacterInstance(locale);
        break;
    case WORD_INDEX:
        iterator = breakIteratorProvider.getWordInstance(locale);
        break;
    case LINE_INDEX:
        iterator = breakIteratorProvider.getLineInstance(locale);
        break;
    case SENTENCE_INDEX:
        iterator = breakIteratorProvider.getSentenceInstance(locale);
        break;
    }
    return iterator;
}
 
Example #14
Source Project: TencentKona-8   Author: Tencent   File: LocaleProviders.java    License: 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 #15
Source Project: TencentKona-8   Author: Tencent   File: LocaleData.java    License: 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 #16
Source Project: Java8CN   Author: Java8-CNAPI-Team   File: BreakIterator.java    License: Apache License 2.0 6 votes vote down vote up
private static BreakIterator createBreakInstance(LocaleProviderAdapter adapter, Locale locale, int type) {
    BreakIteratorProvider breakIteratorProvider = adapter.getBreakIteratorProvider();
    BreakIterator iterator = null;
    switch (type) {
    case CHARACTER_INDEX:
        iterator = breakIteratorProvider.getCharacterInstance(locale);
        break;
    case WORD_INDEX:
        iterator = breakIteratorProvider.getWordInstance(locale);
        break;
    case LINE_INDEX:
        iterator = breakIteratorProvider.getLineInstance(locale);
        break;
    case SENTENCE_INDEX:
        iterator = breakIteratorProvider.getSentenceInstance(locale);
        break;
    }
    return iterator;
}
 
Example #17
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: IsoFields.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public String getDisplayName(Locale locale) {
    Objects.requireNonNull(locale, "locale");
    LocaleResources lr = LocaleProviderAdapter.getResourceBundleBased()
                                .getLocaleResources(locale);
    ResourceBundle rb = lr.getJavaTimeFormatData();
    return rb.containsKey("field.week") ? rb.getString("field.week") : toString();
}
 
Example #18
Source Project: jdk8u60   Author: chenghanpeng   File: JSpinner.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static String getDefaultPattern(Locale locale) {
    // Get the pattern for the default locale.
    LocaleProviderAdapter adapter;
    adapter = LocaleProviderAdapter.getAdapter(NumberFormatProvider.class,
                                               locale);
    LocaleResources lr = adapter.getLocaleResources(locale);
    if (lr == null) {
        lr = LocaleProviderAdapter.forJRE().getLocaleResources(locale);
    }
    String[] all = lr.getNumberPatterns();
    return all[0];
}
 
Example #19
Source Project: jdk8u-dev-jdk   Author: frohoff   File: NumberFormat.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static NumberFormat getInstance(Locale desiredLocale,
                                       int choice) {
    LocaleProviderAdapter adapter;
    adapter = LocaleProviderAdapter.getAdapter(NumberFormatProvider.class,
                                               desiredLocale);
    NumberFormat numberFormat = getInstance(adapter, desiredLocale, choice);
    if (numberFormat == null) {
        numberFormat = getInstance(LocaleProviderAdapter.forJRE(),
                                   desiredLocale, choice);
    }
    return numberFormat;
}
 
Example #20
Source Project: Java8CN   Author: Java8-CNAPI-Team   File: Collator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Gets the Collator for the desired locale.
 * @param desiredLocale the desired locale.
 * @return the Collator for the desired locale.
 * @see java.util.Locale
 * @see java.util.ResourceBundle
 */
public static Collator getInstance(Locale desiredLocale) {
    SoftReference<Collator> ref = cache.get(desiredLocale);
    Collator result = (ref != null) ? ref.get() : null;
    if (result == null) {
        LocaleProviderAdapter adapter;
        adapter = LocaleProviderAdapter.getAdapter(CollatorProvider.class,
                                                   desiredLocale);
        CollatorProvider provider = adapter.getCollatorProvider();
        result = provider.getInstance(desiredLocale);
        if (result == null) {
            result = LocaleProviderAdapter.forJRE()
                         .getCollatorProvider().getInstance(desiredLocale);
        }
        while (true) {
            if (ref != null) {
                // Remove the empty SoftReference if any
                cache.remove(desiredLocale, ref);
            }
            ref = cache.putIfAbsent(desiredLocale, new SoftReference<>(result));
            if (ref == null) {
                break;
            }
            Collator cachedColl = ref.get();
            if (cachedColl != null) {
                result = cachedColl;
                break;
            }
        }
    }
    return (Collator) result.clone(); // make the world safe
}
 
Example #21
Source Project: jdk1.8-source-analysis   Author: raysonfang   File: Locale.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Returns a name for the locale's variant code that is appropriate for display to the
 * user.  If possible, the name will be localized for inLocale.  If the locale
 * doesn't specify a variant code, this function returns the empty string.
 *
 * @param inLocale The locale for which to retrieve the display variant code.
 * @return The name of the display variant code appropriate to the given locale.
 * @exception NullPointerException if <code>inLocale</code> is <code>null</code>
 */
public String getDisplayVariant(Locale inLocale) {
    if (baseLocale.getVariant().length() == 0)
        return "";

    LocaleResources lr = LocaleProviderAdapter.forJRE().getLocaleResources(inLocale);

    String names[] = getDisplayVariantArray(inLocale);

    // Get the localized patterns for formatting a list, and use
    // them to format the list.
    return formatList(names,
                      lr.getLocaleName("ListPattern"),
                      lr.getLocaleName("ListCompositionPattern"));
}
 
Example #22
Source Project: jdk8u60   Author: chenghanpeng   File: WeekFields.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getDisplayName(Locale locale) {
    Objects.requireNonNull(locale, "locale");
    if (rangeUnit == YEARS) {  // only have values for week-of-year
        LocaleResources lr = LocaleProviderAdapter.getResourceBundleBased()
                .getLocaleResources(locale);
        ResourceBundle rb = lr.getJavaTimeFormatData();
        return rb.containsKey("field.week") ? rb.getString("field.week") : name;
    }
    return name;
}
 
Example #23
Source Project: hottub   Author: dsrg-uoft   File: Locale.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a name for the locale's variant code that is appropriate for display to the
 * user.  If possible, the name will be localized for inLocale.  If the locale
 * doesn't specify a variant code, this function returns the empty string.
 *
 * @param inLocale The locale for which to retrieve the display variant code.
 * @return The name of the display variant code appropriate to the given locale.
 * @exception NullPointerException if <code>inLocale</code> is <code>null</code>
 */
public String getDisplayVariant(Locale inLocale) {
    if (baseLocale.getVariant().length() == 0)
        return "";

    LocaleResources lr = LocaleProviderAdapter.forJRE().getLocaleResources(inLocale);

    String names[] = getDisplayVariantArray(inLocale);

    // Get the localized patterns for formatting a list, and use
    // them to format the list.
    return formatList(names,
                      lr.getLocaleName("ListPattern"),
                      lr.getLocaleName("ListCompositionPattern"));
}
 
Example #24
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: NumberFormat.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static NumberFormat getInstance(Locale desiredLocale,
                                       int choice) {
    LocaleProviderAdapter adapter;
    adapter = LocaleProviderAdapter.getAdapter(NumberFormatProvider.class,
                                               desiredLocale);
    NumberFormat numberFormat = getInstance(adapter, desiredLocale, choice);
    if (numberFormat == null) {
        numberFormat = getInstance(LocaleProviderAdapter.forJRE(),
                                   desiredLocale, choice);
    }
    return numberFormat;
}
 
Example #25
Source Project: openjdk-8-source   Author: keerath   File: NumberFormat.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static NumberFormat getInstance(Locale desiredLocale,
                                       int choice) {
    LocaleProviderAdapter adapter;
    adapter = LocaleProviderAdapter.getAdapter(NumberFormatProvider.class,
                                               desiredLocale);
    NumberFormat numberFormat = getInstance(adapter, desiredLocale, choice);
    if (numberFormat == null) {
        numberFormat = getInstance(LocaleProviderAdapter.forJRE(),
                                   desiredLocale, choice);
    }
    return numberFormat;
}
 
Example #26
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: Locale.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Returns a name for the locale's variant code that is appropriate for display to the
 * user.  If possible, the name will be localized for inLocale.  If the locale
 * doesn't specify a variant code, this function returns the empty string.
 *
 * @param inLocale The locale for which to retrieve the display variant code.
 * @return The name of the display variant code appropriate to the given locale.
 * @exception NullPointerException if <code>inLocale</code> is <code>null</code>
 */
public String getDisplayVariant(Locale inLocale) {
    if (baseLocale.getVariant().length() == 0)
        return "";

    LocaleResources lr = LocaleProviderAdapter.forJRE().getLocaleResources(inLocale);

    String names[] = getDisplayVariantArray(inLocale);

    // Get the localized patterns for formatting a list, and use
    // them to format the list.
    return formatList(names,
                      lr.getLocaleName("ListPattern"),
                      lr.getLocaleName("ListCompositionPattern"));
}
 
Example #27
Source Project: jdk8u60   Author: chenghanpeng   File: BreakIterator.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static BreakIterator createBreakInstance(Locale locale,
                                                 int type) {
    LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(BreakIteratorProvider.class, locale);
    BreakIterator iterator = createBreakInstance(adapter, locale, type);
    if (iterator == null) {
        iterator = createBreakInstance(LocaleProviderAdapter.forJRE(), locale, type);
    }
    return iterator;
}
 
Example #28
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: Bug8004240.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    List<LocaleProviderAdapter.Type> types = LocaleProviderAdapter.getAdapterPreference();

    try {
        types.set(0, null);
    } catch (UnsupportedOperationException e) {
        // success
        return;
    }

    throw new RuntimeException("LocaleProviderAdapter.getAdapterPrefence() returned a modifiable list.");
}
 
Example #29
Source Project: dragonwell8_jdk   Author: alibaba   File: Collator.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gets the Collator for the desired locale.
 * @param desiredLocale the desired locale.
 * @return the Collator for the desired locale.
 * @see java.util.Locale
 * @see java.util.ResourceBundle
 */
public static Collator getInstance(Locale desiredLocale) {
    SoftReference<Collator> ref = cache.get(desiredLocale);
    Collator result = (ref != null) ? ref.get() : null;
    if (result == null) {
        LocaleProviderAdapter adapter;
        adapter = LocaleProviderAdapter.getAdapter(CollatorProvider.class,
                                                   desiredLocale);
        CollatorProvider provider = adapter.getCollatorProvider();
        result = provider.getInstance(desiredLocale);
        if (result == null) {
            result = LocaleProviderAdapter.forJRE()
                         .getCollatorProvider().getInstance(desiredLocale);
        }
        while (true) {
            if (ref != null) {
                // Remove the empty SoftReference if any
                cache.remove(desiredLocale, ref);
            }
            ref = cache.putIfAbsent(desiredLocale, new SoftReference<>(result));
            if (ref == null) {
                break;
            }
            Collator cachedColl = ref.get();
            if (cachedColl != null) {
                result = cachedColl;
                break;
            }
        }
    }
    return (Collator) result.clone(); // make the world safe
}
 
Example #30
Source Project: openjdk-8   Author: bpupadhyaya   File: JSpinner.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static String getDefaultPattern(Locale loc) {
    LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, loc);
    LocaleResources lr = adapter.getLocaleResources(loc);
    if (lr == null) {
        lr = LocaleProviderAdapter.forJRE().getLocaleResources(loc);
    }
    return lr.getDateTimePattern(DateFormat.SHORT, DateFormat.SHORT, null);
}