/* GENERATED SOURCE. DO NOT MODIFY. */ // © 2016 and later: Unicode, Inc. and others. // License & terms of use: http://www.unicode.org/copyright.html /* ******************************************************************************* * Copyright (C) 1996-2016, International Business Machines Corporation and * others. All Rights Reserved. ******************************************************************************* */ package android.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.List; 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 android.icu.impl.CacheBase; import android.icu.impl.CalendarUtil; import android.icu.impl.ICUData; import android.icu.impl.ICUResourceBundle; import android.icu.impl.SoftCache; import android.icu.impl.UResource; import android.icu.impl.Utility; import android.icu.text.TimeZoneNames.NameType; import android.icu.util.Calendar; import android.icu.util.ICUCloneNotSupportedException; import android.icu.util.ICUException; import android.icu.util.TimeZone; import android.icu.util.ULocale; import android.icu.util.ULocale.Category; import android.icu.util.UResourceBundle; import android.icu.util.UResourceBundleIterator; /** * [icu enhancement] ICU's replacement for {@link java.text.DateFormatSymbols}. Methods, fields, and other functionality specific to ICU are labeled '[icu]'. * *
DateFormatSymbols
is a public class for encapsulating
* localizable date-time formatting data, such as the names of the
* months, the names of the days of the week, and the time zone data.
* DateFormat
and SimpleDateFormat
both use
* DateFormatSymbols
to encapsulate this information.
*
*
Typically you shouldn't use DateFormatSymbols
directly.
* Rather, you are encouraged to create a date-time formatter with the
* DateFormat
class's factory methods: getTimeInstance
,
* getDateInstance
, or getDateTimeInstance
.
* These methods automatically create a DateFormatSymbols
for
* the formatter so that you don't have to. After the
* formatter is created, you may modify its format pattern using the
* setPattern
method. For more information about
* creating formatters using DateFormat
's factory methods,
* see {@link DateFormat}.
*
*
If you decide to create a date-time formatter with a specific * format pattern for a specific locale, you can do so with: *
** ** new SimpleDateFormat(aPattern, new DateFormatSymbols(aLocale)). **
DateFormatSymbols
objects are clonable. When you obtain
* a DateFormatSymbols
object, feel free to modify the
* date-time formatting data. For instance, you can replace the localized
* date-time format pattern characters with the ones that you feel easy
* to remember. Or you can change the representative cities
* to your favorite ones.
*
*
New DateFormatSymbols
subclasses may be added to support
* SimpleDateFormat
for date-time formatting for additional locales.
*
* @see DateFormat
* @see SimpleDateFormat
* @author Chen-Lieh Huang
*/
public class DateFormatSymbols implements Serializable, Cloneable {
// TODO make sure local pattern char string is 18 characters long,
// that is, that it encompasses the new 'u' char for
// EXTENDED_YEAR. Two options: 1. Make sure resource data is
// correct; 2. Make code add in 'u' at end if len == 17.
// Constants for context
/**
* [icu] Constant for context.
*/
public static final int FORMAT = 0;
/**
* [icu] Constant for context.
*/
public static final int STANDALONE = 1;
/**
* [icu] Constant for context. NUMERIC context
* is only supported for leapMonthPatterns.
* @deprecated This API is ICU internal only.
* @hide original deprecated declaration
* @hide draft / provisional / internal are hidden on Android
*/
@Deprecated
public static final int NUMERIC = 2;
/**
* [icu] Constant for context.
* @deprecated This API is ICU internal only.
* @hide original deprecated declaration
* @hide draft / provisional / internal are hidden on Android
*/
@Deprecated
public static final int DT_CONTEXT_COUNT = 3;
// Constants for width
/**
* [icu] Constant for width.
*/
public static final int ABBREVIATED = 0;
/**
* [icu] Constant for width.
*/
public static final int WIDE = 1;
/**
* [icu] Constant for width.
*/
public static final int NARROW = 2;
/**
* [icu] Constant for width; only supported for weekdays.
*/
public static final int SHORT = 3;
/**
* [icu] Constant for width.
* @deprecated This API is ICU internal only.
* @hide original deprecated declaration
* @hide draft / provisional / internal are hidden on Android
*/
@Deprecated
public static final int DT_WIDTH_COUNT = 4;
/**
* [icu] Somewhat temporary constant for leap month pattern type, adequate for Chinese calendar.
* @hide draft / provisional / internal are hidden on Android
*/
static final int DT_LEAP_MONTH_PATTERN_FORMAT_WIDE = 0;
/**
* [icu] Somewhat temporary constant for leap month pattern type, adequate for Chinese calendar.
* @hide draft / provisional / internal are hidden on Android
*/
static final int DT_LEAP_MONTH_PATTERN_FORMAT_ABBREV = 1;
/**
* [icu] Somewhat temporary constant for leap month pattern type, adequate for Chinese calendar.
* @hide draft / provisional / internal are hidden on Android
*/
static final int DT_LEAP_MONTH_PATTERN_FORMAT_NARROW = 2;
/**
* [icu] Somewhat temporary constant for leap month pattern type, adequate for Chinese calendar.
* @hide draft / provisional / internal are hidden on Android
*/
static final int DT_LEAP_MONTH_PATTERN_STANDALONE_WIDE = 3;
/**
* [icu] Somewhat temporary constant for leap month pattern type, adequate for Chinese calendar.
* @hide draft / provisional / internal are hidden on Android
*/
static final int DT_LEAP_MONTH_PATTERN_STANDALONE_ABBREV = 4;
/**
* [icu] Somewhat temporary constant for leap month pattern type, adequate for Chinese calendar.
* @hide draft / provisional / internal are hidden on Android
*/
static final int DT_LEAP_MONTH_PATTERN_STANDALONE_NARROW = 5;
/**
* [icu] Somewhat temporary constant for leap month pattern type, adequate for Chinese calendar.
* @hide draft / provisional / internal are hidden on Android
*/
static final int DT_LEAP_MONTH_PATTERN_NUMERIC = 6;
/**
* [icu] Somewhat temporary constant for month pattern count, adequate for Chinese calendar.
* @hide draft / provisional / internal are hidden on Android
*/
static final int DT_MONTH_PATTERN_COUNT = 7;
/**
* [icu] This default time separator is used for formatting when the locale
* doesn't specify any time separator, and always recognized when parsing.
* @hide draft / provisional / internal are hidden on Android
*/
static final String DEFAULT_TIME_SEPARATOR = ":";
/**
* [icu] This alternate time separator is always recognized when parsing.
* @hide draft / provisional / internal are hidden on Android
*/
static final String ALTERNATE_TIME_SEPARATOR = ".";
/**
* Constructs a DateFormatSymbols object by loading format data from
* resources for the default FORMAT
locale.
*
* @throws java.util.MissingResourceException if the resources for the default locale
* cannot be found or cannot be loaded.
* @see Category#FORMAT
*/
public DateFormatSymbols()
{
this(ULocale.getDefault(Category.FORMAT));
}
/**
* Constructs a DateFormatSymbols object by loading format data from
* resources for the given locale.
*
* @throws java.util.MissingResourceException if the resources for the specified
* locale cannot be found or cannot be loaded.
*/
public DateFormatSymbols(Locale locale)
{
this(ULocale.forLocale(locale));
}
/**
* [icu] Constructs a DateFormatSymbols object by loading format data from
* resources for the given ulocale.
*
* @throws java.util.MissingResourceException if the resources for the specified
* locale cannot be found or cannot be loaded.
*/
public DateFormatSymbols(ULocale locale)
{
initializeData(locale, CalendarUtil.getCalendarType(locale));
}
/**
* Returns a DateFormatSymbols instance for the default locale.
*
* [icu] Note: Unlike java.text.DateFormatSymbols#getInstance
,
* this method simply returns new android.icu.text.DateFormatSymbols()
.
* ICU does not support DateFormatSymbolsProvider
introduced in Java 6
* or its equivalent implementation for now.
*
* @return A DateFormatSymbols instance.
*/
public static DateFormatSymbols getInstance() {
return new DateFormatSymbols();
}
/**
* Returns a DateFormatSymbols instance for the given locale.
*
* [icu] Note: Unlike java.text.DateFormatSymbols#getInstance
,
* this method simply returns new android.icu.text.DateFormatSymbols(locale)
.
* ICU does not support DateFormatSymbolsProvider
introduced in Java 6
* or its equivalent implementation for now.
*
* @param locale the locale.
* @return A DateFormatSymbols instance.
*/
public static DateFormatSymbols getInstance(Locale locale) {
return new DateFormatSymbols(locale);
}
/**
* [icu] Returns a DateFormatSymbols instance for the given locale.
*
* [icu] Note: Unlike java.text.DateFormatSymbols#getInstance
,
* this method simply returns new android.icu.text.DateFormatSymbols(locale)
.
* ICU does not support DateFormatSymbolsProvider
introduced in Java 6
* or its equivalent implementation for now.
*
* @param locale the locale.
* @return A DateFormatSymbols instance.
*/
public static DateFormatSymbols getInstance(ULocale locale) {
return new DateFormatSymbols(locale);
}
/**
* Returns an array of all locales for which the getInstance
methods of
* this class can return localized instances.
*
* [icu] Note: Unlike java.text.DateFormatSymbols#getAvailableLocales
,
* this method simply returns the array of Locale
s available in this
* class. ICU does not support DateFormatSymbolsProvider
introduced in
* Java 6 or its equivalent implementation for now.
*
* @return An array of Locale
s for which localized
* DateFormatSymbols
instances are available.
*/
public static Locale[] getAvailableLocales() {
return ICUResourceBundle.getAvailableLocales();
}
/**
* [icu] Returns an array of all locales for which the getInstance
* methods of this class can return localized instances.
*
* [icu] Note: Unlike java.text.DateFormatSymbols#getAvailableLocales
,
* this method simply returns the array of ULocale
s available in this
* class. ICU does not support DateFormatSymbolsProvider
introduced in
* Java 6 or its equivalent implementation for now.
*
* @return An array of ULocale
s for which localized
* DateFormatSymbols
instances are available.
* @hide draft / provisional / internal are hidden on Android
*/
public static ULocale[] getAvailableULocales() {
return ICUResourceBundle.getAvailableULocales();
}
/**
* Era strings. For example: "AD" and "BC". An array of 2 strings,
* indexed by Calendar.BC
and Calendar.AD
.
* @serial
*/
String eras[] = null;
/**
* Era name strings. For example: "Anno Domini" and "Before Christ". An array of 2 strings,
* indexed by Calendar.BC
and Calendar.AD
.
* @serial
*/
String eraNames[] = null;
/**
* Narrow era names. For example: "A" and "B". An array of 2 strings,
* indexed by Calendar.BC
and Calendar.AD
.
* @serial
*/
String narrowEras[] = null;
/**
* Month strings. For example: "January", "February", etc. An array
* of 13 strings (some calendars have 13 months), indexed by
* Calendar.JANUARY
, Calendar.FEBRUARY
, etc.
* @serial
*/
String months[] = null;
/**
* Short month strings. For example: "Jan", "Feb", etc. An array of
* 13 strings (some calendars have 13 months), indexed by
* Calendar.JANUARY
, Calendar.FEBRUARY
, etc.
* @serial
*/
String shortMonths[] = null;
/**
* Narrow month strings. For example: "J", "F", etc. An array of
* 13 strings (some calendars have 13 months), indexed by
* Calendar.JANUARY
, Calendar.FEBRUARY
, etc.
* @serial
*/
String narrowMonths[] = null;
/**
* Standalone month strings. For example: "January", "February", etc. An array
* of 13 strings (some calendars have 13 months), indexed by
* Calendar.JANUARY
, Calendar.FEBRUARY
, etc.
* @serial
*/
String standaloneMonths[] = null;
/**
* Standalone short month strings. For example: "Jan", "Feb", etc. An array of
* 13 strings (some calendars have 13 months), indexed by
* Calendar.JANUARY
, Calendar.FEBRUARY
, etc.
* @serial
*/
String standaloneShortMonths[] = null;
/**
* Standalone narrow month strings. For example: "J", "F", etc. An array of
* 13 strings (some calendars have 13 months), indexed by
* Calendar.JANUARY
, Calendar.FEBRUARY
, etc.
* @serial
*/
String standaloneNarrowMonths[] = null;
/**
* Format wide weekday strings, for example: "Sunday", "Monday", etc.
* An array of 8 strings, indexed by Calendar.SUNDAY
,
* Calendar.MONDAY
, etc.
* The element weekdays[0]
is ignored.
* @serial
*/
String weekdays[] = null;
/**
* CLDR-style format abbreviated (not short) weekday strings,
* for example: "Sun", "Mon", etc.
* An array of 8 strings, indexed by Calendar.SUNDAY
,
* Calendar.MONDAY
, etc.
* The element shortWeekdays[0]
is ignored.
* @serial
*/
String shortWeekdays[] = null;
/**
* CLDR-style format short weekday strings, for example: "Su", "Mo", etc.
* An array of 8 strings, indexed by Calendar.SUNDAY
,
* Calendar.MONDAY
, etc.
* The element shorterWeekdays[0]
is ignored.
* @serial
*/
// Note, serialization restore from pre-ICU-51 will leave this null.
String shorterWeekdays[] = null;
/**
* CLDR-style format narrow weekday strings, for example: "S", "M", etc.
* An array of 8 strings, indexed by Calendar.SUNDAY
,
* Calendar.MONDAY
, etc.
* The element narrowWeekdays[0]
is ignored.
* @serial
*/
String narrowWeekdays[] = null;
/**
* Standalone wide weekday strings. For example: "Sunday", "Monday", etc.
* An array of 8 strings, indexed by Calendar.SUNDAY
,
* Calendar.MONDAY
, etc.
* The element standaloneWeekdays[0]
is ignored.
* @serial
*/
String standaloneWeekdays[] = null;
/**
* CLDR-style standalone abbreviated (not short) weekday strings,
* for example: "Sun", "Mon", etc.
* An array of 8 strings, indexed by Calendar.SUNDAY
,
* Calendar.MONDAY
, etc.
* The element standaloneShortWeekdays[0]
is ignored.
* @serial
*/
String standaloneShortWeekdays[] = null;
/**
* CLDR-style standalone short weekday strings, for example: "Sun", "Mon", etc.
* An array of 8 strings, indexed by Calendar.SUNDAY
,
* Calendar.MONDAY
, etc.
* The element standaloneShorterWeekdays[0]
is ignored.
* @serial
*/
// Note, serialization restore from pre-ICU-51 will leave this null.
String standaloneShorterWeekdays[] = null;
/**
* Standalone narrow weekday strings. For example: "S", "M", etc. An array
* of 8 strings, indexed by Calendar.SUNDAY
,
* Calendar.MONDAY
, etc.
* The element standaloneNarrowWeekdays[0]
is ignored.
* @serial
*/
String standaloneNarrowWeekdays[] = null;
/**
* AM and PM strings. For example: "AM" and "PM". An array of
* 2 strings, indexed by Calendar.AM
and
* Calendar.PM
.
* @serial
*/
String ampms[] = null;
/**
* narrow AM and PM strings. For example: "a" and "p". An array of
* 2 strings, indexed by Calendar.AM
and
* Calendar.PM
.
* @serial
*/
String ampmsNarrow[] = null;
/**
* Time separator string. For example: ":".
* @serial
*/
private String timeSeparator = null;
/**
* Abbreviated quarter names. For example: "Q1", "Q2", "Q3", "Q4". An array
* of 4 strings indexed by the month divided by 3.
* @serial
*/
String shortQuarters[] = null;
/**
* Narrow quarter names. For example: "1", "2", "3", "4". An array
* of 4 strings indexed by the month divided by 3.
* @serial
*/
String narrowQuarters[] = null;
/**
* Full quarter names. For example: "1st Quarter", "2nd Quarter", "3rd Quarter",
* "4th Quarter". An array of 4 strings, indexed by the month divided by 3.
* @serial
*/
String quarters[] = null;
/**
* Standalone abbreviated quarter names. For example: "Q1", "Q2", "Q3", "Q4". An array
* of 4 strings indexed by the month divided by 3.
* @serial
*/
String standaloneShortQuarters[] = null;
/**
* Standalone narrow quarter names. For example: "1", "2", "3", "4". An array
* of 4 strings indexed by the month divided by 3.
* @serial
*/
String standaloneNarrowQuarters[] = null;
/**
* Standalone full quarter names. For example: "1st Quarter", "2nd Quarter", "3rd Quarter",
* "4th Quarter". An array of 4 strings, indexed by the month divided by 3.
* @serial
*/
String standaloneQuarters[] = null;
/**
* All leap month patterns, for example "{0}bis".
* An array of DT_MONTH_PATTERN_COUNT strings, indexed by the DT_LEAP_MONTH_PATTERN_XXX value.
* @serial
*/
String leapMonthPatterns[] = null;
/**
* Cyclic year names, for example: "jia-zi", "yi-chou", ... "gui-hai".
* An array of (normally) 60 strings, corresponding to cyclic years 1-60 (in Calendar YEAR field).
* Currently we only have data for format/abbreviated.
* For the others, just get from format/abbreviated, ignore set.
* @serial
*/
String shortYearNames[] = null;
/**
* Cyclic zodiac names, for example: "Rat", "Ox", "Tiger", etc.
* An array of (normally) 12 strings.
* Currently we only have data for format/abbreviated.
* For the others, just get from format/abbreviated, ignore set.
* @serial
*/
String shortZodiacNames[] = null;
/**
* Localized names of time zones in this locale. This is a
* two-dimensional array of strings of size n by m,
* where m is at least 5 and up to 7. Each of the n rows is an
* entry containing the localized names for a single TimeZone
.
* Each such row contains (with i
ranging from
* 0..n-1):
*
zoneStrings[i][0]
- time zone IDzoneStrings[i][1]
- long name of zone in standard
* timezoneStrings[i][2]
- short name of zone in
* standard timezoneStrings[i][3]
- long name of zone in daylight
* savings timezoneStrings[i][4]
- short name of zone in daylight
* savings timezoneStrings[i][5]
- location name of zonezoneStrings[i][6]
- long generic name of zonezoneStrings[i][7]
- short generic of zoneDateFormat.ERA_FIELD
,
* DateFormat.YEAR_FIELD
, etc. Thus, if the string were
* "Xz...", then localized patterns would use 'X' for era and 'z' for year.
* @serial
*/
String localPatternChars = null;
/**
* Localized names for abbreviated (== short) day periods.
* An array of strings, in the order of DayPeriod constants.
*/
String abbreviatedDayPeriods[] = null;
/**
* Localized names for wide day periods.
* An array of strings, in the order of DayPeriod constants.
*/
String wideDayPeriods[] = null;
/**
* Localized names for narrow day periods.
* An array of strings, in the order of DayPeriod constants.
*/
String narrowDayPeriods[] = null;
/**
* Localized names for standalone abbreviated (== short) day periods.
* An array of strings, in the order of DayPeriod constants.
*/
String standaloneAbbreviatedDayPeriods[] = null;
/**
* Localized names for standalone wide day periods.
* An array of strings, in the order of DayPeriod constants.
*/
String standaloneWideDayPeriods[] = null;
/**
* Localized names for standalone narrow day periods.
* An array of strings, in the order of DayPeriod constants.
*/
String standaloneNarrowDayPeriods[] = null;
/* use serialVersionUID from JDK 1.1.4 for interoperability */
private static final long serialVersionUID = -5987973545549424702L;
private static final String[][] CALENDAR_CLASSES = {
{"GregorianCalendar", "gregorian"},
{"JapaneseCalendar", "japanese"},
{"BuddhistCalendar", "buddhist"},
{"TaiwanCalendar", "roc"},
{"PersianCalendar", "persian"},
{"IslamicCalendar", "islamic"},
{"HebrewCalendar", "hebrew"},
{"ChineseCalendar", "chinese"},
{"IndianCalendar", "indian"},
{"CopticCalendar", "coptic"},
{"EthiopicCalendar", "ethiopic"},
};
/**
* [icu] Constants for capitalization context usage types
* related to date formatting.
* @hide draft / provisional / internal are hidden on Android
*/
enum CapitalizationContextUsage {
OTHER,
MONTH_FORMAT, /* except narrow */
MONTH_STANDALONE, /* except narrow */
MONTH_NARROW,
DAY_FORMAT, /* except narrow */
DAY_STANDALONE, /* except narrow */
DAY_NARROW,
ERA_WIDE,
ERA_ABBREV,
ERA_NARROW,
ZONE_LONG,
ZONE_SHORT,
METAZONE_LONG,
METAZONE_SHORT
}
/** Map from resource key to CapitalizationContextUsage value
*/
private static final MapCalendar.SUNDAY
,
* Calendar.MONDAY
, etc. to index the result array.
*/
public String[] getWeekdays() {
return duplicate(weekdays);
}
/**
* Returns weekday strings. For example: "Sunday", "Monday", etc.
* @return the weekday strings. Use Calendar.SUNDAY
,
* Calendar.MONDAY
, etc. to index the result array.
* @param context Formatting context, either FORMAT or STANDALONE.
* @param width Width of strings to be returned, either
* WIDE, ABBREVIATED, SHORT, or NARROW
*/
public String[] getWeekdays(int context, int width) {
String [] returnValue = null;
switch (context) {
case FORMAT :
switch(width) {
case WIDE :
returnValue = weekdays;
break;
case ABBREVIATED :
returnValue = shortWeekdays;
break;
case SHORT :
returnValue = (shorterWeekdays != null)? shorterWeekdays: shortWeekdays;
break;
case NARROW :
returnValue = narrowWeekdays;
break;
}
break;
case STANDALONE :
switch(width) {
case WIDE :
returnValue = standaloneWeekdays;
break;
case ABBREVIATED :
returnValue = standaloneShortWeekdays;
break;
case SHORT :
returnValue = (standaloneShorterWeekdays != null)? standaloneShorterWeekdays: standaloneShortWeekdays;
break;
case NARROW :
returnValue = standaloneNarrowWeekdays;
break;
}
break;
}
if (returnValue == null) {
throw new IllegalArgumentException("Bad context or width argument");
}
return duplicate(returnValue);
}
/**
* Sets weekday strings. For example: "Sunday", "Monday", etc.
* @param newWeekdays The new weekday strings.
* @param context The formatting context, FORMAT or STANDALONE.
* @param width The width of the strings,
* either WIDE, ABBREVIATED, SHORT, or NARROW.
*/
public void setWeekdays(String[] newWeekdays, int context, int width) {
switch (context) {
case FORMAT :
switch(width) {
case WIDE :
weekdays = duplicate(newWeekdays);
break;
case ABBREVIATED :
shortWeekdays = duplicate(newWeekdays);
break;
case SHORT :
shorterWeekdays = duplicate(newWeekdays);
break;
case NARROW :
narrowWeekdays = duplicate(newWeekdays);
break;
}
break;
case STANDALONE :
switch(width) {
case WIDE :
standaloneWeekdays = duplicate(newWeekdays);
break;
case ABBREVIATED :
standaloneShortWeekdays = duplicate(newWeekdays);
break;
case SHORT :
standaloneShorterWeekdays = duplicate(newWeekdays);
break;
case NARROW :
standaloneNarrowWeekdays = duplicate(newWeekdays);
break;
}
break;
}
}
/**
* Sets wide weekday strings. For example: "Sunday", "Monday", etc.
* @param newWeekdays the new weekday strings. The array should
* be indexed by Calendar.SUNDAY
,
* Calendar.MONDAY
, etc.
*/
public void setWeekdays(String[] newWeekdays) {
weekdays = duplicate(newWeekdays);
}
/**
* Returns abbreviated weekday strings; for example: "Sun", "Mon", etc.
* (Note: the method name is misleading; it does not get the CLDR-style
* "short" weekday strings, e.g. "Su", "Mo", etc.)
* @return the abbreviated weekday strings. Use Calendar.SUNDAY
,
* Calendar.MONDAY
, etc. to index the result array.
*/
public String[] getShortWeekdays() {
return duplicate(shortWeekdays);
}
/**
* Sets abbreviated weekday strings; for example: "Sun", "Mon", etc.
* (Note: the method name is misleading; it does not set the CLDR-style
* "short" weekday strings, e.g. "Su", "Mo", etc.)
* @param newAbbrevWeekdays the new abbreviated weekday strings. The array should
* be indexed by Calendar.SUNDAY
,
* Calendar.MONDAY
, etc.
*/
public void setShortWeekdays(String[] newAbbrevWeekdays) {
shortWeekdays = duplicate(newAbbrevWeekdays);
}
/**
* [icu] Returns quarter strings. For example: "1st Quarter", "2nd Quarter", etc.
* @param context The quarter context, FORMAT or STANDALONE.
* @param width The width or the returned quarter string,
* WIDE, NARROW, or ABBREVIATED.
* @return the quarter strings.
*/
public String[] getQuarters(int context, int width) {
String [] returnValue = null;
switch (context) {
case FORMAT :
switch(width) {
case WIDE :
returnValue = quarters;
break;
case ABBREVIATED :
case SHORT : // no quarter data for this, defaults to ABBREVIATED
returnValue = shortQuarters;
break;
case NARROW :
returnValue = narrowQuarters;
break;
}
break;
case STANDALONE :
switch(width) {
case WIDE :
returnValue = standaloneQuarters;
break;
case ABBREVIATED :
case SHORT : // no quarter data for this, defaults to ABBREVIATED
returnValue = standaloneShortQuarters;
break;
case NARROW:
returnValue = standaloneNarrowQuarters;
break;
}
break;
}
if (returnValue == null) {
throw new IllegalArgumentException("Bad context or width argument");
}
return duplicate(returnValue);
}
/**
* [icu] Sets quarter strings. For example: "1st Quarter", "2nd Quarter", etc.
* @param newQuarters the new quarter strings.
* @param context The formatting context, FORMAT or STANDALONE.
* @param width The width of the quarter string,
* WIDE, NARROW, or ABBREVIATED.
*/
public void setQuarters(String[] newQuarters, int context, int width) {
switch (context) {
case FORMAT :
switch(width) {
case WIDE :
quarters = duplicate(newQuarters);
break;
case ABBREVIATED :
shortQuarters = duplicate(newQuarters);
break;
case NARROW :
narrowQuarters = duplicate(newQuarters);
break;
default : // HANDLE SHORT, etc.
break;
}
break;
case STANDALONE :
switch(width) {
case WIDE :
standaloneQuarters = duplicate(newQuarters);
break;
case ABBREVIATED :
standaloneShortQuarters = duplicate(newQuarters);
break;
case NARROW :
standaloneNarrowQuarters = duplicate(newQuarters);
break;
default : // HANDLE SHORT, etc.
break;
}
break;
}
}
/**
* Returns cyclic year name strings if the calendar has them,
* for example: "jia-zi", "yi-chou", etc.
* @param context The usage context: FORMAT, STANDALONE.
* @param width The requested name width: WIDE, ABBREVIATED, SHORT, NARROW.
* @return The year name strings, or null if they are not
* available for this calendar.
*/
public String[] getYearNames(int context, int width) {
// context & width ignored for now, one set of names for all uses
if (shortYearNames != null) {
return duplicate(shortYearNames);
}
return null;
}
/**
* Sets cyclic year name strings, for example: "jia-zi", "yi-chou", etc.
* @param yearNames The new cyclic year name strings.
* @param context The usage context: FORMAT, STANDALONE (currently only FORMAT is supported).
* @param width The name width: WIDE, ABBREVIATED, NARROW (currently only ABBREVIATED is supported).
*/
public void setYearNames(String[] yearNames, int context, int width) {
if (context == FORMAT && width == ABBREVIATED) {
shortYearNames = duplicate(yearNames);
}
}
/**
* Returns calendar zodiac name strings if the calendar has them,
* for example: "Rat", "Ox", "Tiger", etc.
* @param context The usage context: FORMAT, STANDALONE.
* @param width The requested name width: WIDE, ABBREVIATED, SHORT, NARROW.
* @return The zodiac name strings, or null if they are not
* available for this calendar.
*/
public String[] getZodiacNames(int context, int width) {
// context & width ignored for now, one set of names for all uses
if (shortZodiacNames != null) {
return duplicate(shortZodiacNames);
}
return null;
}
/**
* Sets calendar zodiac name strings, for example: "Rat", "Ox", "Tiger", etc.
* @param zodiacNames The new zodiac name strings.
* @param context The usage context: FORMAT, STANDALONE (currently only FORMAT is supported).
* @param width The name width: WIDE, ABBREVIATED, NARROW (currently only ABBREVIATED is supported).
*/
public void setZodiacNames(String[] zodiacNames, int context, int width) {
if (context == FORMAT && width == ABBREVIATED) {
shortZodiacNames = duplicate(zodiacNames);
}
}
/**
* Returns the appropriate leapMonthPattern if the calendar has them,
* for example: "{0}bis"
* @param context The usage context: FORMAT, STANDALONE, NUMERIC.
* @param width The requested pattern width: WIDE, ABBREVIATED, SHORT, NARROW.
* @return The leapMonthPattern, or null if not available for
* this calendar.
* @deprecated This API is ICU internal only.
* @hide original deprecated declaration
* @hide draft / provisional / internal are hidden on Android
*/
@Deprecated
public String getLeapMonthPattern(int context, int width) {
if (leapMonthPatterns != null) {
int leapMonthPatternIndex = -1;
switch (context) {
case FORMAT :
switch(width) {
case WIDE :
leapMonthPatternIndex = DT_LEAP_MONTH_PATTERN_FORMAT_WIDE;
break;
case ABBREVIATED :
case SHORT : // no month data for this, defaults to ABBREVIATED
leapMonthPatternIndex = DT_LEAP_MONTH_PATTERN_FORMAT_ABBREV;
break;
case NARROW :
leapMonthPatternIndex = DT_LEAP_MONTH_PATTERN_FORMAT_NARROW;
break;
}
break;
case STANDALONE :
switch(width) {
case WIDE :
leapMonthPatternIndex = DT_LEAP_MONTH_PATTERN_STANDALONE_WIDE;
break;
case ABBREVIATED :
case SHORT : // no month data for this, defaults to ABBREVIATED
leapMonthPatternIndex = DT_LEAP_MONTH_PATTERN_FORMAT_ABBREV;
break;
case NARROW :
leapMonthPatternIndex = DT_LEAP_MONTH_PATTERN_STANDALONE_NARROW;
break;
}
break;
case NUMERIC :
leapMonthPatternIndex = DT_LEAP_MONTH_PATTERN_NUMERIC;
break;
}
if (leapMonthPatternIndex < 0) {
throw new IllegalArgumentException("Bad context or width argument");
}
return leapMonthPatterns[leapMonthPatternIndex];
}
return null;
}
/**
* Sets a leapMonthPattern, for example: "{0}bis"
* @param leapMonthPattern The new leapMonthPattern.
* @param context The usage context: FORMAT, STANDALONE, NUMERIC.
* @param width The name width: WIDE, ABBREVIATED, NARROW.
* @deprecated This API is ICU internal only.
* @hide original deprecated declaration
* @hide draft / provisional / internal are hidden on Android
*/
@Deprecated
public void setLeapMonthPattern(String leapMonthPattern, int context, int width) {
if (leapMonthPatterns != null) {
int leapMonthPatternIndex = -1;
switch (context) {
case FORMAT :
switch(width) {
case WIDE :
leapMonthPatternIndex = DT_LEAP_MONTH_PATTERN_FORMAT_WIDE;
break;
case ABBREVIATED :
leapMonthPatternIndex = DT_LEAP_MONTH_PATTERN_FORMAT_ABBREV;
break;
case NARROW :
leapMonthPatternIndex = DT_LEAP_MONTH_PATTERN_FORMAT_NARROW;
break;
default : // HANDLE SHORT, etc.
break;
}
break;
case STANDALONE :
switch(width) {
case WIDE :
leapMonthPatternIndex = DT_LEAP_MONTH_PATTERN_STANDALONE_WIDE;
break;
case ABBREVIATED :
leapMonthPatternIndex = DT_LEAP_MONTH_PATTERN_FORMAT_ABBREV;
break;
case NARROW :
leapMonthPatternIndex = DT_LEAP_MONTH_PATTERN_STANDALONE_NARROW;
break;
default : // HANDLE SHORT, etc.
break;
}
break;
case NUMERIC :
leapMonthPatternIndex = DT_LEAP_MONTH_PATTERN_NUMERIC;
break;
default :
break;
}
if (leapMonthPatternIndex >= 0) {
leapMonthPatterns[leapMonthPatternIndex] = leapMonthPattern;
}
}
}
/**
* Returns am/pm strings. For example: "AM" and "PM".
* @return the weekday strings.
*/
public String[] getAmPmStrings() {
return duplicate(ampms);
}
/**
* Sets am/pm strings. For example: "AM" and "PM".
* @param newAmpms the new ampm strings.
*/
public void setAmPmStrings(String[] newAmpms) {
ampms = duplicate(newAmpms);
}
// BEGIN Android-added: Add a getter for ampmsNarrow
/**
* Returns narrow am/pm strings. For example: "a" and "p".
* @return narrow ampm strings
* @hide draft / provisional / internal are hidden on Android
*/
@libcore.api.CorePlatformApi
public String[] getAmpmNarrowStrings() {
return duplicate(ampmsNarrow);
}
// END Android-added: Add a getter for ampmsNarrow
/**
* Returns the time separator string. For example: ":".
* @return the time separator string.
* @deprecated This API is ICU internal only.
* @hide draft / provisional / internal are hidden on Android
*/
@Deprecated
public String getTimeSeparatorString() {
return timeSeparator;
}
/**
* Sets the time separator string. For example: ":".
* @param newTimeSeparator the new time separator string.
* @deprecated This API is ICU internal only.
* @hide draft / provisional / internal are hidden on Android
*/
@Deprecated
public void setTimeSeparatorString(String newTimeSeparator) {
timeSeparator = newTimeSeparator;
}
/**
* Returns time zone strings.
* * The array returned by this API is a two dimensional String array and * each row contains at least following strings: *
null
.
* * Note: ICU implements the time zone display name formatting algorithm * specified by UTS#35 Unicode * Locale Data Markup Language(LDML). The algorithm supports historic * display name changes and various different types of names not available in * {@link java.text.DateFormatSymbols#getZoneStrings()}. For accessing the full * set of time zone string data used by ICU implementation, you should use * {@link TimeZoneNames} APIs instead. * * @return the time zone strings. */ public String[][] getZoneStrings() { if (zoneStrings != null) { return duplicate(zoneStrings); } String[] tzIDs = TimeZone.getAvailableIDs(); TimeZoneNames tznames = TimeZoneNames.getInstance(validLocale); tznames.loadAllDisplayNames(); NameType types[] = { NameType.LONG_STANDARD, NameType.SHORT_STANDARD, NameType.LONG_DAYLIGHT, NameType.SHORT_DAYLIGHT }; long now = System.currentTimeMillis(); String[][] array = new String[tzIDs.length][5]; for (int i = 0; i < tzIDs.length; i++) { String canonicalID = TimeZone.getCanonicalID(tzIDs[i]); if (canonicalID == null) { canonicalID = tzIDs[i]; } array[i][0] = tzIDs[i]; tznames.getDisplayNames(canonicalID, types, now, array[i], 1); } zoneStrings = array; return zoneStrings; } /** * Sets time zone strings. *
* Note: {@link SimpleDateFormat} no longer uses the
* zone strings stored in a DateFormatSymbols
.
* Therefore, the time zone strings set by this method have
* no effects in an instance of SimpleDateFormat
* for formatting time zones. If you want to customize time
* zone display names formatted by SimpleDateFormat
,
* you should customize {@link TimeZoneFormat} and set the
* instance by {@link SimpleDateFormat#setTimeZoneFormat(TimeZoneFormat)}
* instead.
*
* @param newZoneStrings the new time zone strings.
*/
public void setZoneStrings(String[][] newZoneStrings) {
zoneStrings = duplicate(newZoneStrings);
}
/**
* Returns localized date-time pattern characters. For example: 'u', 't', etc.
*
*
Note: ICU no longer provides localized date-time pattern characters for a locale
* starting ICU 3.8. This method returns the non-localized date-time pattern
* characters unless user defined localized data is set by setLocalPatternChars.
* @return the localized date-time pattern characters.
*/
public String getLocalPatternChars() {
return localPatternChars;
}
/**
* Sets localized date-time pattern characters. For example: 'u', 't', etc.
* @param newLocalPatternChars the new localized date-time
* pattern characters.
*/
public void setLocalPatternChars(String newLocalPatternChars) {
localPatternChars = newLocalPatternChars;
}
/**
* Overrides clone.
*/
@Override
public Object clone()
{
try {
DateFormatSymbols other = (DateFormatSymbols)super.clone();
return other;
} catch (CloneNotSupportedException e) {
///CLOVER:OFF
throw new ICUCloneNotSupportedException(e);
///CLOVER:ON
}
}
/**
* Override hashCode.
* Generates a hash code for the DateFormatSymbols object.
*/
@Override
public int hashCode() {
// Is this sufficient?
return requestedLocale.toString().hashCode();
}
/**
* Overrides equals.
*/
@Override
public boolean equals(Object obj)
{
if (this == obj) return true;
if (obj == null || getClass() != obj.getClass()) return false;
DateFormatSymbols that = (DateFormatSymbols) obj;
return (Utility.arrayEquals(eras, that.eras)
&& Utility.arrayEquals(eraNames, that.eraNames)
&& Utility.arrayEquals(narrowEras, that.narrowEras)
&& Utility.arrayEquals(months, that.months)
&& Utility.arrayEquals(shortMonths, that.shortMonths)
&& Utility.arrayEquals(narrowMonths, that.narrowMonths)
&& Utility.arrayEquals(standaloneMonths, that.standaloneMonths)
&& Utility.arrayEquals(standaloneShortMonths, that.standaloneShortMonths)
&& Utility.arrayEquals(standaloneNarrowMonths, that.standaloneNarrowMonths)
&& Utility.arrayEquals(weekdays, that.weekdays)
&& Utility.arrayEquals(shortWeekdays, that.shortWeekdays)
&& Utility.arrayEquals(shorterWeekdays, that.shorterWeekdays)
&& Utility.arrayEquals(narrowWeekdays, that.narrowWeekdays)
&& Utility.arrayEquals(standaloneWeekdays, that.standaloneWeekdays)
&& Utility.arrayEquals(standaloneShortWeekdays, that.standaloneShortWeekdays)
&& Utility.arrayEquals(standaloneShorterWeekdays, that.standaloneShorterWeekdays)
&& Utility.arrayEquals(standaloneNarrowWeekdays, that.standaloneNarrowWeekdays)
&& Utility.arrayEquals(ampms, that.ampms)
&& Utility.arrayEquals(ampmsNarrow, that.ampmsNarrow)
&& Utility.arrayEquals(abbreviatedDayPeriods, that.abbreviatedDayPeriods)
&& Utility.arrayEquals(wideDayPeriods, that.wideDayPeriods)
&& Utility.arrayEquals(narrowDayPeriods, that.narrowDayPeriods)
&& Utility.arrayEquals(standaloneAbbreviatedDayPeriods, that.standaloneAbbreviatedDayPeriods)
&& Utility.arrayEquals(standaloneWideDayPeriods, that.standaloneWideDayPeriods)
&& Utility.arrayEquals(standaloneNarrowDayPeriods, that.standaloneNarrowDayPeriods)
&& Utility.arrayEquals(timeSeparator, that.timeSeparator)
&& arrayOfArrayEquals(zoneStrings, that.zoneStrings)
// getDiplayName maps deprecated country and language codes to the current ones
// too bad there is no way to get the current codes!
// I thought canonicalize() would map the codes but .. alas! it doesn't.
&& requestedLocale.getDisplayName().equals(that.requestedLocale.getDisplayName())
&& Utility.arrayEquals(localPatternChars,
that.localPatternChars));
}
// =======================privates===============================
/**
* Useful constant for defining timezone offsets.
*/
static final int millisPerHour = 60*60*1000;
// DateFormatSymbols cache
// Android-changed: Load extra data, e.g. narrow quarters.
/*
private static CacheBase
* The resource bundle name is based on the calendar's fully-specified
* class name, with ".resources" inserted at the end of the package name
* (just before the class name) and "Symbols" appended to the end.
* For example, the bundle corresponding to "android.icu.util.HebrewCalendar"
* is "android.icu.impl.data.HebrewCalendarSymbols".
*
* Note:Because of the structural changes in the ICU locale bundle,
* this API no longer works as described. This method always returns null.
* @deprecated ICU 4.0
* @hide original deprecated declaration
*/
@Deprecated
// This API was formerly @stable ICU 2.0
static public ResourceBundle getDateFormatBundle(Class extends Calendar> calendarClass,
Locale locale)
throws MissingResourceException {
return null;
}
/**
* Finds the ResourceBundle containing the date format information for
* a specified calendar subclass in a given locale.
*
* The resource bundle name is based on the calendar's fully-specified
* class name, with ".resources" inserted at the end of the package name
* (just before the class name) and "Symbols" appended to the end.
* For example, the bundle corresponding to "android.icu.util.HebrewCalendar"
* is "android.icu.impl.data.HebrewCalendarSymbols".
*
* Note:Because of the structural changes in the ICU locale bundle,
* this API no longer works as described. This method always returns null.
* @deprecated ICU 4.0
* @hide original deprecated declaration
*/
@Deprecated
// This API was formerly @stable ICU 3.2
static public ResourceBundle getDateFormatBundle(Class extends Calendar> calendarClass,
ULocale locale)
throws MissingResourceException {
return null;
}
/**
* Variant of getDateFormatBundle(java.lang.Class, java.util.Locale) that takes
* a Calendar instance instead of a Calendar class.
*
* Note:Because of the structural changes in the ICU locale bundle,
* this API no longer works as described. This method always returns null.
* @see #getDateFormatBundle(java.lang.Class, java.util.Locale)
* @deprecated ICU 4.0
* @hide original deprecated declaration
*/
@Deprecated
// This API was formerly @stable ICU 2.2
public static ResourceBundle getDateFormatBundle(Calendar cal, Locale locale)
throws MissingResourceException {
return null;
}
/**
* Variant of getDateFormatBundle(java.lang.Class, java.util.Locale) that takes
* a Calendar instance instead of a Calendar class.
*
* Note:Because of the structural changes in the ICU locale bundle,
* this API no longer works as described. This method always returns null.
* @see #getDateFormatBundle(java.lang.Class, java.util.Locale)
* @deprecated ICU 4.0
* @hide original deprecated declaration
*/
@Deprecated
// This API was formerly @stable ICU 3.2
public static ResourceBundle getDateFormatBundle(Calendar cal, ULocale locale)
throws MissingResourceException {
return null;
}
// -------- BEGIN ULocale boilerplate --------
/**
* Returns the locale that was used to create this object, or null.
* This may may differ from the locale requested at the time of
* this object's creation. For example, if an object is created
* for locale en_US_CALIFORNIA, the actual data may be
* drawn from en (the actual locale), and
* en_US may be the most specific locale that exists (the
* valid locale).
*
* Note: This method will be implemented in ICU 3.0; ICU 2.8
* contains a partial preview implementation. The actual
* locale is returned correctly, but the valid locale is
* not, in most cases.
* @param type type of information requested, either {@link
* android.icu.util.ULocale#VALID_LOCALE} or {@link
* android.icu.util.ULocale#ACTUAL_LOCALE}.
* @return the information specified by type, or null if
* this object was not constructed from locale data.
* @see android.icu.util.ULocale
* @see android.icu.util.ULocale#VALID_LOCALE
* @see android.icu.util.ULocale#ACTUAL_LOCALE
* @hide draft / provisional / internal are hidden on Android
*/
@android.compat.annotation.UnsupportedAppUsage(maxTargetSdk = 30, trackingBug = 170729553)
public final ULocale getLocale(ULocale.Type type) {
return type == ULocale.ACTUAL_LOCALE ?
this.actualLocale : this.validLocale;
}
/**
* Sets information about the locales that were used to create this
* object. If the object was not constructed from locale data,
* both arguments should be set to null. Otherwise, neither
* should be null. The actual locale must be at the same level or
* less specific than the valid locale. This method is intended
* for use by factories or other entities that create objects of
* this class.
* @param valid the most specific locale containing any resource
* data, or null
* @param actual the locale containing data used to construct this
* object, or null
* @see android.icu.util.ULocale
* @see android.icu.util.ULocale#VALID_LOCALE
* @see android.icu.util.ULocale#ACTUAL_LOCALE
*/
final void setLocale(ULocale valid, ULocale actual) {
// Change the following to an assertion later
if ((valid == null) != (actual == null)) {
///CLOVER:OFF
throw new IllegalArgumentException();
///CLOVER:ON
}
// Another check we could do is that the actual locale is at
// the same level or less specific than the valid locale.
this.validLocale = valid;
this.actualLocale = actual;
}
/**
* The most specific locale containing any resource data, or null.
* @see android.icu.util.ULocale
*/
private ULocale validLocale;
/**
* The locale containing data used to construct this object, or
* null.
* @see android.icu.util.ULocale
*/
private ULocale actualLocale;
// -------- END ULocale boilerplate --------
/**
* 3.8 or older version did not have localized GMT format
* patterns.
*/
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
stream.defaultReadObject();
}
}