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

The following examples show how to use sun.util.locale.provider.LocaleProviderAdapter#getAdapter() . 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: 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 2
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 3
Source File: DateFormat.java    From jdk1.8-source-analysis with 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 4
Source File: NumberFormat.java    From jdk8u-jdk with 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 5
Source File: NumberFormat.java    From hottub with 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 6
Source File: JSpinner.java    From jdk8u-jdk with 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 7
Source File: NumberFormat.java    From Java8CN with Apache License 2.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 8
Source File: JSpinner.java    From jdk8u-jdk with 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 9
Source File: BreakIterator.java    From dragonwell8_jdk with 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 10
Source File: NumberFormat.java    From openjdk-jdk9 with 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 11
Source File: BreakIterator.java    From jdk8u60 with 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 12
Source File: LocaleProviders.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static void bug7198834Test() {
    LocaleProviderAdapter lda = LocaleProviderAdapter.getAdapter(DateFormatProvider.class, Locale.US);
    LocaleProviderAdapter.Type type = lda.getAdapterType();
    if (type == LocaleProviderAdapter.Type.HOST && System.getProperty("os.name").startsWith("Windows")) {
        DateFormat df = DateFormat.getDateInstance(DateFormat.FULL, Locale.US);
        String date = df.format(new Date());
        if (date.charAt(date.length()-1) == ' ') {
            throw new RuntimeException("Windows Host Locale Provider returns a trailing space.");
        }
    } else {
        System.out.println("Windows HOST locale adapter not found. Ignoring this test.");
    }
}
 
Example 13
Source File: LocaleProviders.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
static void bug8010666Test() {
    if (System.getProperty("os.name").startsWith("Windows")) {
        NumberFormat nf = NumberFormat.getInstance(Locale.US);
        try {
            double ver = nf.parse(System.getProperty("os.version"))
                           .doubleValue();
            System.out.printf("Windows version: %.1f\n", ver);
            if (ver >= 6.0) {
                LocaleProviderAdapter lda =
                    LocaleProviderAdapter.getAdapter(
                        LocaleNameProvider.class, Locale.ENGLISH);
                LocaleProviderAdapter.Type type = lda.getAdapterType();
                if (type == LocaleProviderAdapter.Type.HOST) {
                    LocaleNameProvider lnp = lda.getLocaleNameProvider();
                    Locale mkmk = Locale.forLanguageTag("mk-MK");
                    String result = mkmk.getDisplayLanguage(Locale.ENGLISH);
                    String hostResult =
                        lnp.getDisplayLanguage(mkmk.getLanguage(),
                                               Locale.ENGLISH);
                    System.out.printf("  Display language name for" +
                        " (mk_MK): result(HOST): \"%s\", returned: \"%s\"\n",
                        hostResult, result);
                    if (result == null ||
                        hostResult != null &&
                        !result.equals(hostResult)) {
                        throw new RuntimeException("Display language name" +
                            " mismatch for \"mk\". Returned name was" +
                            " \"" + result + "\", result(HOST): \"" +
                            hostResult + "\"");
                    }
                    result = Locale.US.getDisplayLanguage(Locale.ENGLISH);
                    hostResult =
                        lnp.getDisplayLanguage(Locale.US.getLanguage(),
                                               Locale.ENGLISH);
                    System.out.printf("  Display language name for" +
                        " (en_US): result(HOST): \"%s\", returned: \"%s\"\n",
                        hostResult, result);
                    if (result == null ||
                        hostResult != null &&
                        !result.equals(hostResult)) {
                        throw new RuntimeException("Display language name" +
                            " mismatch for \"en\". Returned name was" +
                            " \"" + result + "\", result(HOST): \"" +
                            hostResult + "\"");
                    }
                    if (ver >= 6.1) {
                        result = Locale.US.getDisplayCountry(Locale.ENGLISH);
                        hostResult = lnp.getDisplayCountry(
                            Locale.US.getCountry(), Locale.ENGLISH);
                        System.out.printf("  Display country name for" +
                            " (en_US): result(HOST): \"%s\", returned: \"%s\"\n",
                            hostResult, result);
                        if (result == null ||
                            hostResult != null &&
                            !result.equals(hostResult)) {
                            throw new RuntimeException("Display country name" +
                                " mismatch for \"US\". Returned name was" +
                                " \"" + result + "\", result(HOST): \"" +
                                hostResult + "\"");
                        }
                    }
                } else {
                    throw new RuntimeException("Windows Host" +
                        " LocaleProviderAdapter was not selected for" +
                        " English locale.");
                }
            }
        } catch (ParseException pe) {
            throw new RuntimeException("Parsing Windows version failed: "+pe.toString());
        }
    }
}
 
Example 14
Source File: LocaleProviders.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
static void bug8010666Test() {
    if (System.getProperty("os.name").startsWith("Windows")) {
        NumberFormat nf = NumberFormat.getInstance(Locale.US);
        try {
            double ver = nf.parse(System.getProperty("os.version"))
                           .doubleValue();
            System.out.printf("Windows version: %.1f\n", ver);
            if (ver >= 6.0) {
                LocaleProviderAdapter lda =
                    LocaleProviderAdapter.getAdapter(
                        LocaleNameProvider.class, Locale.ENGLISH);
                LocaleProviderAdapter.Type type = lda.getAdapterType();
                if (type == LocaleProviderAdapter.Type.HOST) {
                    LocaleNameProvider lnp = lda.getLocaleNameProvider();
                    Locale mkmk = Locale.forLanguageTag("mk-MK");
                    String result = mkmk.getDisplayLanguage(Locale.ENGLISH);
                    String hostResult =
                        lnp.getDisplayLanguage(mkmk.getLanguage(),
                                               Locale.ENGLISH);
                    System.out.printf("  Display language name for" +
                        " (mk_MK): result(HOST): \"%s\", returned: \"%s\"\n",
                        hostResult, result);
                    if (result == null ||
                        hostResult != null &&
                        !result.equals(hostResult)) {
                        throw new RuntimeException("Display language name" +
                            " mismatch for \"mk\". Returned name was" +
                            " \"" + result + "\", result(HOST): \"" +
                            hostResult + "\"");
                    }
                    result = Locale.US.getDisplayLanguage(Locale.ENGLISH);
                    hostResult =
                        lnp.getDisplayLanguage(Locale.US.getLanguage(),
                                               Locale.ENGLISH);
                    System.out.printf("  Display language name for" +
                        " (en_US): result(HOST): \"%s\", returned: \"%s\"\n",
                        hostResult, result);
                    if (result == null ||
                        hostResult != null &&
                        !result.equals(hostResult)) {
                        throw new RuntimeException("Display language name" +
                            " mismatch for \"en\". Returned name was" +
                            " \"" + result + "\", result(HOST): \"" +
                            hostResult + "\"");
                    }
                    if (ver >= 6.1) {
                        result = Locale.US.getDisplayCountry(Locale.ENGLISH);
                        hostResult = lnp.getDisplayCountry(
                            Locale.US.getCountry(), Locale.ENGLISH);
                        System.out.printf("  Display country name for" +
                            " (en_US): result(HOST): \"%s\", returned: \"%s\"\n",
                            hostResult, result);
                        if (result == null ||
                            hostResult != null &&
                            !result.equals(hostResult)) {
                            throw new RuntimeException("Display country name" +
                                " mismatch for \"US\". Returned name was" +
                                " \"" + result + "\", result(HOST): \"" +
                                hostResult + "\"");
                        }
                    }
                } else {
                    throw new RuntimeException("Windows Host" +
                        " LocaleProviderAdapter was not selected for" +
                        " English locale.");
                }
            }
        } catch (ParseException pe) {
            throw new RuntimeException("Parsing Windows version failed: "+pe.toString());
        }
    }
}
 
Example 15
Source File: LocaleProviders.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
static void bug8010666Test() {
    if (System.getProperty("os.name").startsWith("Windows")) {
        NumberFormat nf = NumberFormat.getInstance(Locale.US);
        try {
            double ver = nf.parse(System.getProperty("os.version"))
                           .doubleValue();
            System.out.printf("Windows version: %.1f\n", ver);
            if (ver >= 6.0) {
                LocaleProviderAdapter lda =
                    LocaleProviderAdapter.getAdapter(
                        LocaleNameProvider.class, Locale.ENGLISH);
                LocaleProviderAdapter.Type type = lda.getAdapterType();
                if (type == LocaleProviderAdapter.Type.HOST) {
                    LocaleNameProvider lnp = lda.getLocaleNameProvider();
                    Locale mkmk = Locale.forLanguageTag("mk-MK");
                    String result = mkmk.getDisplayLanguage(Locale.ENGLISH);
                    String hostResult =
                        lnp.getDisplayLanguage(mkmk.getLanguage(),
                                               Locale.ENGLISH);
                    System.out.printf("  Display language name for" +
                        " (mk_MK): result(HOST): \"%s\", returned: \"%s\"\n",
                        hostResult, result);
                    if (result == null ||
                        hostResult != null &&
                        !result.equals(hostResult)) {
                        throw new RuntimeException("Display language name" +
                            " mismatch for \"mk\". Returned name was" +
                            " \"" + result + "\", result(HOST): \"" +
                            hostResult + "\"");
                    }
                    result = Locale.US.getDisplayLanguage(Locale.ENGLISH);
                    hostResult =
                        lnp.getDisplayLanguage(Locale.US.getLanguage(),
                                               Locale.ENGLISH);
                    System.out.printf("  Display language name for" +
                        " (en_US): result(HOST): \"%s\", returned: \"%s\"\n",
                        hostResult, result);
                    if (result == null ||
                        hostResult != null &&
                        !result.equals(hostResult)) {
                        throw new RuntimeException("Display language name" +
                            " mismatch for \"en\". Returned name was" +
                            " \"" + result + "\", result(HOST): \"" +
                            hostResult + "\"");
                    }
                    if (ver >= 6.1) {
                        result = Locale.US.getDisplayCountry(Locale.ENGLISH);
                        hostResult = lnp.getDisplayCountry(
                            Locale.US.getCountry(), Locale.ENGLISH);
                        System.out.printf("  Display country name for" +
                            " (en_US): result(HOST): \"%s\", returned: \"%s\"\n",
                            hostResult, result);
                        if (result == null ||
                            hostResult != null &&
                            !result.equals(hostResult)) {
                            throw new RuntimeException("Display country name" +
                                " mismatch for \"US\". Returned name was" +
                                " \"" + result + "\", result(HOST): \"" +
                                hostResult + "\"");
                        }
                    }
                } else {
                    throw new RuntimeException("Windows Host" +
                        " LocaleProviderAdapter was not selected for" +
                        " English locale.");
                }
            }
        } catch (ParseException pe) {
            throw new RuntimeException("Parsing Windows version failed: "+pe.toString());
        }
    }
}
 
Example 16
Source File: DateFormatSymbols.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void initializeData(Locale desiredLocale) {
    locale = desiredLocale;

    // Copy values of a cached instance if any.
    SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale);
    DateFormatSymbols dfs;
    if (ref != null && (dfs = ref.get()) != null) {
        copyMembers(dfs, this);
        return;
    }

    // Initialize the fields from the ResourceBundle for locale.
    LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale);
    // Avoid any potential recursions
    if (!(adapter instanceof ResourceBundleBasedAdapter)) {
        adapter = LocaleProviderAdapter.getResourceBundleBased();
    }
    ResourceBundle resource = ((ResourceBundleBasedAdapter)adapter).getLocaleData().getDateFormatData(locale);

    // JRE and CLDR use different keys
    // JRE: Eras, short.Eras and narrow.Eras
    // CLDR: long.Eras, Eras and narrow.Eras
    if (resource.containsKey("Eras")) {
        eras = resource.getStringArray("Eras");
    } else if (resource.containsKey("long.Eras")) {
        eras = resource.getStringArray("long.Eras");
    } else if (resource.containsKey("short.Eras")) {
        eras = resource.getStringArray("short.Eras");
    }
    months = resource.getStringArray("MonthNames");
    shortMonths = resource.getStringArray("MonthAbbreviations");
    ampms = resource.getStringArray("AmPmMarkers");
    localPatternChars = resource.getString("DateTimePatternChars");

    // Day of week names are stored in a 1-based array.
    weekdays = toOneBasedArray(resource.getStringArray("DayNames"));
    shortWeekdays = toOneBasedArray(resource.getStringArray("DayAbbreviations"));

    // Put a clone in the cache
    ref = new SoftReference<>((DateFormatSymbols)this.clone());
    SoftReference<DateFormatSymbols> x = cachedInstances.putIfAbsent(locale, ref);
    if (x != null) {
        DateFormatSymbols y = x.get();
        if (y == null) {
            // Replace the empty SoftReference with ref.
            cachedInstances.put(locale, ref);
        }
    }
}
 
Example 17
Source File: DateFormatSymbols.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Initializes this DateFormatSymbols with the locale data. This method uses
 * a cached DateFormatSymbols instance for the given locale if available. If
 * there's no cached one, this method creates an uninitialized instance and
 * populates its fields from the resource bundle for the locale, and caches
 * the instance. Note: zoneStrings isn't initialized in this method.
 */
private void initializeData(Locale locale) {
    SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale);
    DateFormatSymbols dfs;
    if (ref == null || (dfs = ref.get()) == null) {
        if (ref != null) {
            // Remove the empty SoftReference
            cachedInstances.remove(locale, ref);
        }
        dfs = new DateFormatSymbols(false);

        // Initialize the fields from the ResourceBundle for locale.
        LocaleProviderAdapter adapter
            = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale);
        // Avoid any potential recursions
        if (!(adapter instanceof ResourceBundleBasedAdapter)) {
            adapter = LocaleProviderAdapter.getResourceBundleBased();
        }
        ResourceBundle resource
            = ((ResourceBundleBasedAdapter)adapter).getLocaleData().getDateFormatData(locale);

        dfs.locale = locale;
        // JRE and CLDR use different keys
        // JRE: Eras, short.Eras and narrow.Eras
        // CLDR: long.Eras, Eras and narrow.Eras
        if (resource.containsKey("Eras")) {
            dfs.eras = resource.getStringArray("Eras");
        } else if (resource.containsKey("long.Eras")) {
            dfs.eras = resource.getStringArray("long.Eras");
        } else if (resource.containsKey("short.Eras")) {
            dfs.eras = resource.getStringArray("short.Eras");
        }
        dfs.months = resource.getStringArray("MonthNames");
        dfs.shortMonths = resource.getStringArray("MonthAbbreviations");
        dfs.ampms = resource.getStringArray("AmPmMarkers");
        dfs.localPatternChars = resource.getString("DateTimePatternChars");

        // Day of week names are stored in a 1-based array.
        dfs.weekdays = toOneBasedArray(resource.getStringArray("DayNames"));
        dfs.shortWeekdays = toOneBasedArray(resource.getStringArray("DayAbbreviations"));

        // Put dfs in the cache
        ref = new SoftReference<>(dfs);
        SoftReference<DateFormatSymbols> x = cachedInstances.putIfAbsent(locale, ref);
        if (x != null) {
            DateFormatSymbols y = x.get();
            if (y == null) {
                // Replace the empty SoftReference with ref.
                cachedInstances.replace(locale, x, ref);
            } else {
                ref = x;
                dfs = y;
            }
        }
        // If the bundle's locale isn't the target locale, put another cache
        // entry for the bundle's locale.
        Locale bundleLocale = resource.getLocale();
        if (!bundleLocale.equals(locale)) {
            SoftReference<DateFormatSymbols> z
                = cachedInstances.putIfAbsent(bundleLocale, ref);
            if (z != null && z.get() == null) {
                cachedInstances.replace(bundleLocale, z, ref);
            }
        }
    }

    // Copy the field values from dfs to this instance.
    copyMembers(dfs, this);
}
 
Example 18
Source File: DecimalFormatSymbols.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Gets the <code>DecimalFormatSymbols</code> instance for the specified
 * locale.  This method provides access to <code>DecimalFormatSymbols</code>
 * instances for locales supported by the Java runtime itself as well
 * as for those supported by installed
 * {@link java.text.spi.DecimalFormatSymbolsProvider
 * DecimalFormatSymbolsProvider} implementations.
 * If the specified locale contains the {@link java.util.Locale#UNICODE_LOCALE_EXTENSION}
 * for the numbering system, the instance is initialized with the specified numbering
 * system if the JRE implementation supports it. For example,
 * <pre>
 * NumberFormat.getNumberInstance(Locale.forLanguageTag("th-TH-u-nu-thai"))
 * </pre>
 * This may return a {@code NumberFormat} instance with the Thai numbering system,
 * instead of the Latin numbering system.
 *
 * @param locale the desired locale.
 * @return a <code>DecimalFormatSymbols</code> instance.
 * @exception NullPointerException if <code>locale</code> is null
 * @since 1.6
 */
public static final DecimalFormatSymbols getInstance(Locale locale) {
    LocaleProviderAdapter adapter;
    adapter = LocaleProviderAdapter.getAdapter(DecimalFormatSymbolsProvider.class, locale);
    DecimalFormatSymbolsProvider provider = adapter.getDecimalFormatSymbolsProvider();
    DecimalFormatSymbols dfsyms = provider.getInstance(locale);
    if (dfsyms == null) {
        provider = LocaleProviderAdapter.forJRE().getDecimalFormatSymbolsProvider();
        dfsyms = provider.getInstance(locale);
    }
    return dfsyms;
}
 
Example 19
Source File: DecimalFormatSymbols.java    From jdk1.8-source-analysis with Apache License 2.0 3 votes vote down vote up
/**
 * Gets the <code>DecimalFormatSymbols</code> instance for the specified
 * locale.  This method provides access to <code>DecimalFormatSymbols</code>
 * instances for locales supported by the Java runtime itself as well
 * as for those supported by installed
 * {@link java.text.spi.DecimalFormatSymbolsProvider
 * DecimalFormatSymbolsProvider} implementations.
 * If the specified locale contains the {@link java.util.Locale#UNICODE_LOCALE_EXTENSION}
 * for the numbering system, the instance is initialized with the specified numbering
 * system if the JRE implementation supports it. For example,
 * <pre>
 * NumberFormat.getNumberInstance(Locale.forLanguageTag("th-TH-u-nu-thai"))
 * </pre>
 * This may return a {@code NumberFormat} instance with the Thai numbering system,
 * instead of the Latin numbering system.
 *
 * @param locale the desired locale.
 * @return a <code>DecimalFormatSymbols</code> instance.
 * @exception NullPointerException if <code>locale</code> is null
 * @since 1.6
 */
public static final DecimalFormatSymbols getInstance(Locale locale) {
    LocaleProviderAdapter adapter;
    adapter = LocaleProviderAdapter.getAdapter(DecimalFormatSymbolsProvider.class, locale);
    DecimalFormatSymbolsProvider provider = adapter.getDecimalFormatSymbolsProvider();
    DecimalFormatSymbols dfsyms = provider.getInstance(locale);
    if (dfsyms == null) {
        provider = LocaleProviderAdapter.forJRE().getDecimalFormatSymbolsProvider();
        dfsyms = provider.getInstance(locale);
    }
    return dfsyms;
}
 
Example 20
Source File: DecimalFormatSymbols.java    From Java8CN with Apache License 2.0 3 votes vote down vote up
/**
 * Gets the <code>DecimalFormatSymbols</code> instance for the specified
 * locale.  This method provides access to <code>DecimalFormatSymbols</code>
 * instances for locales supported by the Java runtime itself as well
 * as for those supported by installed
 * {@link java.text.spi.DecimalFormatSymbolsProvider
 * DecimalFormatSymbolsProvider} implementations.
 * If the specified locale contains the {@link java.util.Locale#UNICODE_LOCALE_EXTENSION}
 * for the numbering system, the instance is initialized with the specified numbering
 * system if the JRE implementation supports it. For example,
 * <pre>
 * NumberFormat.getNumberInstance(Locale.forLanguageTag("th-TH-u-nu-thai"))
 * </pre>
 * This may return a {@code NumberFormat} instance with the Thai numbering system,
 * instead of the Latin numbering system.
 *
 * @param locale the desired locale.
 * @return a <code>DecimalFormatSymbols</code> instance.
 * @exception NullPointerException if <code>locale</code> is null
 * @since 1.6
 */
public static final DecimalFormatSymbols getInstance(Locale locale) {
    LocaleProviderAdapter adapter;
    adapter = LocaleProviderAdapter.getAdapter(DecimalFormatSymbolsProvider.class, locale);
    DecimalFormatSymbolsProvider provider = adapter.getDecimalFormatSymbolsProvider();
    DecimalFormatSymbols dfsyms = provider.getInstance(locale);
    if (dfsyms == null) {
        provider = LocaleProviderAdapter.forJRE().getDecimalFormatSymbolsProvider();
        dfsyms = provider.getInstance(locale);
    }
    return dfsyms;
}