Search in sources :

Example 1 with DecimalFormatSymbolsProvider

use of java.text.spi.DecimalFormatSymbolsProvider in project jdk8u_jdk by JetBrains.

the class DecimalFormatSymbols method getInstance.

/**
     * 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;
}
Also used : LocaleProviderAdapter(sun.util.locale.provider.LocaleProviderAdapter) DecimalFormatSymbolsProvider(java.text.spi.DecimalFormatSymbolsProvider)

Example 2 with DecimalFormatSymbolsProvider

use of java.text.spi.DecimalFormatSymbolsProvider in project jdk8u_jdk by JetBrains.

the class HostLocaleProviderAdapterImpl method getDecimalFormatSymbolsProvider.

public static DecimalFormatSymbolsProvider getDecimalFormatSymbolsProvider() {
    return new DecimalFormatSymbolsProvider() {

        @Override
        public Locale[] getAvailableLocales() {
            return getSupportedNativeDigitLocales();
        }

        @Override
        public boolean isSupportedLocale(Locale locale) {
            return isSupportedNativeDigitLocale(locale);
        }

        @Override
        public DecimalFormatSymbols getInstance(Locale locale) {
            DecimalFormatSymbols dfs;
            SoftReference<DecimalFormatSymbols> ref = decimalFormatSymbolsCache.get(locale);
            if (ref == null || (dfs = ref.get()) == null) {
                dfs = new DecimalFormatSymbols(getNumberLocale(locale));
                String langTag = removeExtensions(locale).toLanguageTag();
                // DecimalFormatSymbols.setInternationalCurrencySymbol() has
                // a side effect of setting the currency symbol as well. So
                // the calling order is relevant here.
                dfs.setInternationalCurrencySymbol(getInternationalCurrencySymbol(langTag, dfs.getInternationalCurrencySymbol()));
                dfs.setCurrencySymbol(getCurrencySymbol(langTag, dfs.getCurrencySymbol()));
                dfs.setDecimalSeparator(getDecimalSeparator(langTag, dfs.getDecimalSeparator()));
                dfs.setGroupingSeparator(getGroupingSeparator(langTag, dfs.getGroupingSeparator()));
                dfs.setInfinity(getInfinity(langTag, dfs.getInfinity()));
                dfs.setMinusSign(getMinusSign(langTag, dfs.getMinusSign()));
                dfs.setMonetaryDecimalSeparator(getMonetaryDecimalSeparator(langTag, dfs.getMonetaryDecimalSeparator()));
                dfs.setNaN(getNaN(langTag, dfs.getNaN()));
                dfs.setPercent(getPercent(langTag, dfs.getPercent()));
                dfs.setPerMill(getPerMill(langTag, dfs.getPerMill()));
                dfs.setZeroDigit(getZeroDigit(langTag, dfs.getZeroDigit()));
                ref = new SoftReference<>(dfs);
                decimalFormatSymbolsCache.put(locale, ref);
            }
            return (DecimalFormatSymbols) dfs.clone();
        }
    };
}
Also used : Locale(java.util.Locale) DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormatSymbolsProvider(java.text.spi.DecimalFormatSymbolsProvider)

Aggregations

DecimalFormatSymbolsProvider (java.text.spi.DecimalFormatSymbolsProvider)2 DecimalFormatSymbols (java.text.DecimalFormatSymbols)1 Locale (java.util.Locale)1 LocaleProviderAdapter (sun.util.locale.provider.LocaleProviderAdapter)1