]> granicus.if.org Git - icu/commitdiff
ICU-12576 Small changes to Java DateTimePatternGenerator for C++ consistency.
authorShane Carr <shane@unicode.org>
Fri, 17 Jun 2016 23:40:09 +0000 (23:40 +0000)
committerShane Carr <shane@unicode.org>
Fri, 17 Jun 2016 23:40:09 +0000 (23:40 +0000)
X-SVN-Rev: 38863

icu4j/main/classes/core/src/com/ibm/icu/text/DateTimePatternGenerator.java

index 3414f33fb7833ec64a71af51a220dccfe752cffe..0616efb35357f5e09944a65a208fb70111bb5627 100644 (file)
@@ -150,16 +150,28 @@ public class DateTimePatternGenerator implements Freezable<DateTimePatternGenera
             addPattern(df.toPattern(), false, returnInfo);
 
             if (i == DateFormat.SHORT) {
-                consumeShortTimePattern(df, returnInfo);
+                consumeShortTimePattern(df.toPattern(), returnInfo);
             }
         }
     }
 
-    private void consumeShortTimePattern(SimpleDateFormat df, PatternInfo returnInfo) {
+    private String getCalendarTypeToUse(ULocale uLocale) {
+        // Get the correct calendar type
+        // TODO: C++ and Java are inconsistent (see #9952).
+        String calendarTypeToUse = uLocale.getKeywordValue("calendar");
+        if ( calendarTypeToUse == null ) {
+            String[] preferredCalendarTypes = Calendar.getKeywordValuesForLocale("calendar", uLocale, true);
+            calendarTypeToUse = preferredCalendarTypes[0]; // the most preferred calendar
+        }
+        if ( calendarTypeToUse == null ) {
+            calendarTypeToUse = "gregorian"; // fallback
+        }
+        return calendarTypeToUse;
+    }
+
+    private void consumeShortTimePattern(String shortTimePattern, PatternInfo returnInfo) {
         // keep this pattern to populate other time field
         // combination patterns by hackTimes later in this method.
-        String shortTimePattern = df.toPattern();
-
         // use hour style in SHORT time pattern as the default
         // hour style for the locale
         FormatParser fp = new FormatParser();
@@ -251,48 +263,41 @@ public class DateTimePatternGenerator implements Freezable<DateTimePatternGenera
 
     private void addCLDRData(PatternInfo returnInfo, ULocale uLocale) {
         ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, uLocale);
-        // Get the correct calendar type
-        String calendarTypeToUse = uLocale.getKeywordValue("calendar");
-        if ( calendarTypeToUse == null ) {
-            String[] preferredCalendarTypes = Calendar.getKeywordValuesForLocale("calendar", uLocale, true);
-            calendarTypeToUse = preferredCalendarTypes[0]; // the most preferred calendar
-        }
-        if ( calendarTypeToUse == null ) {
-            calendarTypeToUse = "gregorian"; // fallback
-        }
+        String calendarTypeToUse = getCalendarTypeToUse(uLocale);
+
+        //      ICU4J getWithFallback does not work well when
+        //      1) A nested table is an alias to /LOCALE/...
+        //      2) getWithFallback is called multiple times for going down hierarchical resource path
+        //      #9987 resolved the issue of alias table when full path is specified in getWithFallback,
+        //      but there is no easy solution when the equivalent operation is done by multiple operations.
+        //      This issue is addressed in #9964.
 
-        // Get data for that calendar
+        // Load append item formats.
+        AppendItemFormatsSink appendItemFormatsSink = new AppendItemFormatsSink();
         try {
-            //      ICU4J getWithFallback does not work well when
-            //      1) A nested table is an alias to /LOCALE/...
-            //      2) getWithFallback is called multiple times for going down hierarchical resource path
-            //      #9987 resolved the issue of alias table when full path is specified in getWithFallback,
-            //      but there is no easy solution when the equivalent operation is done by multiple operations.
-            //      This issue is addressed in #9964.
-            AppendItemFormatsSink sink = new AppendItemFormatsSink();
-            rb.getAllItemsWithFallback("calendar/" + calendarTypeToUse + "/appendItems", sink);
-            sink.fillInMissing();
+            rb.getAllItemsWithFallback(
+                    "calendar/" + calendarTypeToUse + "/appendItems",
+                    appendItemFormatsSink);
         }catch(MissingResourceException e) {
         }
+        appendItemFormatsSink.fillInMissing();
 
-        // CLDR item names
+        // Load CLDR item names.
+        AppendItemNamesSink appendItemNamesSink = new AppendItemNamesSink();
         try {
-            AppendItemNamesSink sink = new AppendItemNamesSink();
-            rb.getAllItemsWithFallback("fields", sink);
-            sink.fillInMissing();
+            rb.getAllItemsWithFallback(
+                    "fields",
+                    appendItemNamesSink);
         }catch(MissingResourceException e) {
         }
+        appendItemNamesSink.fillInMissing();
 
-        // set the AvailableFormat in CLDR
+        // Load the available formats from CLDR.
+        AvailableFormatsSink availableFormatsSink = new AvailableFormatsSink(returnInfo);
         try {
-            //      ICU4J getWithFallback does not work well when
-            //      1) A nested table is an alias to /LOCALE/...
-            //      2) getWithFallback is called multiple times for going down hierarchical resource path
-            //      #9987 resolved the issue of alias table when full path is specified in getWithFallback,
-            //      but there is no easy solution when the equivalent operation is done by multiple operations.
-            //      This issue is addressed in #9964.
-            AvailableFormatsSink sink = new AvailableFormatsSink(returnInfo);
-            rb.getAllItemsWithFallback("calendar/" + calendarTypeToUse + "/availableFormats", sink);
+            rb.getAllItemsWithFallback(
+                    "calendar/" + calendarTypeToUse + "/availableFormats",
+                    availableFormatsSink);
         } catch (MissingResourceException e) {
         }
     }