java.text
Class DateFormatSymbols

java.lang.Object
  extended byjava.text.DateFormatSymbols
All Implemented Interfaces:
Cloneable, Serializable

public class DateFormatSymbols
extends Object
implements Serializable, Cloneable

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 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 cloneable. 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.

Author:
Chen-Lieh Huang
See Also:
DateFormat, SimpleDateFormat, SimpleTimeZone, Serialized Form

Field Summary
(package private)  String[] ampms
          AM and PM strings.
private static Hashtable cachedLocaleData
          Cache to hold the LocaleElements and DateFormatZoneData ResourceBundles of a Locale.
private static Hashtable cachedZoneData
          cache to hold time zone localized strings.
(package private)  String[] eras
          Era strings.
(package private)  String localPatternChars
          Localized date-time pattern characters.
(package private) static int millisPerHour
          Useful constant for defining timezone offsets.
(package private)  String[] months
          Month strings.
(package private) static String patternChars
          Unlocalized date-time pattern characters.
(package private) static long serialVersionUID
           
(package private)  String[] shortMonths
          Short month strings.
(package private)  String[] shortWeekdays
          Short weekday strings.
(package private)  String[] weekdays
          Weekday strings.
(package private)  String[][] zoneStrings
          Localized names of time zones in this locale.
 
Constructor Summary
DateFormatSymbols()
          Construct a DateFormatSymbols object by loading format data from resources for the default locale.
DateFormatSymbols(Locale locale)
          Construct a DateFormatSymbols object by loading format data from resources for the given locale.
 
Method Summary
private  ResourceBundle[] cacheLookup(Locale desiredLocale)
          Look up resource data for the desiredLocale in the cache; update the cache if necessary.
 Object clone()
          Overrides Cloneable
private  void copyMembers(DateFormatSymbols src, DateFormatSymbols dst)
          Clones all the data members from the source DateFormatSymbols to the target DateFormatSymbols.
private  String[] duplicate(String[] srcArray)
          Clones an array of Strings.
 boolean equals(Object obj)
          Override equals
private  boolean equals(String[] current, String[] other)
          Compares the equality of the two arrays of String.
 String[] getAmPmStrings()
          Gets ampm strings.
 String[] getEras()
          Gets era strings.
 String getLocalPatternChars()
          Gets localized date-time pattern characters.
 String[] getMonths()
          Gets month strings.
 String[] getShortMonths()
          Gets short month strings.
 String[] getShortWeekdays()
          Gets short weekday strings.
 String[] getWeekdays()
          Gets weekday strings.
(package private)  int getZoneIndex(String ID)
          Package private: used by SimpleDateFormat Gets the index for the given time zone ID to obtain the timezone strings for formatting.
 String[][] getZoneStrings()
          Gets timezone strings.
 int hashCode()
          Override hashCode.
private  void initializeData(Locale desiredLocale)
           
private  String[][] loadZoneStrings(Locale desiredLocale, ResourceBundle rsrc)
          Load time zone localized strings.
 void setAmPmStrings(String[] newAmpms)
          Sets ampm strings.
 void setEras(String[] newEras)
          Sets era strings.
 void setLocalPatternChars(String newLocalPatternChars)
          Sets localized date-time pattern characters.
 void setMonths(String[] newMonths)
          Sets month strings.
 void setShortMonths(String[] newShortMonths)
          Sets short month strings.
 void setShortWeekdays(String[] newShortWeekdays)
          Sets short weekday strings.
 void setWeekdays(String[] newWeekdays)
          Sets weekday strings.
 void setZoneStrings(String[][] newZoneStrings)
          Sets timezone strings.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

eras

String[] eras
Era strings. For example: "AD" and "BC". An array of 2 strings, indexed by Calendar.BC and Calendar.AD.


months

String[] months
Month strings. For example: "January", "February", etc. An array of 13 strings (some calendars have 13 months), indexed by Calendar.JANUARY, Calendar.FEBRUARY, etc.


shortMonths

String[] shortMonths
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.


weekdays

String[] weekdays
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.


shortWeekdays

String[] shortWeekdays
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.


ampms

String[] ampms
AM and PM strings. For example: "AM" and "PM". An array of 2 strings, indexed by Calendar.AM and Calendar.PM.


zoneStrings

String[][] zoneStrings
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. 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): The zone ID is not localized; it corresponds to the ID value associated with a system time zone object. All other entries are localized names. If a zone does not implement daylight savings time, the daylight savings time names are ignored.

See Also:
TimeZone

patternChars

static final String patternChars
Unlocalized date-time pattern characters. For example: 'y', 'd', etc. All locales use the same these unlocalized pattern characters.

See Also:
Constant Field Values

localPatternChars

String localPatternChars
Localized date-time pattern characters. For example, a locale may wish to use 'u' rather than 'y' to represent years in its date format pattern strings. This string must be exactly 18 characters long, with the index of the characters described by DateFormat.ERA_FIELD, DateFormat.YEAR_FIELD, etc. Thus, if the string were "Xz...", then localized patterns would use 'X' for era and 'z' for year.


serialVersionUID

static final long serialVersionUID
See Also:
Constant Field Values

millisPerHour

static final int millisPerHour
Useful constant for defining timezone offsets.

See Also:
Constant Field Values

cachedLocaleData

private static Hashtable cachedLocaleData
Cache to hold the LocaleElements and DateFormatZoneData ResourceBundles of a Locale.


cachedZoneData

private static Hashtable cachedZoneData
cache to hold time zone localized strings. Keyed by Locale

Constructor Detail

DateFormatSymbols

public DateFormatSymbols()
Construct a DateFormatSymbols object by loading format data from resources for the default locale.

Throws:
MissingResourceException - if the resources for the default locale cannot be found or cannot be loaded.

DateFormatSymbols

public DateFormatSymbols(Locale locale)
Construct a DateFormatSymbols object by loading format data from resources for the given locale.

Throws:
MissingResourceException - if the resources for the specified locale cannot be found or cannot be loaded.
Method Detail

getEras

public String[] getEras()
Gets era strings. For example: "AD" and "BC".

Returns:
the era strings.

setEras

public void setEras(String[] newEras)
Sets era strings. For example: "AD" and "BC".

Parameters:
newEras - the new era strings.

getMonths

public String[] getMonths()
Gets month strings. For example: "January", "February", etc.

Returns:
the month strings.

setMonths

public void setMonths(String[] newMonths)
Sets month strings. For example: "January", "February", etc.

Parameters:
newMonths - the new month strings.

getShortMonths

public String[] getShortMonths()
Gets short month strings. For example: "Jan", "Feb", etc.

Returns:
the short month strings.

setShortMonths

public void setShortMonths(String[] newShortMonths)
Sets short month strings. For example: "Jan", "Feb", etc.

Parameters:
newShortMonths - the new short month strings.

getWeekdays

public String[] getWeekdays()
Gets weekday strings. For example: "Sunday", "Monday", etc.

Returns:
the weekday strings. Use Calendar.SUNDAY, Calendar.MONDAY, etc. to index the result array.

setWeekdays

public void setWeekdays(String[] newWeekdays)
Sets weekday strings. For example: "Sunday", "Monday", etc.

Parameters:
newWeekdays - the new weekday strings. The array should be indexed by Calendar.SUNDAY, Calendar.MONDAY, etc.

getShortWeekdays

public String[] getShortWeekdays()
Gets short weekday strings. For example: "Sun", "Mon", etc.

Returns:
the short weekday strings. Use Calendar.SUNDAY, Calendar.MONDAY, etc. to index the result array.

setShortWeekdays

public void setShortWeekdays(String[] newShortWeekdays)
Sets short weekday strings. For example: "Sun", "Mon", etc.

Parameters:
newShortWeekdays - the new short weekday strings. The array should be indexed by Calendar.SUNDAY, Calendar.MONDAY, etc.

getAmPmStrings

public String[] getAmPmStrings()
Gets ampm strings. For example: "AM" and "PM".

Returns:
the ampm strings.

setAmPmStrings

public void setAmPmStrings(String[] newAmpms)
Sets ampm strings. For example: "AM" and "PM".

Parameters:
newAmpms - the new ampm strings.

getZoneStrings

public String[][] getZoneStrings()
Gets timezone strings.

Returns:
the timezone strings.

setZoneStrings

public void setZoneStrings(String[][] newZoneStrings)
Sets timezone strings.

Parameters:
newZoneStrings - the new timezone strings.

getLocalPatternChars

public String getLocalPatternChars()
Gets localized date-time pattern characters. For example: 'u', 't', etc.

Returns:
the localized date-time pattern characters.

setLocalPatternChars

public void setLocalPatternChars(String newLocalPatternChars)
Sets localized date-time pattern characters. For example: 'u', 't', etc.

Parameters:
newLocalPatternChars - the new localized date-time pattern characters.

clone

public Object clone()
Overrides Cloneable

Overrides:
clone in class Object
Returns:
a clone of this instance.
See Also:
Cloneable

hashCode

public int hashCode()
Override hashCode. Generates a hash code for the DateFormatSymbols object.

Overrides:
hashCode in class Object
Returns:
a hash code value for this object.
See Also:
Object.equals(java.lang.Object), Hashtable

equals

public boolean equals(Object obj)
Override equals

Overrides:
equals in class Object
Parameters:
obj - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.
See Also:
Object.hashCode(), Hashtable

cacheLookup

private ResourceBundle[] cacheLookup(Locale desiredLocale)
Look up resource data for the desiredLocale in the cache; update the cache if necessary.


loadZoneStrings

private String[][] loadZoneStrings(Locale desiredLocale,
                                   ResourceBundle rsrc)
Load time zone localized strings. Enumerate all keys (except "localPatternChars" and "zoneStrings").


initializeData

private void initializeData(Locale desiredLocale)

getZoneIndex

final int getZoneIndex(String ID)
Package private: used by SimpleDateFormat Gets the index for the given time zone ID to obtain the timezone strings for formatting. The time zone ID is just for programmatic lookup. NOT LOCALIZED!!!

Parameters:
ID - the given time zone ID.
Returns:
the index of the given time zone ID. Returns -1 if the given time zone ID can't be located in the DateFormatSymbols object.
See Also:
SimpleTimeZone

duplicate

private final String[] duplicate(String[] srcArray)
Clones an array of Strings.

Parameters:
srcArray - the source array to be cloned.
Returns:
a cloned array.

copyMembers

private final void copyMembers(DateFormatSymbols src,
                               DateFormatSymbols dst)
Clones all the data members from the source DateFormatSymbols to the target DateFormatSymbols. This is only for subclasses.

Parameters:
src - the source DateFormatSymbols.
dst - the target DateFormatSymbols.

equals

private final boolean equals(String[] current,
                             String[] other)
Compares the equality of the two arrays of String.

Parameters:
current - this String array.
other - that String array.