java.util.ResourceBundle#getStringArray ( )源码实例Demo

下面列出了java.util.ResourceBundle#getStringArray ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: jdk8u-jdk   文件: LocaleResources.java
String[] getJavaTimeNames(String key) {
    String[] names = null;
    String cacheKey = CALENDAR_NAMES + key;

    removeEmptyReferences();
    ResourceReference data = cache.get(cacheKey);

    if (data == null || ((names = (String[]) data.get()) == null)) {
        ResourceBundle rb = getJavaTimeFormatData();
        if (rb.containsKey(key)) {
            names = rb.getStringArray(key);
            cache.put(cacheKey,
                      new ResourceReference(cacheKey, (Object) names, referenceQueue));
        }
    }

    return names;
}
 
源代码2 项目: jdk8u-dev-jdk   文件: LocaleResources.java
String[] getJavaTimeNames(String key) {
    String[] names = null;
    String cacheKey = CALENDAR_NAMES + key;

    removeEmptyReferences();
    ResourceReference data = cache.get(cacheKey);

    if (data == null || ((names = (String[]) data.get()) == null)) {
        ResourceBundle rb = getJavaTimeFormatData();
        if (rb.containsKey(key)) {
            names = rb.getStringArray(key);
            cache.put(cacheKey,
                      new ResourceReference(cacheKey, (Object) names, referenceQueue));
        }
    }

    return names;
}
 
源代码3 项目: Bytecoder   文件: LocaleResources.java
String[] getCalendarNames(String key) {
    String[] names = null;
    String cacheKey = CALENDAR_NAMES + key;

    removeEmptyReferences();
    ResourceReference data = cache.get(cacheKey);

    if (data == null || ((names = (String[]) data.get()) == null)) {
        ResourceBundle rb = localeData.getDateFormatData(locale);
        if (rb.containsKey(key)) {
            names = rb.getStringArray(key);
            cache.put(cacheKey,
                      new ResourceReference(cacheKey, (Object) names, referenceQueue));
        }
    }

    return names;
}
 
源代码4 项目: jdk8u_jdk   文件: LocaleResources.java
String[] getJavaTimeNames(String key) {
    String[] names = null;
    String cacheKey = CALENDAR_NAMES + key;

    removeEmptyReferences();
    ResourceReference data = cache.get(cacheKey);

    if (data == null || ((names = (String[]) data.get()) == null)) {
        ResourceBundle rb = getJavaTimeFormatData();
        if (rb.containsKey(key)) {
            names = rb.getStringArray(key);
            cache.put(cacheKey,
                      new ResourceReference(cacheKey, (Object) names, referenceQueue));
        }
    }

    return names;
}
 
源代码5 项目: jdk8u-jdk   文件: LocaleResources.java
String[] getJavaTimeNames(String key) {
    String[] names = null;
    String cacheKey = CALENDAR_NAMES + key;

    removeEmptyReferences();
    ResourceReference data = cache.get(cacheKey);

    if (data == null || ((names = (String[]) data.get()) == null)) {
        ResourceBundle rb = getJavaTimeFormatData();
        if (rb.containsKey(key)) {
            names = rb.getStringArray(key);
            cache.put(cacheKey,
                      new ResourceReference(cacheKey, (Object) names, referenceQueue));
        }
    }

    return names;
}
 
源代码6 项目: jdk8u-dev-jdk   文件: LocaleResources.java
String[] getCalendarNames(String key) {
    String[] names = null;
    String cacheKey = CALENDAR_NAMES + key;

    removeEmptyReferences();
    ResourceReference data = cache.get(cacheKey);

    if (data == null || ((names = (String[]) data.get()) == null)) {
        ResourceBundle rb = localeData.getDateFormatData(locale);
        if (rb.containsKey(key)) {
            names = rb.getStringArray(key);
            cache.put(cacheKey,
                      new ResourceReference(cacheKey, (Object) names, referenceQueue));
        }
    }

    return names;
}
 
源代码7 项目: openjdk-jdk8u-backup   文件: LocaleResources.java
public String[] getNumberPatterns() {
    String[] numberPatterns = null;

    removeEmptyReferences();
    ResourceReference data = cache.get(NUMBER_PATTERNS_CACHEKEY);

    if (data == null || ((numberPatterns = (String[]) data.get()) == null)) {
        ResourceBundle resource = localeData.getNumberFormatData(locale);
        numberPatterns = resource.getStringArray("NumberPatterns");
        cache.put(NUMBER_PATTERNS_CACHEKEY,
                  new ResourceReference(NUMBER_PATTERNS_CACHEKEY, (Object) numberPatterns, referenceQueue));
    }

    return numberPatterns;
}
 
源代码8 项目: jdk8u60   文件: LocaleResources.java
public String[] getNumberPatterns() {
    String[] numberPatterns = null;

    removeEmptyReferences();
    ResourceReference data = cache.get(NUMBER_PATTERNS_CACHEKEY);

    if (data == null || ((numberPatterns = (String[]) data.get()) == null)) {
        ResourceBundle resource = localeData.getNumberFormatData(locale);
        numberPatterns = resource.getStringArray("NumberPatterns");
        cache.put(NUMBER_PATTERNS_CACHEKEY,
                  new ResourceReference(NUMBER_PATTERNS_CACHEKEY, (Object) numberPatterns, referenceQueue));
    }

    return numberPatterns;
}
 
源代码9 项目: jdk8u-dev-jdk   文件: DateFormatSymbols.java
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);
        }
    }
}
 
源代码10 项目: openjdk-jdk8u-backup   文件: DateFormatSymbols.java
/**
 * 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);
}
 
源代码11 项目: openjdk-jdk9   文件: LocaleResources.java
public Object[] getDecimalFormatSymbolsData() {
    Object[] dfsdata;

    removeEmptyReferences();
    ResourceReference data = cache.get(DECIMAL_FORMAT_SYMBOLS_DATA_CACHEKEY);
    if (data == null || ((dfsdata = (Object[]) data.get()) == null)) {
        // Note that only dfsdata[0] is prepared here in this method. Other
        // elements are provided by the caller, yet they are cached here.
        ResourceBundle rb = localeData.getNumberFormatData(locale);
        dfsdata = new Object[3];

        // NumberElements look up. First, try the Unicode extension
        String numElemKey;
        String numberType = locale.getUnicodeLocaleType("nu");
        if (numberType != null) {
            numElemKey = numberType + ".NumberElements";
            if (rb.containsKey(numElemKey)) {
                dfsdata[0] = rb.getStringArray(numElemKey);
            }
        }

        // Next, try DefaultNumberingSystem value
        if (dfsdata[0] == null && rb.containsKey("DefaultNumberingSystem")) {
            numElemKey = rb.getString("DefaultNumberingSystem") + ".NumberElements";
            if (rb.containsKey(numElemKey)) {
                dfsdata[0] = rb.getStringArray(numElemKey);
            }
        }

        // Last resort. No need to check the availability.
        // Just let it throw MissingResourceException when needed.
        if (dfsdata[0] == null) {
            dfsdata[0] = rb.getStringArray("NumberElements");
        }

        cache.put(DECIMAL_FORMAT_SYMBOLS_DATA_CACHEKEY,
                  new ResourceReference(DECIMAL_FORMAT_SYMBOLS_DATA_CACHEKEY, (Object) dfsdata, referenceQueue));
    }

    return dfsdata;
}
 
源代码12 项目: j2objc   文件: TransliteratorRegistry.java
/**
 * Attempt to find an entry in a single resource bundle.  This is
 * a one-sided lookup.  findInStaticStore() performs up to two such
 * lookups, one for the source, and one for the target.
 *
 * Do not perform fallback.  Return 0 on failure.
 *
 * On success, create a new Entry object, populate it, and return it.
 * The caller owns the returned object.
 */
private Object[] findInBundle(Spec specToOpen,
                              Spec specToFind,
                              String variant,
                              int direction) {
    // assert(specToOpen.isLocale());
    ResourceBundle res = specToOpen.getBundle();

    if (res == null) {
        // This means that the bundle's locale does not match
        // the current level of iteration for the spec.
        return null;
    }

    for (int pass=0; pass<2; ++pass) {
        StringBuilder tag = new StringBuilder();
        // First try either TransliteratorTo_xxx or
        // TransliterateFrom_xxx, then try the bidirectional
        // Transliterate_xxx.  This precedence order is arbitrary
        // but must be consistent and documented.
        if (pass == 0) {
            tag.append(direction == Transliterator.FORWARD ?
                       "TransliterateTo" : "TransliterateFrom");
        } else {
            tag.append("Transliterate");
        }
        tag.append(specToFind.get().toUpperCase(Locale.ENGLISH));

        try {
            // The Transliterate*_xxx resource is an array of
            // strings of the format { <v0>, <r0>, ... }.  Each
            // <vi> is a variant name, and each <ri> is a rule.
            String[] subres = res.getStringArray(tag.toString());

            // assert(subres != null);
            // assert(subres.length % 2 == 0);
            int i = 0;
            if (variant.length() != 0) {
                for (i=0; i<subres.length; i+= 2) {
                    if (subres[i].equalsIgnoreCase(variant)) {
                        break;
                    }
                }
            }

            if (i < subres.length) {
                // We have a match, or there is no variant and i == 0.
                // We have succeeded in loading a string from the
                // locale resources.  Return the rule string which
                // will itself become the registry entry.

                // The direction is always forward for the
                // TransliterateTo_xxx and TransliterateFrom_xxx
                // items; those are unidirectional forward rules.
                // For the bidirectional Transliterate_xxx items,
                // the direction is the value passed in to this
                // function.
                int dir = (pass == 0) ? Transliterator.FORWARD : direction;
                return new Object[] { new LocaleEntry(subres[i+1], dir) };
            }

        } catch (MissingResourceException e) {
            ///CLOVER:OFF
            if (DEBUG) System.out.println("missing resource: " + e);
            ///CLOVER:ON
        }
    }

    // If we get here we had a missing resource exception or we
    // failed to find a desired variant.
    return null;
}
 
源代码13 项目: openjdk-8   文件: DateFormatSymbols.java
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);
        }
    }
}
 
源代码14 项目: jdk8u-jdk   文件: DateFormatSymbols.java
/**
 * 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);
}
 
源代码15 项目: openjdk-jdk9   文件: DateFormatSymbols.java
/**
 * 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);
}
 
源代码16 项目: JDKSourceCode1.8   文件: DateFormatSymbols.java
/**
 * 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);
}
 
源代码17 项目: openjdk-jdk8u   文件: DateFormatSymbols.java
/**
 * 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);
}
 
源代码18 项目: openjdk-jdk8u   文件: LocaleResources.java
public Object[] getDecimalFormatSymbolsData() {
    Object[] dfsdata;

    removeEmptyReferences();
    ResourceReference data = cache.get(DECIMAL_FORMAT_SYMBOLS_DATA_CACHEKEY);
    if (data == null || ((dfsdata = (Object[]) data.get()) == null)) {
        // Note that only dfsdata[0] is prepared here in this method. Other
        // elements are provided by the caller, yet they are cached here.
        ResourceBundle rb = localeData.getNumberFormatData(locale);
        dfsdata = new Object[3];

        // NumberElements look up. First, try the Unicode extension
        String numElemKey;
        String numberType = locale.getUnicodeLocaleType("nu");
        if (numberType != null) {
            numElemKey = numberType + ".NumberElements";
            if (rb.containsKey(numElemKey)) {
                dfsdata[0] = rb.getStringArray(numElemKey);
            }
        }

        // Next, try DefaultNumberingSystem value
        if (dfsdata[0] == null && rb.containsKey("DefaultNumberingSystem")) {
            numElemKey = rb.getString("DefaultNumberingSystem") + ".NumberElements";
            if (rb.containsKey(numElemKey)) {
                dfsdata[0] = rb.getStringArray(numElemKey);
            }
        }

        // Last resort. No need to check the availability.
        // Just let it throw MissingResourceException when needed.
        if (dfsdata[0] == null) {
            dfsdata[0] = rb.getStringArray("NumberElements");
        }

        cache.put(DECIMAL_FORMAT_SYMBOLS_DATA_CACHEKEY,
                  new ResourceReference(DECIMAL_FORMAT_SYMBOLS_DATA_CACHEKEY, (Object) dfsdata, referenceQueue));
    }

    return dfsdata;
}
 
源代码19 项目: mpxj   文件: LocaleData.java
/**
 * Convenience method for retrieving a String[] resource.
 *
 * @param locale locale identifier
 * @param key resource key
 * @return resource value
 */
public static final String[] getStringArray(Locale locale, String key)
{
   ResourceBundle bundle = ResourceBundle.getBundle(LocaleData.class.getName(), locale);
   return (bundle.getStringArray(key));
}
 
源代码20 项目: mpxj   文件: LocaleData.java
/**
 * Convenience method for retrieving a String[] resource.
 *
 * @param locale locale identifier
 * @param key resource key
 * @return resource value
 */
public static final String[] getStringArray(Locale locale, String key)
{
   ResourceBundle bundle = ResourceBundle.getBundle(LocaleData.class.getName(), locale);
   return (bundle.getStringArray(key));
}