java.text.spi.DateFormatSymbolsProvider Java Examples

The following examples show how to use java.text.spi.DateFormatSymbolsProvider. 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: JRELocaleProviderAdapter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public DateFormatSymbolsProvider getDateFormatSymbolsProvider() {
    if (dateFormatSymbolsProvider == null) {
        DateFormatSymbolsProvider provider = AccessController.doPrivileged(
            (PrivilegedAction<DateFormatSymbolsProvider>) () ->
                new DateFormatSymbolsProviderImpl(
                    getAdapterType(),
                    getLanguageTagSet("FormatData")));

        synchronized (this) {
            if (dateFormatSymbolsProvider == null) {
                dateFormatSymbolsProvider = provider;
            }
        }
    }
    return dateFormatSymbolsProvider;
}
 
Example #2
Source Project: jdk-1.7-annotated   Author: ZhaoX   File: DateFormatSymbols.java    License: Apache License 2.0 5 votes vote down vote up
private static DateFormatSymbols getProviderInstance(Locale locale) {
    DateFormatSymbols providersInstance = null;

    // Check whether a provider can provide an implementation that's closer
    // to the requested locale than what the Java runtime itself can provide.
    LocaleServiceProviderPool pool =
        LocaleServiceProviderPool.getPool(DateFormatSymbolsProvider.class);
    if (pool.hasProviders()) {
        providersInstance = pool.getLocalizedObject(
                                DateFormatSymbolsGetter.INSTANCE, locale);
    }
    return providersInstance;
}
 
Example #3
Source Project: jdk8u_jdk   Author: JetBrains   File: DateFormatSymbols.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static DateFormatSymbols getProviderInstance(Locale locale) {
    LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale);
    DateFormatSymbolsProvider provider = adapter.getDateFormatSymbolsProvider();
    DateFormatSymbols dfsyms = provider.getInstance(locale);
    if (dfsyms == null) {
        provider = LocaleProviderAdapter.forJRE().getDateFormatSymbolsProvider();
        dfsyms = provider.getInstance(locale);
    }
    return dfsyms;
}
 
Example #4
Source Project: TencentKona-8   Author: Tencent   File: JRELocaleProviderAdapter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public DateFormatSymbolsProvider getDateFormatSymbolsProvider() {
    if (dateFormatSymbolsProvider == null) {
        DateFormatSymbolsProvider provider = new DateFormatSymbolsProviderImpl(getAdapterType(),
                                                            getLanguageTagSet("FormatData"));
        synchronized (this) {
            if (dateFormatSymbolsProvider == null) {
                dateFormatSymbolsProvider = provider;
            }
        }
    }
    return dateFormatSymbolsProvider;
}
 
Example #5
Source Project: jdk8u_jdk   Author: JetBrains   File: JRELocaleProviderAdapter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public DateFormatSymbolsProvider getDateFormatSymbolsProvider() {
    if (dateFormatSymbolsProvider == null) {
        DateFormatSymbolsProvider provider = new DateFormatSymbolsProviderImpl(getAdapterType(),
                                                            getLanguageTagSet("FormatData"));
        synchronized (this) {
            if (dateFormatSymbolsProvider == null) {
                dateFormatSymbolsProvider = provider;
            }
        }
    }
    return dateFormatSymbolsProvider;
}
 
Example #6
Source Project: jdk8u60   Author: chenghanpeng   File: DateFormatSymbols.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static DateFormatSymbols getProviderInstance(Locale locale) {
    LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale);
    DateFormatSymbolsProvider provider = adapter.getDateFormatSymbolsProvider();
    DateFormatSymbols dfsyms = provider.getInstance(locale);
    if (dfsyms == null) {
        provider = LocaleProviderAdapter.forJRE().getDateFormatSymbolsProvider();
        dfsyms = provider.getInstance(locale);
    }
    return dfsyms;
}
 
Example #7
Source Project: jdk8u60   Author: chenghanpeng   File: JRELocaleProviderAdapter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public DateFormatSymbolsProvider getDateFormatSymbolsProvider() {
    if (dateFormatSymbolsProvider == null) {
        DateFormatSymbolsProvider provider = new DateFormatSymbolsProviderImpl(getAdapterType(),
                                                            getLanguageTagSet("FormatData"));
        synchronized (this) {
            if (dateFormatSymbolsProvider == null) {
                dateFormatSymbolsProvider = provider;
            }
        }
    }
    return dateFormatSymbolsProvider;
}
 
Example #8
Source Project: jdk-1.7-annotated   Author: ZhaoX   File: DateFormatSymbols.java    License: Apache License 2.0 5 votes vote down vote up
public DateFormatSymbols getObject(DateFormatSymbolsProvider dateFormatSymbolsProvider,
                        Locale locale,
                        String key,
                        Object... params) {
    assert params.length == 0;
    return dateFormatSymbolsProvider.getInstance(locale);
}
 
Example #9
Source Project: JDKSourceCode1.8   Author: wupeixuan   File: DateFormatSymbols.java    License: MIT License 5 votes vote down vote up
private static DateFormatSymbols getProviderInstance(Locale locale) {
    LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale);
    DateFormatSymbolsProvider provider = adapter.getDateFormatSymbolsProvider();
    DateFormatSymbols dfsyms = provider.getInstance(locale);
    if (dfsyms == null) {
        provider = LocaleProviderAdapter.forJRE().getDateFormatSymbolsProvider();
        dfsyms = provider.getInstance(locale);
    }
    return dfsyms;
}
 
Example #10
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: DateFormatSymbols.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static DateFormatSymbols getProviderInstance(Locale locale) {
    LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale);
    DateFormatSymbolsProvider provider = adapter.getDateFormatSymbolsProvider();
    DateFormatSymbols dfsyms = provider.getInstance(locale);
    if (dfsyms == null) {
        provider = LocaleProviderAdapter.forJRE().getDateFormatSymbolsProvider();
        dfsyms = provider.getInstance(locale);
    }
    return dfsyms;
}
 
Example #11
Source Project: jdk8u-jdk   Author: frohoff   File: DateFormatSymbols.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static DateFormatSymbols getProviderInstance(Locale locale) {
    LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale);
    DateFormatSymbolsProvider provider = adapter.getDateFormatSymbolsProvider();
    DateFormatSymbols dfsyms = provider.getInstance(locale);
    if (dfsyms == null) {
        provider = LocaleProviderAdapter.forJRE().getDateFormatSymbolsProvider();
        dfsyms = provider.getInstance(locale);
    }
    return dfsyms;
}
 
Example #12
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: JRELocaleProviderAdapter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public DateFormatSymbolsProvider getDateFormatSymbolsProvider() {
    if (dateFormatSymbolsProvider == null) {
        DateFormatSymbolsProvider provider = new DateFormatSymbolsProviderImpl(getAdapterType(),
                                                            getLanguageTagSet("FormatData"));
        synchronized (this) {
            if (dateFormatSymbolsProvider == null) {
                dateFormatSymbolsProvider = provider;
            }
        }
    }
    return dateFormatSymbolsProvider;
}
 
Example #13
Source Project: openjdk-8-source   Author: keerath   File: DateFormatSymbols.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static DateFormatSymbols getProviderInstance(Locale locale) {
    LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale);
    DateFormatSymbolsProvider provider = adapter.getDateFormatSymbolsProvider();
    DateFormatSymbols dfsyms = provider.getInstance(locale);
    if (dfsyms == null) {
        provider = LocaleProviderAdapter.forJRE().getDateFormatSymbolsProvider();
        dfsyms = provider.getInstance(locale);
    }
    return dfsyms;
}
 
Example #14
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: JRELocaleProviderAdapter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public DateFormatSymbolsProvider getDateFormatSymbolsProvider() {
    if (dateFormatSymbolsProvider == null) {
        DateFormatSymbolsProvider provider = new DateFormatSymbolsProviderImpl(getAdapterType(),
                                                            getLanguageTagSet("FormatData"));
        synchronized (this) {
            if (dateFormatSymbolsProvider == null) {
                dateFormatSymbolsProvider = provider;
            }
        }
    }
    return dateFormatSymbolsProvider;
}
 
Example #15
Source Project: Bytecoder   Author: mirkosertic   File: DateFormatSymbols.java    License: Apache License 2.0 5 votes vote down vote up
private static DateFormatSymbols getProviderInstance(Locale locale) {
    LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale);
    DateFormatSymbolsProvider provider = adapter.getDateFormatSymbolsProvider();
    DateFormatSymbols dfsyms = provider.getInstance(locale);
    if (dfsyms == null) {
        provider = LocaleProviderAdapter.forJRE().getDateFormatSymbolsProvider();
        dfsyms = provider.getInstance(locale);
    }
    return dfsyms;
}
 
Example #16
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: DateFormatSymbols.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static DateFormatSymbols getProviderInstance(Locale locale) {
    LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale);
    DateFormatSymbolsProvider provider = adapter.getDateFormatSymbolsProvider();
    DateFormatSymbols dfsyms = provider.getInstance(locale);
    if (dfsyms == null) {
        provider = LocaleProviderAdapter.forJRE().getDateFormatSymbolsProvider();
        dfsyms = provider.getInstance(locale);
    }
    return dfsyms;
}
 
Example #17
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: JRELocaleProviderAdapter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public DateFormatSymbolsProvider getDateFormatSymbolsProvider() {
    if (dateFormatSymbolsProvider == null) {
        DateFormatSymbolsProvider provider = new DateFormatSymbolsProviderImpl(getAdapterType(),
                                                            getLanguageTagSet("FormatData"));
        synchronized (this) {
            if (dateFormatSymbolsProvider == null) {
                dateFormatSymbolsProvider = provider;
            }
        }
    }
    return dateFormatSymbolsProvider;
}
 
Example #18
Source Project: Java8CN   Author: Java8-CNAPI-Team   File: DateFormatSymbols.java    License: Apache License 2.0 5 votes vote down vote up
private static DateFormatSymbols getProviderInstance(Locale locale) {
    LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale);
    DateFormatSymbolsProvider provider = adapter.getDateFormatSymbolsProvider();
    DateFormatSymbols dfsyms = provider.getInstance(locale);
    if (dfsyms == null) {
        provider = LocaleProviderAdapter.forJRE().getDateFormatSymbolsProvider();
        dfsyms = provider.getInstance(locale);
    }
    return dfsyms;
}
 
Example #19
Source Project: hottub   Author: dsrg-uoft   File: DateFormatSymbols.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static DateFormatSymbols getProviderInstance(Locale locale) {
    LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale);
    DateFormatSymbolsProvider provider = adapter.getDateFormatSymbolsProvider();
    DateFormatSymbols dfsyms = provider.getInstance(locale);
    if (dfsyms == null) {
        provider = LocaleProviderAdapter.forJRE().getDateFormatSymbolsProvider();
        dfsyms = provider.getInstance(locale);
    }
    return dfsyms;
}
 
Example #20
Source Project: hottub   Author: dsrg-uoft   File: JRELocaleProviderAdapter.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public DateFormatSymbolsProvider getDateFormatSymbolsProvider() {
    if (dateFormatSymbolsProvider == null) {
        DateFormatSymbolsProvider provider = new DateFormatSymbolsProviderImpl(getAdapterType(),
                                                            getLanguageTagSet("FormatData"));
        synchronized (this) {
            if (dateFormatSymbolsProvider == null) {
                dateFormatSymbolsProvider = provider;
            }
        }
    }
    return dateFormatSymbolsProvider;
}
 
Example #21
Source Project: jdk8u-dev-jdk   Author: frohoff   File: AuxLocaleProviderAdapter.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public DateFormatSymbolsProvider getDateFormatSymbolsProvider() {
    return getLocaleServiceProvider(DateFormatSymbolsProvider.class);
}
 
Example #22
Source Project: openjdk-8   Author: bpupadhyaya   File: SPILocaleProviderAdapter.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public DateFormatSymbolsProvider getImpl(Locale locale) {
    return SPILocaleProviderAdapter.getImpl(map, locale);
}
 
Example #23
Source Project: dragonwell8_jdk   Author: alibaba   File: DateFormatSymbols.java    License: 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 #24
Source Project: dragonwell8_jdk   Author: alibaba   File: AuxLocaleProviderAdapter.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public DateFormatSymbolsProvider getDateFormatSymbolsProvider() {
    return getLocaleServiceProvider(DateFormatSymbolsProvider.class);
}
 
Example #25
Source Project: dragonwell8_jdk   Author: alibaba   File: SPILocaleProviderAdapter.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public DateFormatSymbolsProvider getImpl(Locale locale) {
    return SPILocaleProviderAdapter.getImpl(map, locale);
}
 
Example #26
Source Project: jdk8u-dev-jdk   Author: frohoff   File: SPILocaleProviderAdapter.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public void addImpl(DateFormatSymbolsProvider impl) {
    for (Locale l : impl.getAvailableLocales()) {
        map.putIfAbsent(l, impl);
    }
}
 
Example #27
Source Project: TencentKona-8   Author: Tencent   File: DateFormatSymbols.java    License: 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 #28
Source Project: TencentKona-8   Author: Tencent   File: AuxLocaleProviderAdapter.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public DateFormatSymbolsProvider getDateFormatSymbolsProvider() {
    return getLocaleServiceProvider(DateFormatSymbolsProvider.class);
}
 
Example #29
Source Project: jdk8u60   Author: chenghanpeng   File: DateFormatSymbols.java    License: 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 #30
Source Project: jdk8u-jdk   Author: frohoff   File: DateFormatSymbols.java    License: 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);
        }
    }
}