ICU-12414 Updated DateFormatSymbols to load data using ResourceSink on ICU4J.

X-SVN-Rev: 38774
This commit is contained in:
Felipe Balbontín 2016-05-31 17:52:07 +00:00
parent 4316e50619
commit f937e63126
3 changed files with 388 additions and 163 deletions

View File

@ -100,45 +100,7 @@ public class CalendarData {
}
}
/**
* Load data for calendar. Note, this object owns the resources...
* data is located in: "calendar/key/set/contextKey/subKey"
* for example, calendar/cyclicNameSets/years/format/abbreviated
*
* @param key Resource key to data
* @param set Resource key to data
* @param contextKey Resource key to data
* @param subKey Resource key to data
* @internal
*/
public ICUResourceBundle get(String key, String set, String contextKey, String subKey) {
try {
return fBundle.getWithFallback("calendar/" + fMainType + "/" + key + "/" + set + "/" + contextKey + "/" + subKey);
} catch(MissingResourceException m) {
if(fFallbackType != null) {
return fBundle.getWithFallback("calendar/" + fFallbackType + "/" + key + "/" + set + "/" + contextKey + "/" + subKey);
}
throw m;
}
}
public String[] getStringArray(String key) {
return get(key).getStringArray();
}
public String[] getStringArray(String key, String subKey) {
return get(key, subKey).getStringArray();
}
public String[] getStringArray(String key, String contextKey, String subKey) {
return get(key, contextKey, subKey).getStringArray();
}
public String[] getEras(String subkey){
ICUResourceBundle bundle = get("eras/"+subkey);
return bundle.getStringArray();
}
public String[] getDateTimePatterns(){
ICUResourceBundle bundle = get("DateTimePatterns");
ArrayList<String> list = new ArrayList<String>();
@ -169,20 +131,6 @@ public class CalendarData {
return _getDateTimePattern(-1);
}
/**
* Returns the date-time pattern by style where style is one of the style fields defined
* in DateFormat. If date-time patterns by style are not available, it returns what
* {@link #getDateTimePattern()} would return.
* @param style the style e.g DateFormat.LONG.
* @return the pattern, e.g {1}, {0}.
*/
public String getDateTimePattern(int style) {
// mask away high order bits such as the DateFormat.RELATIVE bit.
// We do it this way to avoid making this class depend on DateFormat. It makes this
// code more brittle, but it is no more brittle than how we access patterns by style.
return _getDateTimePattern(style & 7);
}
private String _getDateTimePattern(int offset) {
String[] patterns = null;
try {
@ -223,10 +171,6 @@ public class CalendarData {
return list.toArray(new String[list.size()]);
}
public ULocale getULocale() {
return fBundle.getULocale();
}
private ICUResourceBundle fBundle;
private String fMainType;
private String fFallbackType;

View File

@ -8,7 +8,7 @@ package com.ibm.icu.text;
import java.util.Locale;
import com.ibm.icu.impl.CalendarData;
import com.ibm.icu.impl.ICUResourceBundle;
import com.ibm.icu.util.Calendar;
import com.ibm.icu.util.ChineseCalendar;
import com.ibm.icu.util.ULocale;
@ -103,8 +103,9 @@ public class ChineseDateFormatSymbols extends DateFormatSymbols {
* @deprecated ICU 50
*/
@Deprecated
protected void initializeData(ULocale loc, CalendarData calData) {
super.initializeData(loc, calData);
@Override
protected void initializeData(ULocale loc, ICUResourceBundle b, String calendarType) {
super.initializeData(loc, b, calendarType);
initializeIsLeapMonth();
}

View File

@ -10,22 +10,30 @@ package com.ibm.icu.text;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.TreeMap;
import com.ibm.icu.impl.CalendarData;
import com.ibm.icu.impl.CalendarUtil;
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.UResource;
import com.ibm.icu.impl.Utility;
import com.ibm.icu.text.TimeZoneNames.NameType;
import com.ibm.icu.util.Calendar;
import com.ibm.icu.util.ICUCloneNotSupportedException;
import com.ibm.icu.util.ICUException;
import com.ibm.icu.util.TimeZone;
import com.ibm.icu.util.ULocale;
import com.ibm.icu.util.ULocale.Category;
@ -1508,8 +1516,7 @@ public class DateFormatSymbols implements Serializable, Cloneable {
DateFormatSymbols dfs = DFSCACHE.get(key);
if (dfs == null) {
// Initialize data from scratch put a clone of this instance into the cache
CalendarData calData = new CalendarData(desiredLocale, type);
initializeData(desiredLocale, calData);
initializeData(desiredLocale, null, type);
// Do not cache subclass instances
if (this.getClass().getName().equals("com.ibm.icu.text.DateFormatSymbols")) {
dfs = (DateFormatSymbols)this.clone();
@ -1570,59 +1577,346 @@ public class DateFormatSymbols implements Serializable, Cloneable {
this.requestedLocale = dfs.requestedLocale;
}
/**
* Sink to enumerate the calendar data
*/
private static final class CalendarDataSink extends UResource.Sink {
// Data structures to store resources from the resource bundle
Map<String, String[]> arrays = new TreeMap<String, String[]>();
Map<String, Map<String, String>> maps = new TreeMap<String, Map<String, String>>();
List<String> aliasPathPairs = new ArrayList<String>();
// Current and next calendar resource table which should be loaded
String currentCalendarType = null;
String nextCalendarType = null;
// Resources to visit when enumerating fallback calendars
private Set<String> resourcesToVisit;
// Alias' relative path populated when an alias is read
private String aliasRelativePath;
/**
* Initializes CalendarDataSink with default values
*/
CalendarDataSink() { }
/**
* Configure the CalendarSink to visit all the resources
*/
void visitAllResources() {
resourcesToVisit = null;
}
/**
* Actions to be done before enumerating
*/
void preEnumerate(String calendarType) {
currentCalendarType = calendarType;
nextCalendarType = null;
aliasPathPairs.clear();
}
@Override
public void put(UResource.Key key, UResource.Value value, boolean noFallback) {
assert currentCalendarType != null && !currentCalendarType.isEmpty();
// Stores the resources to visit on the next calendar.
Set<String> resourcesToVisitNext = null;
UResource.Table calendarData = value.getTable();
// Enumerate all resources for this calendar
for (int i = 0; calendarData.getKeyAndValue(i, key, value); i++) {
String keyString = key.toString();
// == Handle aliases ==
AliasType aliasType = processAliasFromValue(keyString, value);
if (aliasType == AliasType.GREGORIAN) {
// Ignore aliases to the gregorian calendar, all of its resources will be loaded anyways.
continue;
} else if (aliasType == AliasType.DIFFERENT_CALENDAR) {
// Whenever an alias to the next calendar (except gregorian) is encountered, register the
// calendar type it's pointing to
if (resourcesToVisitNext == null) {
resourcesToVisitNext = new HashSet<String>();
}
resourcesToVisitNext.add(aliasRelativePath);
continue;
} else if (aliasType == AliasType.SAME_CALENDAR) {
// Register same-calendar alias
if (!arrays.containsKey(keyString) && !maps.containsKey(keyString)) {
aliasPathPairs.add(aliasRelativePath);
aliasPathPairs.add(keyString);
}
continue;
}
// Only visit the resources that were referenced by an alias on the previous calendar
// (AmPmMarkersAbbr is an exception).
if (resourcesToVisit != null && !resourcesToVisit.isEmpty() && !resourcesToVisit.contains(keyString)
&& !keyString.equals("AmPmMarkersAbbr")) { continue; }
// == Handle data ==
if (keyString.startsWith("AmPmMarkers")) {
if (!keyString.endsWith("%variant") && !arrays.containsKey(keyString)) {
String[] dataArray = value.getStringArray();
arrays.put(keyString, dataArray);
}
} else if (keyString.equals("eras")
|| keyString.equals("dayNames")
|| keyString.equals("monthNames")
|| keyString.equals("quarters")
|| keyString.equals("dayPeriod")
|| keyString.equals("monthPatterns")
|| keyString.equals("cyclicNameSets")) {
processResource(keyString, key, value);
}
}
// Apply same-calendar aliases
boolean modified;
do {
modified = false;
for (int i = 0; i < aliasPathPairs.size();) {
boolean mod = false;
String alias = aliasPathPairs.get(i);
if (arrays.containsKey(alias)) {
arrays.put(aliasPathPairs.get(i + 1), arrays.get(alias));
mod = true;
} else if (maps.containsKey(alias)) {
maps.put(aliasPathPairs.get(i + 1), maps.get(alias));
mod = true;
}
if (mod) {
aliasPathPairs.remove(i + 1);
aliasPathPairs.remove(i);
modified = true;
} else {
i += 2;
}
}
} while (modified && !aliasPathPairs.isEmpty());
// Set the resources to visit on the next calendar
if (resourcesToVisitNext != null) {
resourcesToVisit = resourcesToVisitNext;
}
}
/**
* Process the nested resource bundle tables
* @param path Table's relative path to the calendar
* @param key Resource bundle key
* @param value Resource bundle value (has to have the table to read)
*/
protected void processResource(String path, UResource.Key key, UResource.Value value) {
UResource.Table table = value.getTable();
Map<String, String> stringMap = null;
// Iterate over all the elements of the table and add them to the map
for(int i = 0; table.getKeyAndValue(i, key, value); i++) {
// Ignore '%variant' keys
if (key.endsWith("%variant")) { continue; }
String keyString = key.toString();
// == Handle String elements ==
if (value.getType() == ICUResourceBundle.STRING) {
// We are on a leaf, store the map elements into the stringMap
if (i == 0) {
stringMap = new HashMap<String, String>();
maps.put(path, stringMap);
}
assert stringMap != null;
stringMap.put(keyString, value.getString());
continue;
}
assert stringMap == null;
String currentPath = path + "/" + keyString;
// In cyclicNameSets ignore everything but years/format/abbreviated
// and zodiacs/format/abbreviated
if (currentPath.startsWith("cyclicNameSets")) {
if (!"cyclicNameSets/years/format/abbreviated".startsWith(currentPath)
&& !"cyclicNameSets/zodiacs/format/abbreviated".startsWith(currentPath)
&& !"cyclicNameSets/dayParts/format/abbreviated".startsWith(currentPath))
{ continue; }
}
// == Handle aliases ==
if (arrays.containsKey(currentPath)
|| maps.containsKey(currentPath)) { continue; }
AliasType aliasType = processAliasFromValue(currentPath, value);
if (aliasType == AliasType.SAME_CALENDAR) {
aliasPathPairs.add(aliasRelativePath);
aliasPathPairs.add(currentPath);
continue;
}
assert aliasType == AliasType.NONE;
// == Handle data ==
if (value.getType() == ICUResourceBundle.ARRAY) {
// We are on a leaf, store the array
String[] dataArray = value.getStringArray();
arrays.put(currentPath, dataArray);
} else if (value.getType() == ICUResourceBundle.TABLE) {
// We are not on a leaf, recursively process the subtable.
processResource(currentPath, key, value);
}
}
}
// Alias' path prefix
private static final String CALENDAR_ALIAS_PREFIX = "/LOCALE/calendar/";
/**
* Populates an AliasIdentifier with the alias information contained on the UResource.Value.
* @param currentRelativePath Relative path of this alias' resource
* @param value Value which contains the alias
* @return The AliasType of the alias found on Value
*/
private AliasType processAliasFromValue(String currentRelativePath, UResource.Value value) {
if (value.getType() == ICUResourceBundle.ALIAS) {
String aliasPath = value.getAliasString();
if (aliasPath.startsWith(CALENDAR_ALIAS_PREFIX) &&
aliasPath.length() > CALENDAR_ALIAS_PREFIX.length()) {
int typeLimit = aliasPath.indexOf('/', CALENDAR_ALIAS_PREFIX.length());
if (typeLimit > CALENDAR_ALIAS_PREFIX.length()) {
String aliasCalendarType = aliasPath.substring(CALENDAR_ALIAS_PREFIX.length(), typeLimit);
aliasRelativePath = aliasPath.substring(typeLimit + 1);
if (currentCalendarType.equals(aliasCalendarType)
&& !currentRelativePath.equals(aliasRelativePath)) {
// If we have an alias to the same calendar, the path to the resource must be different
return AliasType.SAME_CALENDAR;
} else if (!currentCalendarType.equals(aliasCalendarType)
&& currentRelativePath.equals(aliasRelativePath)) {
// If we have an alias to a different calendar, the path to the resource must be the same
if (aliasCalendarType.equals("gregorian")) {
return AliasType.GREGORIAN;
} else if (nextCalendarType == null || nextCalendarType.equals(aliasCalendarType)) {
nextCalendarType = aliasCalendarType;
return AliasType.DIFFERENT_CALENDAR;
}
}
}
}
throw new ICUException("Malformed 'calendar' alias. Path: " + aliasPath);
}
return AliasType.NONE;
}
/**
* Enum which specifies the type of alias received, or no alias
*/
private enum AliasType {
SAME_CALENDAR,
DIFFERENT_CALENDAR,
GREGORIAN,
NONE
}
}
/**
* Initializes format symbols for the locale and calendar type
* @param desiredLocale The locale whose symbols are desired.
* @param calData The calendar resource data
* @param b Resource bundle provided externally
* @param calendarType The calendar type being used
* @internal
* @deprecated This API is ICU internal only.
*/
@Deprecated
// This API was accidentally marked as @stable ICU 3.0 formerly.
protected void initializeData(ULocale desiredLocale, CalendarData calData)
protected void initializeData(ULocale desiredLocale, ICUResourceBundle b, String calendarType)
{
// FIXME: cache only ResourceBundle. Hence every time, will do
// getObject(). This won't be necessary if the Resource itself
// is cached.
eras = calData.getEras("abbreviated");
// Create a CalendarSink to load this data and a resource bundle
CalendarDataSink calendarSink = new CalendarDataSink();
if (b == null) {
b = (ICUResourceBundle) UResourceBundle
.getBundleInstance(ICUData.ICU_BASE_NAME, desiredLocale);
}
eraNames = calData.getEras("wide");
// Iterate over the resource bundle data following the fallbacks through different calendar types
while (calendarType != null) {
narrowEras = calData.getEras("narrow");
// Enumerate this calendar type. If the calendar is not found fallback to gregorian.
ICUResourceBundle dataForType = b.findWithFallback("calendar/" + calendarType);
if (dataForType == null) {
if (!"gregorian".equals(calendarType)) {
calendarType = "gregorian";
calendarSink.visitAllResources();
continue;
}
throw new MissingResourceException("The 'gregorian' calendar type wasn't found for the locale: "
+ desiredLocale.getBaseName(), getClass().getName(), "gregorian");
}
calendarSink.preEnumerate(calendarType);
dataForType.getAllItemsWithFallback("", calendarSink);
months = calData.getStringArray("monthNames", "wide");
shortMonths = calData.getStringArray("monthNames", "abbreviated");
narrowMonths = calData.getStringArray("monthNames", "narrow");
// Stop loading when gregorian was loaded
if (calendarType.equals("gregorian")) {
break;
}
standaloneMonths = calData.getStringArray("monthNames", "stand-alone", "wide");
standaloneShortMonths = calData.getStringArray("monthNames", "stand-alone", "abbreviated");
standaloneNarrowMonths = calData.getStringArray("monthNames", "stand-alone", "narrow");
// Get the next calendar type to process from the sink
calendarType = calendarSink.nextCalendarType;
String[] lWeekdays = calData.getStringArray("dayNames", "wide");
// Gregorian is always the last fallback
if (calendarType == null) {
calendarType = "gregorian";
calendarSink.visitAllResources();
}
}
Map<String, String[]> arrays = calendarSink.arrays;
Map<String, Map<String, String>> maps = calendarSink.maps;
eras = arrays.get("eras/abbreviated");
eraNames = arrays.get("eras/wide");
narrowEras = arrays.get("eras/narrow");
months = arrays.get("monthNames/format/wide");
shortMonths = arrays.get("monthNames/format/abbreviated");
narrowMonths = arrays.get("monthNames/format/narrow");
standaloneMonths = arrays.get("monthNames/stand-alone/wide");
standaloneShortMonths = arrays.get("monthNames/stand-alone/abbreviated");
standaloneNarrowMonths = arrays.get("monthNames/stand-alone/narrow");
String[] lWeekdays = arrays.get("dayNames/format/wide");
weekdays = new String[8];
weekdays[0] = ""; // 1-based
System.arraycopy(lWeekdays, 0, weekdays, 1, lWeekdays.length);
String[] aWeekdays = calData.getStringArray("dayNames", "abbreviated");
String[] aWeekdays = arrays.get("dayNames/format/abbreviated");
shortWeekdays = new String[8];
shortWeekdays[0] = ""; // 1-based
System.arraycopy(aWeekdays, 0, shortWeekdays, 1, aWeekdays.length);
String[] sWeekdays = calData.getStringArray("dayNames", "short");
String[] sWeekdays = arrays.get("dayNames/format/short");
shorterWeekdays = new String[8];
shorterWeekdays[0] = ""; // 1-based
System.arraycopy(sWeekdays, 0, shorterWeekdays, 1, sWeekdays.length);
String [] nWeekdays = null;
try {
nWeekdays = calData.getStringArray("dayNames", "narrow");
}
catch (MissingResourceException e) {
try {
nWeekdays = calData.getStringArray("dayNames", "stand-alone", "narrow");
}
catch (MissingResourceException e1) {
nWeekdays = calData.getStringArray("dayNames", "abbreviated");
String [] nWeekdays = arrays.get("dayNames/format/narrow");
if (nWeekdays == null) {
nWeekdays = arrays.get("dayNames/stand-alone/narrow");
if (nWeekdays == null) {
nWeekdays = arrays.get("dayNames/format/abbreviated");
if (nWeekdays == null) {
throw new MissingResourceException("Resource not found",
getClass().getName(), "dayNames/format/abbreviated");
}
}
}
narrowWeekdays = new String[8];
@ -1630,76 +1924,63 @@ public class DateFormatSymbols implements Serializable, Cloneable {
System.arraycopy(nWeekdays, 0, narrowWeekdays, 1, nWeekdays.length);
String [] swWeekdays = null;
swWeekdays = calData.getStringArray("dayNames", "stand-alone", "wide");
swWeekdays = arrays.get("dayNames/stand-alone/wide");
standaloneWeekdays = new String[8];
standaloneWeekdays[0] = ""; // 1-based
System.arraycopy(swWeekdays, 0, standaloneWeekdays, 1, swWeekdays.length);
String [] saWeekdays = null;
saWeekdays = calData.getStringArray("dayNames", "stand-alone", "abbreviated");
saWeekdays = arrays.get("dayNames/stand-alone/abbreviated");
standaloneShortWeekdays = new String[8];
standaloneShortWeekdays[0] = ""; // 1-based
System.arraycopy(saWeekdays, 0, standaloneShortWeekdays, 1, saWeekdays.length);
String [] ssWeekdays = null;
ssWeekdays = calData.getStringArray("dayNames", "stand-alone", "short");
ssWeekdays = arrays.get("dayNames/stand-alone/short");
standaloneShorterWeekdays = new String[8];
standaloneShorterWeekdays[0] = ""; // 1-based
System.arraycopy(ssWeekdays, 0, standaloneShorterWeekdays, 1, ssWeekdays.length);
String [] snWeekdays = null;
snWeekdays = calData.getStringArray("dayNames", "stand-alone", "narrow");
snWeekdays = arrays.get("dayNames/stand-alone/narrow");
standaloneNarrowWeekdays = new String[8];
standaloneNarrowWeekdays[0] = ""; // 1-based
System.arraycopy(snWeekdays, 0, standaloneNarrowWeekdays, 1, snWeekdays.length);
ampms = calData.getStringArray("AmPmMarkers");
ampmsNarrow = calData.getStringArray("AmPmMarkersNarrow");
ampms = arrays.get("AmPmMarkers");
ampmsNarrow = arrays.get("AmPmMarkersNarrow");
quarters = calData.getStringArray("quarters", "wide");
shortQuarters = calData.getStringArray("quarters", "abbreviated");
quarters = arrays.get("quarters/format/wide");
shortQuarters = arrays.get("quarters/format/abbreviated");
standaloneQuarters = calData.getStringArray("quarters", "stand-alone", "wide");
standaloneShortQuarters = calData.getStringArray("quarters", "stand-alone", "abbreviated");
standaloneQuarters = arrays.get("quarters/stand-alone/wide");
standaloneShortQuarters = arrays.get("quarters/stand-alone/abbreviated");
abbreviatedDayPeriods = loadDayPeriodStrings(calData, false, "abbreviated");
wideDayPeriods = loadDayPeriodStrings(calData, false, "wide");
narrowDayPeriods = loadDayPeriodStrings(calData, false, "narrow");
standaloneAbbreviatedDayPeriods = loadDayPeriodStrings(calData, true, "abbreviated");
standaloneWideDayPeriods = loadDayPeriodStrings(calData, true, "wide");
standaloneNarrowDayPeriods = loadDayPeriodStrings(calData, true, "narrow");
abbreviatedDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/format/abbreviated"));
wideDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/format/wide"));
narrowDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/format/narrow"));
standaloneAbbreviatedDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/stand-alone/abbreviated"));
standaloneWideDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/stand-alone/wide"));
standaloneNarrowDayPeriods = loadDayPeriodStrings(maps.get("dayPeriod/stand-alone/narrow"));
// The code for getting individual symbols in the leapMonthSymbols array is here
// rather than in CalendarData because it depends on DateFormatSymbols constants...
ICUResourceBundle monthPatternsBundle = null;
try {
monthPatternsBundle = calData.get("monthPatterns");
}
catch (MissingResourceException e) {
monthPatternsBundle = null; // probably redundant
}
if (monthPatternsBundle != null) {
leapMonthPatterns = new String[DT_MONTH_PATTERN_COUNT];
leapMonthPatterns[DT_LEAP_MONTH_PATTERN_FORMAT_WIDE] = calData.get("monthPatterns", "wide").get("leap").getString();
leapMonthPatterns[DT_LEAP_MONTH_PATTERN_FORMAT_ABBREV] = calData.get("monthPatterns", "abbreviated").get("leap").getString();
leapMonthPatterns[DT_LEAP_MONTH_PATTERN_FORMAT_NARROW] = calData.get("monthPatterns", "narrow").get("leap").getString();
leapMonthPatterns[DT_LEAP_MONTH_PATTERN_STANDALONE_WIDE] = calData.get("monthPatterns", "stand-alone", "wide").get("leap").getString();
leapMonthPatterns[DT_LEAP_MONTH_PATTERN_STANDALONE_ABBREV] = calData.get("monthPatterns", "stand-alone", "abbreviated").get("leap").getString();
leapMonthPatterns[DT_LEAP_MONTH_PATTERN_STANDALONE_NARROW] = calData.get("monthPatterns", "stand-alone", "narrow").get("leap").getString();
leapMonthPatterns[DT_LEAP_MONTH_PATTERN_NUMERIC] = calData.get("monthPatterns", "numeric", "all").get("leap").getString();
for (int i = 0; i < DT_MONTH_PATTERN_COUNT; i++) {
String monthPatternPath = LEAP_MONTH_PATTERNS_PATHS[i];
if (monthPatternPath != null) {
Map<String, String> monthPatternMap = maps.get(monthPatternPath);
if (monthPatternMap != null) {
String leapMonthPattern = monthPatternMap.get("leap");
if (leapMonthPattern != null) {
if (leapMonthPatterns == null) {
leapMonthPatterns = new String[DT_MONTH_PATTERN_COUNT];
}
leapMonthPatterns[i] = leapMonthPattern;
}
}
}
}
ICUResourceBundle cyclicNameSetsBundle = null;
try {
cyclicNameSetsBundle = calData.get("cyclicNameSets");
}
catch (MissingResourceException e) {
cyclicNameSetsBundle = null; // probably redundant
}
if (cyclicNameSetsBundle != null) {
shortYearNames = calData.get("cyclicNameSets", "years", "format", "abbreviated").getStringArray();
shortZodiacNames = calData.get("cyclicNameSets", "zodiacs", "format", "abbreviated").getStringArray();
}
shortYearNames = arrays.get("cyclicNameSets/years/format/abbreviated");
shortZodiacNames = arrays.get("cyclicNameSets/zodiacs/format/abbreviated");
requestedLocale = desiredLocale;
@ -1707,11 +1988,6 @@ public class DateFormatSymbols implements Serializable, Cloneable {
(ICUResourceBundle)UResourceBundle.getBundleInstance(
ICUData.ICU_BASE_NAME, desiredLocale);
// Because localized date/time pattern characters will be obsolete in CLDR,
// we decided not to maintain localized pattern characters in ICU any more.
// We always use the base pattern characters by default. (ticket#5597)
//localPatternChars = rb.getString("localPatternChars");
localPatternChars = patternChars;
// TODO: obtain correct actual/valid locale later
@ -1761,6 +2037,20 @@ public class DateFormatSymbols implements Serializable, Cloneable {
}
}
/**
* Resource bundle paths for each leap month pattern
*/
private static final String[] LEAP_MONTH_PATTERNS_PATHS = new String[DT_MONTH_PATTERN_COUNT];
static {
LEAP_MONTH_PATTERNS_PATHS[DT_LEAP_MONTH_PATTERN_FORMAT_WIDE] = "monthPatterns/format/wide";
LEAP_MONTH_PATTERNS_PATHS[DT_LEAP_MONTH_PATTERN_FORMAT_ABBREV] = "monthPatterns/format/abbreviated";
LEAP_MONTH_PATTERNS_PATHS[DT_LEAP_MONTH_PATTERN_FORMAT_NARROW] = "monthPatterns/format/narrow";
LEAP_MONTH_PATTERNS_PATHS[DT_LEAP_MONTH_PATTERN_STANDALONE_WIDE] = "monthPatterns/stand-alone/wide";
LEAP_MONTH_PATTERNS_PATHS[DT_LEAP_MONTH_PATTERN_STANDALONE_ABBREV] = "monthPatterns/stand-alone/abbreviated";
LEAP_MONTH_PATTERNS_PATHS[DT_LEAP_MONTH_PATTERN_STANDALONE_NARROW] = "monthPatterns/stand-alone/narrow";
LEAP_MONTH_PATTERNS_PATHS[DT_LEAP_MONTH_PATTERN_NUMERIC] = "monthPatterns/numeric/all";
}
private static final boolean arrayOfArrayEquals(Object[][] aa1, Object[][]aa2) {
if (aa1 == aa2) { // both are null
return true;
@ -1782,32 +2072,23 @@ public class DateFormatSymbols implements Serializable, Cloneable {
}
/**
* Loads localized names for day periods in the requested format.
* @param calData where the strings come from
* @param standalone whether the standalone version is requested
* @param width "abbreviated", "wide", or "narrow".
* Keys for dayPeriods
*/
private String[] loadDayPeriodStrings(CalendarData calData, boolean standalone, String width) {
String[] dayPeriodKeys = {"midnight", "noon",
"morning1", "afternoon1", "evening1", "night1",
"morning2", "afternoon2", "evening2", "night2"};
private static final String[] DAY_PERIOD_KEYS = {"midnight", "noon",
"morning1", "afternoon1", "evening1", "night1",
"morning2", "afternoon2", "evening2", "night2"};
ICUResourceBundle b;
String strings[] = new String[10];
try {
if (standalone) {
b = calData.get("dayPeriod", "standalone", width);
} else {
b = calData.get("dayPeriod", "format", width);
/**
* Loads localized names for day periods in the requested format.
* @param resourceMap Contains the dayPeriod resource to load
*/
private String[] loadDayPeriodStrings(Map<String, String> resourceMap) {
String strings[] = new String[DAY_PERIOD_KEYS.length];
if (resourceMap != null) {
for (int i = 0; i < DAY_PERIOD_KEYS.length; ++i) {
strings[i] = resourceMap.get(DAY_PERIOD_KEYS[i]); // Null if string doesn't exist.
}
} catch (MissingResourceException e) {
return strings; // Array of null's.
}
for (int i = 0; i < 10; ++i) {
strings[i] = b.findStringWithFallback(dayPeriodKeys[i]); // Null if string doesn't exist.
}
return strings;
}
@ -2032,8 +2313,7 @@ public class DateFormatSymbols implements Serializable, Cloneable {
* @stable ICU 3.2
*/
public DateFormatSymbols(ResourceBundle bundle, ULocale locale) {
initializeData(locale,
new CalendarData((ICUResourceBundle)bundle, CalendarUtil.getCalendarType(locale)));
initializeData(locale, (ICUResourceBundle) bundle, CalendarUtil.getCalendarType(locale));
}
/**