src/windows/classes/sun/util/locale/provider/HostLocaleProviderAdapterImpl.java

Print this page

        

@@ -23,25 +23,31 @@
  * questions.
  */
 package sun.util.locale.provider;
 
 import java.lang.ref.SoftReference;
-import java.text.*;
+import java.text.DateFormat;
+import java.text.DateFormatSymbols;
+import java.text.DecimalFormat;
+import java.text.DecimalFormatSymbols;
+import java.text.NumberFormat;
+import java.text.SimpleDateFormat;
 import java.text.spi.DateFormatProvider;
 import java.text.spi.DateFormatSymbolsProvider;
 import java.text.spi.DecimalFormatSymbolsProvider;
 import java.text.spi.NumberFormatProvider;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Locale;
 import java.util.Map;
-import java.util.Set;
 import java.util.ResourceBundle.Control;
+import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.atomic.AtomicReferenceArray;
 import java.util.spi.CalendarDataProvider;
+import java.util.spi.CalendarNameProvider;
 
 /**
  * LocaleProviderdapter implementation for the Windows locale data.
  *
  * @author Naoto Sato

@@ -86,11 +92,11 @@
     private static ConcurrentMap<Locale, SoftReference<AtomicReferenceArray<String>>> numberFormatCache = new ConcurrentHashMap<>();
     private static ConcurrentMap<Locale, SoftReference<DecimalFormatSymbols>> decimalFormatSymbolsCache = new ConcurrentHashMap<>();
 
     private static final Set<Locale> supportedLocaleSet;
     static {
-        Set<Locale> tmpSet = new HashSet<Locale>();
+        Set<Locale> tmpSet = new HashSet<>();
         if (initialize()) {
             // Assuming the default locales do not include any extensions, so
             // no stripping is needed here.
             Locale l = Locale.forLanguageTag(getDefaultLocale(CAT_FORMAT).replaceAll("_","-"));
             tmpSet.addAll(Control.getNoFallbackControl(Control.FORMAT_DEFAULT).getCandidateLocales("", l));

@@ -256,11 +262,11 @@
                 AtomicReferenceArray<String> patterns;
                 SoftReference<AtomicReferenceArray<String>> ref = numberFormatCache.get(locale);
 
                 if (ref == null || (patterns = ref.get()) == null) {
                     String langtag = locale.toLanguageTag();
-                    patterns = new AtomicReferenceArray<String>(NF_MAX+1);
+                    patterns = new AtomicReferenceArray<>(NF_MAX+1);
                     for (int i = 0; i <= NF_MAX; i++) {
                         patterns.compareAndSet(i, null, getNumberPattern(i, langtag));
                     }
                     ref = new SoftReference<>(patterns);
                     numberFormatCache.put(locale, ref);

@@ -328,22 +334,10 @@
             public boolean isSupportedLocale(Locale locale) {
                 return isSupportedCalendarLocale(locale);
             }
 
             @Override
-            public String getDisplayName(String calType, int field, int value,
-                                         int style, Locale locale) {
-                return null;
-            }
-
-            @Override
-            public Map<String, Integer> getDisplayNames(String calType,
-                                         int field, int style, Locale locale) {
-                return null;
-            }
-
-            @Override
             public int getFirstDayOfWeek(Locale locale) {
                 int first = getCalendarDataValue(
                                  removeExtensions(locale).toLanguageTag(),
                                  CD_FIRSTDAYOFWEEK);
                 if (first != -1) {

@@ -358,10 +352,36 @@
                 return 0;
             }
         };
     }
 
+    public static CalendarNameProvider getCalendarNameProvider() {
+        return new CalendarNameProvider() {
+            @Override
+            public Locale[] getAvailableLocales() {
+                return getSupportedCalendarLocales();
+            }
+
+            @Override
+            public boolean isSupportedLocale(Locale locale) {
+                return isSupportedCalendarLocale(locale);
+            }
+
+            @Override
+            public String getDisplayName(String calType, int field, int value,
+                                         int style, Locale locale) {
+                return null;
+            }
+
+            @Override
+            public Map<String, Integer> getDisplayNames(String calType,
+                                         int field, int style, Locale locale) {
+                return null;
+            }
+        };
+    }
+
     private static String convertDateTimePattern(String winPattern) {
         String ret = winPattern.replaceAll("dddd", "EEEE");
         ret = ret.replaceAll("ddd", "EEE");
         ret = ret.replaceAll("tt", "aa");
         ret = ret.replaceAll("g", "GG");