< prev index next >

src/java.base/share/classes/sun/util/locale/provider/LocaleResources.java

Print this page

        

@@ -40,14 +40,16 @@
 
 package sun.util.locale.provider;
 
 import java.lang.ref.ReferenceQueue;
 import java.lang.ref.SoftReference;
+import java.text.CompactNumberFormat;
 import java.text.MessageFormat;
 import java.util.Calendar;
 import java.util.HashSet;
 import java.util.LinkedHashSet;
+import java.util.List;
 import java.util.Locale;
 import java.util.Map;
 import java.util.Objects;
 import java.util.ResourceBundle;
 import java.util.Set;

@@ -86,10 +88,11 @@
     private static final String LOCALE_NAMES = "LN.";
     private static final String TIME_ZONE_NAMES = "TZN.";
     private static final String ZONE_IDS_CACHEKEY = "ZID";
     private static final String CALENDAR_NAMES = "CALN.";
     private static final String NUMBER_PATTERNS_CACHEKEY = "NP";
+    private static final String COMPACT_NUMBER_PATTERNS_CACHEKEY = "CNP";
     private static final String DATE_TIME_PATTERN = "DTP.";
 
     // TimeZoneNamesBundle exemplar city prefix
     private static final String TZNB_EXCITY_PREFIX = "timezone.excity.";
 

@@ -477,10 +480,36 @@
 
         return numberPatterns;
     }
 
     /**
+     * Returns the compact number format patterns.
+     * @param formatStyle the style for formatting a number
+     * @return a list of compact number patterns
+     */
+    @SuppressWarnings("unchecked")
+    public List<String> getCNPatterns(CompactNumberFormat.Style formatStyle) {
+
+        Objects.requireNonNull(formatStyle);
+        List<String> compactNumberPatterns = null;
+        removeEmptyReferences();
+        String width = (formatStyle == CompactNumberFormat.Style.LONG) ? "long" : "short";
+        String cacheKey = width + "." + COMPACT_NUMBER_PATTERNS_CACHEKEY;
+        ResourceReference data = cache.get(cacheKey);
+        if (data == null || ((compactNumberPatterns
+                = (List<String>) data.get()) == null)) {
+            ResourceBundle resource = localeData.getNumberFormatData(locale);
+            compactNumberPatterns = (List<String>) resource
+                    .getObject(width + ".CompactNumberPatterns");
+            cache.put(cacheKey, new ResourceReference(cacheKey,
+                    (Object) compactNumberPatterns, referenceQueue));
+        }
+        return compactNumberPatterns;
+    }
+
+
+    /**
      * Returns the FormatData resource bundle of this LocaleResources.
      * The FormatData should be used only for accessing extra
      * resources required by JSR 310.
      */
     public ResourceBundle getJavaTimeFormatData() {
< prev index next >