FileDocCategorySizeDatePackage
DateFormatSymbols.javaAPI DocAndroid 1.5 API16197Wed May 06 22:41:06 BST 2009java.text

DateFormatSymbols

public class DateFormatSymbols extends Object implements Serializable, Cloneable
Encapsulates 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. {@code DateFormat} and {@code SimpleDateFormat} both use {@code DateFormatSymbols} to encapsulate this information.

Typically you shouldn't use {@code DateFormatSymbols} directly. Rather, you are encouraged to create a date/time formatter with the {@code DateFormat} class's factory methods: {@code getTimeInstance}, {@code getDateInstance}, or {@code getDateTimeInstance}. These methods automatically create a {@code DateFormatSymbols} for the formatter so that you don't have to. After the formatter is created, you may modify its format pattern using the {@code setPattern} method. For more information about creating formatters using {@code 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)).

{@code DateFormatSymbols} objects can be cloned. When you obtain a {@code 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 {@code DateFormatSymbols} subclasses may be added to support {@code SimpleDateFormat} for date/time formatting for additional locales.

see
DateFormat
see
SimpleDateFormat
since
Android 1.0

Fields Summary
private static final long
serialVersionUID
private String
localPatternChars
String[]
ampms
String[]
eras
String[]
months
String[]
shortMonths
String[]
shortWeekdays
String[]
weekdays
String[]
zoneStrings
final transient Locale
locale
Locale, necessary to lazily load time zone strings. We force the time zone names to load upon serialization, so this will never be needed post deserialization.
Constructors Summary
public DateFormatSymbols()
Constructs a new {@code DateFormatSymbols} instance containing the symbols for the default locale.

since
Android 1.0

        this(Locale.getDefault());
    
public DateFormatSymbols(Locale locale)
Constructs a new {@code DateFormatSymbols} instance containing the symbols for the specified locale.

param
locale the locale.
since
Android 1.0

        ResourceBundle bundle = Format.getBundle(locale);
        localPatternChars = bundle.getString("LocalPatternChars"); //$NON-NLS-1$
        ampms = bundle.getStringArray("ampm"); //$NON-NLS-1$
        eras = bundle.getStringArray("eras"); //$NON-NLS-1$
        months = bundle.getStringArray("months"); //$NON-NLS-1$
        shortMonths = bundle.getStringArray("shortMonths"); //$NON-NLS-1$
        shortWeekdays = bundle.getStringArray("shortWeekdays"); //$NON-NLS-1$
        weekdays = bundle.getStringArray("weekdays"); //$NON-NLS-1$
        // BEGIN android-changed
        // zoneStrings = (String[][]) bundle.getObject("timezones"); //$NON-NLS-1$
        this.locale = locale;
        // END android-changed
    
Methods Summary
public java.lang.Objectclone()

        // BEGIN android-changed
        try {
            return super.clone();
        } catch (CloneNotSupportedException e) {
            throw new AssertionError();
        }
        // END android-changed
    
public booleanequals(java.lang.Object object)
Compares this object with the specified object and indicates if they are equal.

param
object the object to compare with this object.
return
{@code true} if {@code object} is an instance of {@code DateFormatSymbols} and has the same symbols as this object, {@code false} otherwise.
see
#hashCode
since
Android 1.0

        if (this == object) {
            return true;
        }
        if (!(object instanceof DateFormatSymbols)) {
            return false;
        }
        DateFormatSymbols obj = (DateFormatSymbols) object;
        if (!localPatternChars.equals(obj.localPatternChars)) {
            return false;
        }
        if (!Arrays.equals(ampms, obj.ampms)) {
            return false;
        }
        if (!Arrays.equals(eras, obj.eras)) {
            return false;
        }
        if (!Arrays.equals(months, obj.months)) {
            return false;
        }
        if (!Arrays.equals(shortMonths, obj.shortMonths)) {
            return false;
        }
        if (!Arrays.equals(shortWeekdays, obj.shortWeekdays)) {
            return false;
        }
        if (!Arrays.equals(weekdays, obj.weekdays)) {
            return false;
        }
        // BEGIN android-changed
        // Quick check that may keep us from having to load the zone strings.
        if (zoneStrings == null && obj.zoneStrings == null
                    && !locale.equals(obj.locale)) {
            return false;
        }
        // Make sure zone strings are loaded.
        internalZoneStrings();
        obj.internalZoneStrings();
        // END android-changed
        if (zoneStrings.length != obj.zoneStrings.length) {
            return false;
        }
        for (String[] element : zoneStrings) {
            if (element.length != element.length) {
                return false;
            }
            for (int j = 0; j < element.length; j++) {
                if (element[j] != element[j]
                        && !(element[j].equals(element[j]))) {
                    return false;
                }
            }
        }
        return true;
    
public java.lang.String[]getAmPmStrings()
Returns the array of strings which represent AM and PM. Use the {@link java.util.Calendar} constants {@code Calendar.AM} and {@code Calendar.PM} as indices for the array.

return
an array of strings.
since
Android 1.0

        return ampms.clone();
    
public java.lang.String[]getEras()
Returns the array of strings which represent BC and AD. Use the {@link java.util.Calendar} constants {@code GregorianCalendar.BC} and {@code GregorianCalendar.AD} as indices for the array.

return
an array of strings.
since
Android 1.0

        return eras.clone();
    
public java.lang.StringgetLocalPatternChars()
Returns the pattern characters used by {@link SimpleDateFormat} to specify date and time fields.

return
a string containing the pattern characters.
since
Android 1.0

        return localPatternChars;
    
public java.lang.String[]getMonths()
Returns the array of strings containing the full names of the months. Use the {@link java.util.Calendar} constants {@code Calendar.JANUARY} etc. as indices for the array.

return
an array of strings.
since
Android 1.0

        return months.clone();
    
public java.lang.String[]getShortMonths()
Returns the array of strings containing the abbreviated names of the months. Use the {@link java.util.Calendar} constants {@code Calendar.JANUARY} etc. as indices for the array.

return
an array of strings.
since
Android 1.0

        return shortMonths.clone();
    
public java.lang.String[]getShortWeekdays()
Returns the array of strings containing the abbreviated names of the days of the week. Use the {@link java.util.Calendar} constants {@code Calendar.SUNDAY} etc. as indices for the array.

return
an array of strings.
since
Android 1.0

        return shortWeekdays.clone();
    
public java.lang.String[]getWeekdays()
Returns the array of strings containing the full names of the days of the week. Use the {@link java.util.Calendar} constants {@code Calendar.SUNDAY} etc. as indices for the array.

return
an array of strings.
since
Android 1.0

        return weekdays.clone();
    
public java.lang.String[][]getZoneStrings()
Returns the two-dimensional array of strings containing the names of the time zones. Each element in the array is an array of five strings, the first is a TimeZone ID, the second and third are the full and abbreviated time zone names for standard time, and the fourth and fifth are the full and abbreviated names for daylight time.

return
a two-dimensional array of strings.
since
Android 1.0

        // BEGIN android-added
        String[][] zoneStrings = internalZoneStrings();
        // END android-added
        String[][] clone = new String[zoneStrings.length][];
        for (int i = zoneStrings.length; --i >= 0;) {
            clone[i] = zoneStrings[i].clone();
        }
        return clone;
    
public inthashCode()

        int hashCode;
        hashCode = localPatternChars.hashCode();
        for (String element : ampms) {
            hashCode += element.hashCode();
        }
        for (String element : eras) {
            hashCode += element.hashCode();
        }
        for (String element : months) {
            hashCode += element.hashCode();
        }
        for (String element : shortMonths) {
            hashCode += element.hashCode();
        }
        for (String element : shortWeekdays) {
            hashCode += element.hashCode();
        }
        for (String element : weekdays) {
            hashCode += element.hashCode();
        }
        // BEGIN android-added
        String[][] zoneStrings = internalZoneStrings();
        // END android-added
        for (String[] element : zoneStrings) {
            for (int j = 0; j < element.length; j++) {
                hashCode += element[j].hashCode();
            }
        }
        return hashCode;
    
synchronized java.lang.String[][]internalZoneStrings()
Gets zone strings, initializing them if necessary. Does not create a defensive copy, so make sure you do so before exposing the returned arrays to clients.


                                   
       
        if (zoneStrings == null) {
            zoneStrings = Resources.getDisplayTimeZones(locale.toString());
        }
        return zoneStrings;       
    
public voidsetAmPmStrings(java.lang.String[] data)
Sets the array of strings which represent AM and PM. Use the {@link java.util.Calendar} constants {@code Calendar.AM} and {@code Calendar.PM} as indices for the array.

param
data the array of strings for AM and PM.
since
Android 1.0

        ampms = data.clone();
    
public voidsetEras(java.lang.String[] data)
Sets the array of Strings which represent BC and AD. Use the {@link java.util.Calendar} constants {@code GregorianCalendar.BC} and {@code GregorianCalendar.AD} as indices for the array.

param
data the array of strings for BC and AD.
since
Android 1.0

        eras = data.clone();
    
public voidsetLocalPatternChars(java.lang.String data)
Sets the pattern characters used by {@link SimpleDateFormat} to specify date and time fields.

param
data the string containing the pattern characters.
since
Android 1.0

        if (data == null) {
            throw new NullPointerException();
        }
        localPatternChars = data;
    
public voidsetMonths(java.lang.String[] data)
Sets the array of strings containing the full names of the months. Use the {@link java.util.Calendar} constants {@code Calendar.JANUARY} etc. as indices for the array.

param
data the array of strings.
since
Android 1.0

        months = data.clone();
    
public voidsetShortMonths(java.lang.String[] data)
Sets the array of strings containing the abbreviated names of the months. Use the {@link java.util.Calendar} constants {@code Calendar.JANUARY} etc. as indices for the array.

param
data the array of strings.
since
Android 1.0

        shortMonths = data.clone();
    
public voidsetShortWeekdays(java.lang.String[] data)
Sets the array of strings containing the abbreviated names of the days of the week. Use the {@link java.util.Calendar} constants {@code Calendar.SUNDAY} etc. as indices for the array.

param
data the array of strings.
since
Android 1.0

        shortWeekdays = data.clone();
    
public voidsetWeekdays(java.lang.String[] data)
Sets the array of strings containing the full names of the days of the week. Use the {@link java.util.Calendar} constants {@code Calendar.SUNDAY} etc. as indices for the array.

param
data the array of strings.
since
Android 1.0

        weekdays = data.clone();
    
public voidsetZoneStrings(java.lang.String[][] data)
Sets the two-dimensional array of strings containing the names of the time zones. Each element in the array is an array of five strings, the first is a TimeZone ID, and second and third are the full and abbreviated time zone names for standard time, and the fourth and fifth are the full and abbreviated names for daylight time.

param
data the two-dimensional array of strings.
since
Android 1.0

        zoneStrings = data.clone();
    
private voidwriteObject(java.io.ObjectOutputStream out)

        // Ensure internal zone strings are initialized to ensure backward
        // compatibility.
        internalZoneStrings();

        out.defaultWriteObject();