Java Code Examples for sun.util.locale.provider.LocaleProviderAdapter#getResourceBundleBased()
The following examples show how to use
sun.util.locale.provider.LocaleProviderAdapter#getResourceBundleBased() .
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: DateFormatSymbols.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
/** * 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 2
Source File: DateFormatSymbols.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
/** * 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; } } } // Copy the field values from dfs to this instance. copyMembers(dfs, this); }
Example 3
Source File: DateFormatSymbols.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
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 4
Source File: DateFormatSymbols.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
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 5
Source File: DateFormatSymbols.java From Bytecoder with Apache License 2.0 | 4 votes |
/** * 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); // check for region override Locale override = CalendarDataUtility.findRegionOverride(locale); // Initialize the fields from the ResourceBundle for locale. LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, override); // Avoid any potential recursions if (!(adapter instanceof ResourceBundleBasedAdapter)) { adapter = LocaleProviderAdapter.getResourceBundleBased(); } ResourceBundle resource = ((ResourceBundleBasedAdapter)adapter).getLocaleData().getDateFormatData(override); 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; } } } // Copy the field values from dfs to this instance. copyMembers(dfs, this); }
Example 6
Source File: DateFormatSymbols.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
/** * 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 7
Source File: DateFormatSymbols.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
/** * 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 8
Source File: DateFormatSymbols.java From hottub with GNU General Public License v2.0 | 4 votes |
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 9
Source File: DateFormatSymbols.java From Java8CN with Apache License 2.0 | 4 votes |
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 10
Source File: DateFormatSymbols.java From jdk8u60 with GNU General Public License v2.0 | 4 votes |
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 11
Source File: DateFormatSymbols.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
/** * 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 12
Source File: DateFormatSymbols.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
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 13
Source File: DateFormatSymbols.java From jdk1.8-source-analysis with Apache License 2.0 | 4 votes |
/** * 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 14
Source File: DecimalFormat.java From openjdk-jdk9 with GNU General Public License v2.0 | 3 votes |
/** * Creates a DecimalFormat using the default pattern and symbols * for the default {@link java.util.Locale.Category#FORMAT FORMAT} locale. * This is a convenient way to obtain a * DecimalFormat when internationalization is not the main concern. * <p> * To obtain standard formats for a given locale, use the factory methods * on NumberFormat such as getNumberInstance. These factories will * return the most appropriate sub-class of NumberFormat for a given * locale. * * @see java.text.NumberFormat#getInstance * @see java.text.NumberFormat#getNumberInstance * @see java.text.NumberFormat#getCurrencyInstance * @see java.text.NumberFormat#getPercentInstance */ public DecimalFormat() { // Get the pattern for the default locale. Locale def = Locale.getDefault(Locale.Category.FORMAT); LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(NumberFormatProvider.class, def); if (!(adapter instanceof ResourceBundleBasedAdapter)) { adapter = LocaleProviderAdapter.getResourceBundleBased(); } String[] all = adapter.getLocaleResources(def).getNumberPatterns(); // Always applyPattern after the symbols are set this.symbols = DecimalFormatSymbols.getInstance(def); applyPattern(all[0], false); }
Example 15
Source File: DecimalFormat.java From Java8CN with Apache License 2.0 | 3 votes |
/** * Creates a DecimalFormat using the default pattern and symbols * for the default {@link java.util.Locale.Category#FORMAT FORMAT} locale. * This is a convenient way to obtain a * DecimalFormat when internationalization is not the main concern. * <p> * To obtain standard formats for a given locale, use the factory methods * on NumberFormat such as getNumberInstance. These factories will * return the most appropriate sub-class of NumberFormat for a given * locale. * * @see java.text.NumberFormat#getInstance * @see java.text.NumberFormat#getNumberInstance * @see java.text.NumberFormat#getCurrencyInstance * @see java.text.NumberFormat#getPercentInstance */ public DecimalFormat() { // Get the pattern for the default locale. Locale def = Locale.getDefault(Locale.Category.FORMAT); LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(NumberFormatProvider.class, def); if (!(adapter instanceof ResourceBundleBasedAdapter)) { adapter = LocaleProviderAdapter.getResourceBundleBased(); } String[] all = adapter.getLocaleResources(def).getNumberPatterns(); // Always applyPattern after the symbols are set this.symbols = DecimalFormatSymbols.getInstance(def); applyPattern(all[0], false); }
Example 16
Source File: DecimalFormat.java From TencentKona-8 with GNU General Public License v2.0 | 3 votes |
/** * Creates a DecimalFormat using the default pattern and symbols * for the default {@link java.util.Locale.Category#FORMAT FORMAT} locale. * This is a convenient way to obtain a * DecimalFormat when internationalization is not the main concern. * <p> * To obtain standard formats for a given locale, use the factory methods * on NumberFormat such as getNumberInstance. These factories will * return the most appropriate sub-class of NumberFormat for a given * locale. * * @see java.text.NumberFormat#getInstance * @see java.text.NumberFormat#getNumberInstance * @see java.text.NumberFormat#getCurrencyInstance * @see java.text.NumberFormat#getPercentInstance */ public DecimalFormat() { // Get the pattern for the default locale. Locale def = Locale.getDefault(Locale.Category.FORMAT); LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(NumberFormatProvider.class, def); if (!(adapter instanceof ResourceBundleBasedAdapter)) { adapter = LocaleProviderAdapter.getResourceBundleBased(); } String[] all = adapter.getLocaleResources(def).getNumberPatterns(); // Always applyPattern after the symbols are set this.symbols = DecimalFormatSymbols.getInstance(def); applyPattern(all[0], false); }
Example 17
Source File: DecimalFormat.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 3 votes |
/** * Creates a DecimalFormat using the default pattern and symbols * for the default {@link java.util.Locale.Category#FORMAT FORMAT} locale. * This is a convenient way to obtain a * DecimalFormat when internationalization is not the main concern. * <p> * To obtain standard formats for a given locale, use the factory methods * on NumberFormat such as getNumberInstance. These factories will * return the most appropriate sub-class of NumberFormat for a given * locale. * * @see java.text.NumberFormat#getInstance * @see java.text.NumberFormat#getNumberInstance * @see java.text.NumberFormat#getCurrencyInstance * @see java.text.NumberFormat#getPercentInstance */ public DecimalFormat() { // Get the pattern for the default locale. Locale def = Locale.getDefault(Locale.Category.FORMAT); LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(NumberFormatProvider.class, def); if (!(adapter instanceof ResourceBundleBasedAdapter)) { adapter = LocaleProviderAdapter.getResourceBundleBased(); } String[] all = adapter.getLocaleResources(def).getNumberPatterns(); // Always applyPattern after the symbols are set this.symbols = DecimalFormatSymbols.getInstance(def); applyPattern(all[0], false); }
Example 18
Source File: DecimalFormat.java From Bytecoder with Apache License 2.0 | 3 votes |
/** * Creates a DecimalFormat using the default pattern and symbols * for the default {@link java.util.Locale.Category#FORMAT FORMAT} locale. * This is a convenient way to obtain a * DecimalFormat when internationalization is not the main concern. * <p> * To obtain standard formats for a given locale, use the factory methods * on NumberFormat such as getNumberInstance. These factories will * return the most appropriate sub-class of NumberFormat for a given * locale. * * @see java.text.NumberFormat#getInstance * @see java.text.NumberFormat#getNumberInstance * @see java.text.NumberFormat#getCurrencyInstance * @see java.text.NumberFormat#getPercentInstance */ public DecimalFormat() { // Get the pattern for the default locale. Locale def = Locale.getDefault(Locale.Category.FORMAT); LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(NumberFormatProvider.class, def); if (!(adapter instanceof ResourceBundleBasedAdapter)) { adapter = LocaleProviderAdapter.getResourceBundleBased(); } String[] all = adapter.getLocaleResources(def).getNumberPatterns(); // Always applyPattern after the symbols are set this.symbols = DecimalFormatSymbols.getInstance(def); applyPattern(all[0], false); }
Example 19
Source File: DecimalFormat.java From jdk8u_jdk with GNU General Public License v2.0 | 3 votes |
/** * Creates a DecimalFormat using the default pattern and symbols * for the default {@link java.util.Locale.Category#FORMAT FORMAT} locale. * This is a convenient way to obtain a * DecimalFormat when internationalization is not the main concern. * <p> * To obtain standard formats for a given locale, use the factory methods * on NumberFormat such as getNumberInstance. These factories will * return the most appropriate sub-class of NumberFormat for a given * locale. * * @see java.text.NumberFormat#getInstance * @see java.text.NumberFormat#getNumberInstance * @see java.text.NumberFormat#getCurrencyInstance * @see java.text.NumberFormat#getPercentInstance */ public DecimalFormat() { // Get the pattern for the default locale. Locale def = Locale.getDefault(Locale.Category.FORMAT); LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(NumberFormatProvider.class, def); if (!(adapter instanceof ResourceBundleBasedAdapter)) { adapter = LocaleProviderAdapter.getResourceBundleBased(); } String[] all = adapter.getLocaleResources(def).getNumberPatterns(); // Always applyPattern after the symbols are set this.symbols = DecimalFormatSymbols.getInstance(def); applyPattern(all[0], false); }
Example 20
Source File: DecimalFormat.java From openjdk-8-source with GNU General Public License v2.0 | 3 votes |
/** * Creates a DecimalFormat using the default pattern and symbols * for the default {@link java.util.Locale.Category#FORMAT FORMAT} locale. * This is a convenient way to obtain a * DecimalFormat when internationalization is not the main concern. * <p> * To obtain standard formats for a given locale, use the factory methods * on NumberFormat such as getNumberInstance. These factories will * return the most appropriate sub-class of NumberFormat for a given * locale. * * @see java.text.NumberFormat#getInstance * @see java.text.NumberFormat#getNumberInstance * @see java.text.NumberFormat#getCurrencyInstance * @see java.text.NumberFormat#getPercentInstance */ public DecimalFormat() { // Get the pattern for the default locale. Locale def = Locale.getDefault(Locale.Category.FORMAT); LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(NumberFormatProvider.class, def); if (!(adapter instanceof ResourceBundleBasedAdapter)) { adapter = LocaleProviderAdapter.getResourceBundleBased(); } String[] all = adapter.getLocaleResources(def).getNumberPatterns(); // Always applyPattern after the symbols are set this.symbols = DecimalFormatSymbols.getInstance(def); applyPattern(all[0], false); }