diff --git a/icu4j/main/classes/core/src/com/ibm/icu/text/DateTimePatternGenerator.java b/icu4j/main/classes/core/src/com/ibm/icu/text/DateTimePatternGenerator.java index 1375ce7b96..f504a09fd1 100644 --- a/icu4j/main/classes/core/src/com/ibm/icu/text/DateTimePatternGenerator.java +++ b/icu4j/main/classes/core/src/com/ibm/icu/text/DateTimePatternGenerator.java @@ -30,6 +30,7 @@ import com.ibm.icu.impl.ICUResourceBundle; import com.ibm.icu.impl.PatternTokenizer; import com.ibm.icu.impl.SimpleCache; import com.ibm.icu.impl.SimpleFormatterImpl; +import com.ibm.icu.impl.UResource; import com.ibm.icu.impl.Utility; import com.ibm.icu.util.Calendar; import com.ibm.icu.util.Freezable; @@ -37,7 +38,6 @@ import com.ibm.icu.util.ICUCloneNotSupportedException; import com.ibm.icu.util.ULocale; import com.ibm.icu.util.ULocale.Category; import com.ibm.icu.util.UResourceBundle; -import com.ibm.icu.util.UResourceBundleIterator; /** * This class provides flexible generation of date format patterns, like @@ -249,7 +249,7 @@ public class DateTimePatternGenerator implements Freezable getPreferredHourFormats(ULocale uLocale) { + private static final String[] LAST_RESORT_ALLOWED_HOUR_FORMAT = {"H"}; + + private static String[] getAllowedHourFormats(ULocale uLocale) { // key can be either region or locale (lang_region) // ZW{ // allowed{ @@ -282,11 +284,11 @@ public class DateTimePatternGenerator implements Freezable list = LOCALE_TO_PREFERED_HOUR.get(langCountry); + String[] list = LOCALE_TO_ALLOWED_HOUR.get(langCountry); if (list == null) { - list = LOCALE_TO_PREFERED_HOUR.get(country); + list = LOCALE_TO_ALLOWED_HOUR.get(country); if (list == null) { - list = Collections.singletonList("H"); + list = LAST_RESORT_ALLOWED_HOUR_FORMAT; } } return list; @@ -422,7 +424,7 @@ public class DateTimePatternGenerator implements Freezable tempMap; + String regionOrLocale; + String[] formatList; + + private DayPeriodAllowedHoursSink(HashMap tempMap) { + this.tempMap = tempMap; + } + + @Override + public UResource.TableSink getOrCreateTableSink(UResource.Key key, int initialSize) { + regionOrLocale = key.toString(); + + return formatListSink; + } + + private class FormatListSink extends UResource.TableSink { + @Override + public UResource.ArraySink getOrCreateArraySink(UResource.Key key, int initialSize) { + if (key.contentEquals("allowed")) { // Ignore "preferred" list. + formatList = new String[initialSize]; + return allowedFormatListSink; + } + + return null; + } + } + private FormatListSink formatListSink = new FormatListSink(); + + private class AllowedFormatListSink extends UResource.ArraySink { + @Override + public void put(int index, UResource.Value value) { + formatList[index] = value.getString(); + } + + @Override + public void leave() { + tempMap.put(regionOrLocale, formatList); + formatList = null; // For good measure. + } + } + private AllowedFormatListSink allowedFormatListSink = new AllowedFormatListSink(); + } + // get the data for dayperiod C. - static final Map> LOCALE_TO_PREFERED_HOUR; + static final Map LOCALE_TO_ALLOWED_HOUR; static { - HashMap> temp = new HashMap>(); - UResourceBundle suppData = UResourceBundle.getBundleInstance( + HashMap temp = new HashMap(); + ICUResourceBundle suppData = (ICUResourceBundle)ICUResourceBundle.getBundleInstance( ICUResourceBundle.ICU_BASE_NAME, "supplementalData", ICUResourceBundle.ICU_DATA_CLASS_LOADER); - UResourceBundle suppTimeData = suppData.get("timeData"); - for(UResourceBundleIterator iter = suppTimeData.getIterator(); iter.hasNext();) { - ICUResourceBundle subBndle = (ICUResourceBundle) iter.next(); - final String regionOrLocale = subBndle.getKey(); - // final List list = Arrays.asList(subBndle.getStringArray()); Didn't work, so doing it the long way. - UResourceBundle allowedBundle = subBndle.get("allowed"); - List list = allowedBundle.getType() == UResourceBundle.STRING // getStringArray API should do this automatically! - ? Collections.singletonList(allowedBundle.getString()) - : Arrays.asList(allowedBundle.getStringArray()); - temp.put(regionOrLocale, list); - } - LOCALE_TO_PREFERED_HOUR = Collections.unmodifiableMap(temp); + + DayPeriodAllowedHoursSink allowedHoursSink = new DayPeriodAllowedHoursSink(temp); + suppData.getAllTableItemsWithFallback("timeData", allowedHoursSink); + + LOCALE_TO_ALLOWED_HOUR = Collections.unmodifiableMap(temp); } /* @@ -473,7 +512,7 @@ public class DateTimePatternGenerator implements Freezable * This reflects the way that the CLDR data is organized. - * + * * @param field such as ERA * @param value pattern, such as "{0}, {1}" * @stable ICU 3.6 @@ -1043,7 +1082,7 @@ public class DateTimePatternGenerator implements Freezable * This reflects the way that the CLDR data is organized. - * + * * @param field Index of the append item names. * @param value The value to set the item to. * @stable ICU 3.6 @@ -1071,7 +1110,7 @@ public class DateTimePatternGenerator implements Freezable type) minField = type; // if (maxField < type) maxField = type; - // if (type == ZONE || type == DAYPERIOD || type == WEEKDAY) return result; // skip anything with zones + // if (type == ZONE || type == DAYPERIOD || type == WEEKDAY) return result; // skip anything with zones // fieldCount++; // } catch (Exception e) { // return result; // if there are any funny fields, return @@ -1511,7 +1550,7 @@ public class DateTimePatternGenerator implements Freezable 0) { // Object previousItem = items.get(0); // if (alpha.containsSome(previousItem.toString())) break; @@ -1677,7 +1716,7 @@ public class DateTimePatternGenerator implements Freezable allowedHourFormats; + private String[] allowedHourFormats; private static final int FRACTIONAL_MASK = 1< CANONICAL_SET = new HashSet(Arrays.asList(CANONICAL_ITEMS)); private Set cldrAvailableFormatKeys = new HashSet(20); - private static final int + private static final int DATE_MASK = (1<