DateFormatSymbolspublic class DateFormatSymbols extends Object implements Serializable, CloneableDateFormatSymbols 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 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. |
Fields Summary |
---|
String[] | erasEra strings. For example: "AD" and "BC". An array of 2 strings,
indexed by Calendar.BC and Calendar.AD . | String[] | monthsMonth strings. For example: "January", "February", etc. An array
of 13 strings (some calendars have 13 months), indexed by
Calendar.JANUARY , Calendar.FEBRUARY , etc. | String[] | shortMonthsShort month strings. For example: "Jan", "Feb", etc. An array of
13 strings (some calendars have 13 months), indexed by
Calendar.JANUARY , Calendar.FEBRUARY , etc. | String[] | weekdaysWeekday strings. For example: "Sunday", "Monday", etc. An array
of 8 strings, indexed by Calendar.SUNDAY ,
Calendar.MONDAY , etc.
The element weekdays[0] is ignored. | String[] | shortWeekdaysShort 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. | String[] | ampmsAM and PM strings. For example: "AM" and "PM". An array of
2 strings, indexed by Calendar.AM and
Calendar.PM . | String[] | zoneStringsLocalized 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):
zoneStrings[i][0] - time zone ID
zoneStrings[i][1] - long name of zone in standard
time
zoneStrings[i][2] - short name of zone in
standard time
zoneStrings[i][3] - long name of zone in daylight
savings time
zoneStrings[i][4] - short name of zone in daylight
savings time
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. | static final String | patternCharsUnlocalized date-time pattern characters. For example: 'y', 'd', etc.
All locales use the same these unlocalized pattern characters. | String | localPatternCharsLocalized 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. | static final long | serialVersionUID | static final int | millisPerHourUseful constant for defining timezone offsets. | private static Hashtable | cachedLocaleDataCache to hold the LocaleElements and DateFormatZoneData ResourceBundles
of a Locale. | private static Hashtable | cachedZoneDatacache to hold time zone localized strings. Keyed by Locale |
Constructors Summary |
---|
public DateFormatSymbols()Construct a DateFormatSymbols object by loading format data from
resources for the default locale.
initializeData(Locale.getDefault());
| public DateFormatSymbols(Locale locale)Construct a DateFormatSymbols object by loading format data from
resources for the given locale.
initializeData(locale);
|
Methods Summary |
---|
private java.util.ResourceBundle[] | cacheLookup(java.util.Locale desiredLocale)Look up resource data for the desiredLocale in the cache; update the
cache if necessary.
ResourceBundle[] rbs = new ResourceBundle[2];
SoftReference[] data
= (SoftReference[])cachedLocaleData.get(desiredLocale);
if (data == null) {
rbs[0] = LocaleData.getLocaleElements(desiredLocale);
rbs[1] = LocaleData.getDateFormatZoneData(desiredLocale);
data = new SoftReference[] { new SoftReference(rbs[0]),
new SoftReference(rbs[1]) };
cachedLocaleData.put(desiredLocale, data);
} else {
ResourceBundle r;
if ((r = (ResourceBundle)data[0].get()) == null) {
r = LocaleData.getLocaleElements(desiredLocale);
data[0] = new SoftReference(r);
}
rbs[0] = r;
if ((r = (ResourceBundle)data[1].get()) == null) {
r = LocaleData.getDateFormatZoneData(desiredLocale);
data[1] = new SoftReference(r);
}
rbs[1] = r;
}
return rbs;
| public java.lang.Object | clone()Overrides Cloneable
try
{
DateFormatSymbols other = (DateFormatSymbols)super.clone();
copyMembers(this, other);
return other;
} catch (CloneNotSupportedException e) {
throw new InternalError();
}
| private final void | copyMembers(java.text.DateFormatSymbols src, java.text.DateFormatSymbols dst)Clones all the data members from the source DateFormatSymbols to
the target DateFormatSymbols. This is only for subclasses.
dst.eras = duplicate(src.eras);
dst.months = duplicate(src.months);
dst.shortMonths = duplicate(src.shortMonths);
dst.weekdays = duplicate(src.weekdays);
dst.shortWeekdays = duplicate(src.shortWeekdays);
dst.ampms = duplicate(src.ampms);
for (int i = 0; i < dst.zoneStrings.length; ++i)
dst.zoneStrings[i] = duplicate(src.zoneStrings[i]);
dst.localPatternChars = new String (src.localPatternChars);
| private final java.lang.String[] | duplicate(java.lang.String[] srcArray)Clones an array of Strings.
String[] dstArray = new String[srcArray.length];
System.arraycopy(srcArray, 0, dstArray, 0, srcArray.length);
return dstArray;
| public boolean | equals(java.lang.Object obj)Override equals
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(months, that.months)
&& Utility.arrayEquals(shortMonths, that.shortMonths)
&& Utility.arrayEquals(weekdays, that.weekdays)
&& Utility.arrayEquals(shortWeekdays, that.shortWeekdays)
&& Utility.arrayEquals(ampms, that.ampms)
&& Utility.arrayEquals(zoneStrings, that.zoneStrings)
&& Utility.arrayEquals(localPatternChars,
that.localPatternChars));
| private final boolean | equals(java.lang.String[] current, java.lang.String[] other)Compares the equality of the two arrays of String.
int count = current.length;
for (int i = 0; i < count; ++i)
if (!current[i].equals(other[i]))
return false;
return true;
| public java.lang.String[] | getAmPmStrings()Gets ampm strings. For example: "AM" and "PM".
return duplicate(ampms);
| public java.lang.String[] | getEras()Gets era strings. For example: "AD" and "BC".
return duplicate(eras);
| public java.lang.String | getLocalPatternChars()Gets localized date-time pattern characters. For example: 'u', 't', etc.
return new String(localPatternChars);
| public java.lang.String[] | getMonths()Gets month strings. For example: "January", "February", etc.
return duplicate(months);
| public java.lang.String[] | getShortMonths()Gets short month strings. For example: "Jan", "Feb", etc.
return duplicate(shortMonths);
| public java.lang.String[] | getShortWeekdays()Gets short weekday strings. For example: "Sun", "Mon", etc.
return duplicate(shortWeekdays);
| public java.lang.String[] | getWeekdays()Gets weekday strings. For example: "Sunday", "Monday", etc.
return duplicate(weekdays);
| final int | getZoneIndex(java.lang.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!!!
for (int index=0; index<zoneStrings.length; index++)
{
if (ID.equalsIgnoreCase(zoneStrings[index][0])) return index;
}
return -1;
| public java.lang.String[][] | getZoneStrings()Gets timezone strings.
String[][] aCopy = new String[zoneStrings.length][];
for (int i = 0; i < zoneStrings.length; ++i)
aCopy[i] = duplicate(zoneStrings[i]);
return aCopy;
| public int | hashCode()Override hashCode.
Generates a hash code for the DateFormatSymbols object.
int hashcode = 0;
for (int index = 0; index < this.zoneStrings[0].length; ++index)
hashcode ^= this.zoneStrings[0][index].hashCode();
return hashcode;
| private void | initializeData(java.util.Locale desiredLocale)
int i;
ResourceBundle[] rbs = cacheLookup(desiredLocale);
ResourceBundle resource = rbs[0];
ResourceBundle zoneResource = rbs[1];
// FIXME: cache only ResourceBundle. Hence every time, will do
// getObject(). This won't be necessary if the Resource itself
// is cached.
eras = (String[])resource.getObject("Eras");
months = resource.getStringArray("MonthNames");
shortMonths = resource.getStringArray("MonthAbbreviations");
String[] lWeekdays = resource.getStringArray("DayNames");
weekdays = new String[8];
weekdays[0] = ""; // 1-based
for (i=0; i<lWeekdays.length; i++)
weekdays[i+1] = lWeekdays[i];
String[] sWeekdays = resource.getStringArray("DayAbbreviations");
shortWeekdays = new String[8];
shortWeekdays[0] = ""; // 1-based
for (i=0; i<sWeekdays.length; i++)
shortWeekdays[i+1] = sWeekdays[i];
ampms = resource.getStringArray("AmPmMarkers");
zoneStrings = (String[][])loadZoneStrings(desiredLocale,
zoneResource);
localPatternChars
= (String) zoneResource.getObject("localPatternChars");
| private java.lang.String[][] | loadZoneStrings(java.util.Locale desiredLocale, java.util.ResourceBundle rsrc)Load time zone localized strings. Enumerate all keys (except
"localPatternChars" and "zoneStrings").
String[][] zones;
SoftReference data = (SoftReference)cachedZoneData.get(desiredLocale);
if (data == null || ((zones = (String[][])data.get()) == null)) {
Vector vec = new Vector();
Enumeration keys = rsrc.getKeys();
while(keys.hasMoreElements()) {
String key = (String)keys.nextElement();
if (!key.equals("localPatternChars") &&
!key.equals("zoneStrings")) {
vec.add(rsrc.getObject(key));
}
}
zones = new String[vec.size()][];
vec.toArray(zones);
data = new SoftReference(zones);
cachedZoneData.put(desiredLocale, data);
}
return zones;
| public void | setAmPmStrings(java.lang.String[] newAmpms)Sets ampm strings. For example: "AM" and "PM".
ampms = duplicate(newAmpms);
| public void | setEras(java.lang.String[] newEras)Sets era strings. For example: "AD" and "BC".
eras = duplicate(newEras);
| public void | setLocalPatternChars(java.lang.String newLocalPatternChars)Sets localized date-time pattern characters. For example: 'u', 't', etc.
localPatternChars = new String(newLocalPatternChars);
| public void | setMonths(java.lang.String[] newMonths)Sets month strings. For example: "January", "February", etc.
months = duplicate(newMonths);
| public void | setShortMonths(java.lang.String[] newShortMonths)Sets short month strings. For example: "Jan", "Feb", etc.
shortMonths = duplicate(newShortMonths);
| public void | setShortWeekdays(java.lang.String[] newShortWeekdays)Sets short weekday strings. For example: "Sun", "Mon", etc.
shortWeekdays = duplicate(newShortWeekdays);
| public void | setWeekdays(java.lang.String[] newWeekdays)Sets weekday strings. For example: "Sunday", "Monday", etc.
weekdays = duplicate(newWeekdays);
| public void | setZoneStrings(java.lang.String[][] newZoneStrings)Sets timezone strings.
String[][] aCopy = new String[newZoneStrings.length][];
for (int i = 0; i < newZoneStrings.length; ++i)
aCopy[i] = duplicate(newZoneStrings[i]);
zoneStrings = aCopy;
|
|