]> granicus.if.org Git - icu/commitdiff
ICU-12591 Remove CalendarData references from:
authorFelipe Balbontín <fabalbon@google.com>
Tue, 23 Aug 2016 00:58:29 +0000 (00:58 +0000)
committerFelipe Balbontín <fabalbon@google.com>
Tue, 23 Aug 2016 00:58:29 +0000 (00:58 +0000)
- DateIntervalFormat.java
- Calendar.java

X-SVN-Rev: 39081

icu4j/main/classes/core/src/com/ibm/icu/impl/CalendarData.java
icu4j/main/classes/core/src/com/ibm/icu/text/DateIntervalFormat.java
icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java

index 0ac803c75926ae0277a0dca2ef5ee178d12d508d..16520b1c7b9f8090bdbca1fb2ae7215b32e88c9f 100644 (file)
@@ -59,50 +59,6 @@ public class CalendarData {
         }       
     }
 
-    /**
-     * Load data for calendar. Note, this object owns the resources, do NOT call ures_close()!
-     * There is an implicit key of 'format'
-     * data is located in:   "calendar/key/format/subKey"
-     * for example,  calendar/dayNames/format/abbreviated
-     *
-     * @param key Resource key to data
-     * @param subKey Resource key to data
-     * @internal
-     */
-    public ICUResourceBundle get(String key, String subKey) {
-        try {
-            return fBundle.getWithFallback("calendar/" + fMainType + "/" + key + "/format/" + subKey);
-        } catch(MissingResourceException m) {
-            if(fFallbackType != null) {
-                return fBundle.getWithFallback("calendar/" + fFallbackType + "/" + key + "/format/" + subKey);
-            }
-            throw m;
-            
-        }       
-    }
-
-    /**
-     * Load data for calendar. Note, this object owns the resources, do NOT call ures_close()!
-     * data is located in:   "calendar/key/contextKey/subKey"
-     * for example,  calendar/dayNames/stand-alone/narrow
-     *
-     * @param key Resource key to data
-     * @param contextKey Resource key to data
-     * @param subKey Resource key to data
-     * @internal
-     */
-    public ICUResourceBundle get(String key, String contextKey, String subKey) {
-        try {
-            return fBundle.getWithFallback("calendar/" + fMainType + "/" + key + "/" + contextKey + "/" + subKey);
-        } catch(MissingResourceException m) {
-            if(fFallbackType != null) {
-                return fBundle.getWithFallback("calendar/" + fFallbackType + "/" + key + "/" + contextKey + "/" + subKey);
-            }
-            throw m;
-            
-        }       
-    }
-
     public String[] getDateTimePatterns(){
         ICUResourceBundle bundle = get("DateTimePatterns");
         ArrayList<String> list = new ArrayList<String>();
@@ -152,26 +108,6 @@ public class CalendarData {
         // DateTimePatterns start at index 9 in the array.
         return patterns[9 + offset];
     }
-        
-    public String[] getOverrides(){
-        ICUResourceBundle bundle = get("DateTimePatterns");
-        ArrayList<String> list = new ArrayList<String>();
-        UResourceBundleIterator iter = bundle.getIterator();
-        while (iter.hasNext()) {
-            UResourceBundle patResource = iter.next();
-            int resourceType = patResource.getType();
-            switch (resourceType) {
-                case UResourceBundle.STRING:
-                    list.add(null);
-                    break;
-                case UResourceBundle.ARRAY:
-                    String[] items = patResource.getStringArray();
-                    list.add(items[1]);
-                    break;
-            }
-        }
-        return list.toArray(new String[list.size()]);
-    }
 
     private ICUResourceBundle fBundle;
     private String fMainType;
index 2924da184b2773036e68c692ed22237af4d01d1c..86f387c64b43033eec7e7d39fdd6d67f179ffc5e 100644 (file)
@@ -15,9 +15,13 @@ import java.util.Collections;
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
 
 import com.ibm.icu.impl.CalendarData;
 import com.ibm.icu.impl.ICUCache;
+import com.ibm.icu.impl.ICUData;
+import com.ibm.icu.impl.ICUResourceBundle;
 import com.ibm.icu.impl.SimpleCache;
 import com.ibm.icu.impl.SimpleFormatterImpl;
 import com.ibm.icu.text.DateIntervalInfo.PatternInfo;
@@ -27,6 +31,8 @@ import com.ibm.icu.util.Output;
 import com.ibm.icu.util.TimeZone;
 import com.ibm.icu.util.ULocale;
 import com.ibm.icu.util.ULocale.Category;
+import com.ibm.icu.util.UResourceBundle;
+import com.ibm.icu.util.UResourceTypeMismatchException;
 
 
 /**
@@ -1135,13 +1141,11 @@ public class DateIntervalFormat extends UFormat {
 
         // move this up here since we need it for fallbacks
         if (time.length() != 0 && date.length() != 0) {
-            // Need the Date/Time pattern for concatnation the date with
+            // Need the Date/Time pattern for concatenating the date with
             // the time interval.
             // The date/time pattern ( such as {0} {1} ) is saved in
             // calendar, that is why need to get the CalendarData here.
-            CalendarData calData = new CalendarData(locale, null);
-            String[] patterns = calData.getDateTimePatterns();
-            fDateTimeFormat = patterns[8];
+            fDateTimeFormat = getConcatenationPattern(locale);
         }
 
         boolean found = genSeparateDateTimePtn(normalizedDateSkeleton, 
@@ -1264,6 +1268,21 @@ public class DateIntervalFormat extends UFormat {
         return intervalPatterns;
     }
 
+    /**
+     * Retrieves the concatenation DateTime pattern from the resource bundle.
+     * @param locale Locale to retrieve.
+     * @return Concatenation DateTime pattern.
+     */
+    private String getConcatenationPattern(ULocale locale) {
+        ICUResourceBundle rb = (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, locale);
+        ICUResourceBundle dtPatternsRb = rb.getWithFallback("calendar/gregorian/DateTimePatterns");
+        ICUResourceBundle concatenationPatternRb = (ICUResourceBundle) dtPatternsRb.get(8);
+        if (concatenationPatternRb.getType() == UResourceBundle.STRING) {
+            return concatenationPatternRb.getString();
+        } else {
+            return concatenationPatternRb.getString(0);
+        }
+    }
 
     /*
      * Generate fall back interval pattern given a calendar field,
index 67315abedca2b21706abbf181cf802f403bfa7cd..313df8f086f9277fd0323d146a9d141f210a1c24 100644 (file)
@@ -28,6 +28,7 @@ import com.ibm.icu.impl.SoftCache;
 import com.ibm.icu.text.DateFormat;
 import com.ibm.icu.text.DateFormatSymbols;
 import com.ibm.icu.text.SimpleDateFormat;
+import com.ibm.icu.text.UTF16;
 import com.ibm.icu.util.ULocale.Category;
 
 /**
@@ -3610,9 +3611,7 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
             if (patternData == null) {
                 // Cache missed.  Get one from bundle
                 try {
-                    CalendarData calData = new CalendarData(loc, calType);
-                    patternData = new PatternData(calData.getDateTimePatterns(),
-                            calData.getOverrides());
+                    patternData = getPatternData(loc, calType);
                 } catch (MissingResourceException e) {
                     patternData = new PatternData(DEFAULT_PATTERNS, null);
                 }
@@ -3622,6 +3621,39 @@ public abstract class Calendar implements Serializable, Cloneable, Comparable<Ca
         }
     }
 
+    /**
+     * Retrieves the DateTime patterns and overrides from the resource bundle and generates a
+     * new PatternData object.
+     * @param locale Locale to retrieve.
+     * @param calType Calendar type to retrieve. If not found will fallback to gregorian.
+     * @return PatternData object for this locale and calendarType.
+     */
+    private static PatternData getPatternData(ULocale locale, String calType) {
+        ICUResourceBundle rb =
+                (ICUResourceBundle) UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME, locale);
+        ICUResourceBundle dtPatternsRb = rb.findWithFallback("calendar/" + calType + "/DateTimePatterns");
+        if (dtPatternsRb == null) {
+            dtPatternsRb = rb.getWithFallback("calendar/gregorian/DateTimePatterns");
+        }
+
+        int patternsSize = dtPatternsRb.getSize();
+        String[] dateTimePatterns = new String[patternsSize];
+        String[] dateTimePatternsOverrides = new String[patternsSize];
+        for (int i = 0; i < patternsSize; i++) {
+            ICUResourceBundle concatenationPatternRb = (ICUResourceBundle) dtPatternsRb.get(i);
+            switch (concatenationPatternRb.getType()) {
+                case UResourceBundle.STRING:
+                    dateTimePatterns[i] = concatenationPatternRb.getString();
+                    break;
+                case UResourceBundle.ARRAY:
+                    dateTimePatterns[i] = concatenationPatternRb.getString(0);
+                    dateTimePatternsOverrides[i] = concatenationPatternRb.getString(1);
+                    break;
+            }
+        }
+        return new PatternData(dateTimePatterns, dateTimePatternsOverrides);
+    }
+
     /**
      * @internal
      * @deprecated This API is ICU internal only.