From a64c50c57001520f686bce16b6cc6450c23c0e66 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Felipe=20Balbont=C3=ADn?= Date: Tue, 23 Aug 2016 00:58:29 +0000 Subject: [PATCH] ICU-12591 Remove CalendarData references from: - DateIntervalFormat.java - Calendar.java X-SVN-Rev: 39081 --- .../src/com/ibm/icu/impl/CalendarData.java | 64 ------------------- .../com/ibm/icu/text/DateIntervalFormat.java | 27 ++++++-- .../core/src/com/ibm/icu/util/Calendar.java | 38 ++++++++++- 3 files changed, 58 insertions(+), 71 deletions(-) diff --git a/icu4j/main/classes/core/src/com/ibm/icu/impl/CalendarData.java b/icu4j/main/classes/core/src/com/ibm/icu/impl/CalendarData.java index 0ac803c7592..16520b1c7b9 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/impl/CalendarData.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/impl/CalendarData.java @@ -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 list = new ArrayList(); @@ -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 list = new ArrayList(); - 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; diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/DateIntervalFormat.java b/icu4j/main/classes/core/src/com/ibm/icu/text/DateIntervalFormat.java index 2924da184b2..86f387c64b4 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/DateIntervalFormat.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/DateIntervalFormat.java @@ -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, diff --git a/icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java b/icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java index 67315abedca..313df8f086f 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/util/Calendar.java @@ -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