0N/A/*
2702N/A * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/A/*
0N/A * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved
0N/A * (C) Copyright IBM Corp. 1996 - All Rights Reserved
0N/A *
0N/A * The original version of this source code and documentation is copyrighted
0N/A * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
0N/A * materials are provided under terms of a License Agreement between Taligent
0N/A * and Sun. This technology is protected by multiple US and International
0N/A * patents. This notice and attribution to Taligent may not be removed.
0N/A * Taligent is a registered trademark of Taligent, Inc.
0N/A *
0N/A */
0N/A
0N/Apackage java.text;
0N/A
0N/Aimport java.io.IOException;
0N/Aimport java.io.ObjectOutputStream;
0N/Aimport java.io.Serializable;
0N/Aimport java.lang.ref.SoftReference;
0N/Aimport java.text.spi.DateFormatSymbolsProvider;
0N/Aimport java.util.Arrays;
0N/Aimport java.util.List;
0N/Aimport java.util.Locale;
0N/Aimport java.util.ResourceBundle;
0N/Aimport java.util.TimeZone;
2962N/Aimport java.util.concurrent.ConcurrentHashMap;
2962N/Aimport java.util.concurrent.ConcurrentMap;
0N/Aimport java.util.spi.LocaleServiceProvider;
0N/Aimport sun.util.LocaleServiceProviderPool;
0N/Aimport sun.util.TimeZoneNameUtility;
0N/Aimport sun.util.calendar.ZoneInfo;
0N/Aimport sun.util.resources.LocaleData;
0N/A
0N/A/**
0N/A * <code>DateFormatSymbols</code> is a public class for encapsulating
0N/A * localizable date-time formatting data, such as the names of the
0N/A * months, the names of the days of the week, and the time zone data.
0N/A * <code>DateFormat</code> and <code>SimpleDateFormat</code> both use
0N/A * <code>DateFormatSymbols</code> to encapsulate this information.
0N/A *
0N/A * <p>
0N/A * Typically you shouldn't use <code>DateFormatSymbols</code> directly.
0N/A * Rather, you are encouraged to create a date-time formatter with the
0N/A * <code>DateFormat</code> class's factory methods: <code>getTimeInstance</code>,
0N/A * <code>getDateInstance</code>, or <code>getDateTimeInstance</code>.
0N/A * These methods automatically create a <code>DateFormatSymbols</code> for
0N/A * the formatter so that you don't have to. After the
0N/A * formatter is created, you may modify its format pattern using the
0N/A * <code>setPattern</code> method. For more information about
0N/A * creating formatters using <code>DateFormat</code>'s factory methods,
0N/A * see {@link DateFormat}.
0N/A *
0N/A * <p>
0N/A * If you decide to create a date-time formatter with a specific
0N/A * format pattern for a specific locale, you can do so with:
0N/A * <blockquote>
0N/A * <pre>
0N/A * new SimpleDateFormat(aPattern, DateFormatSymbols.getInstance(aLocale)).
0N/A * </pre>
0N/A * </blockquote>
0N/A *
0N/A * <p>
0N/A * <code>DateFormatSymbols</code> objects are cloneable. When you obtain
0N/A * a <code>DateFormatSymbols</code> object, feel free to modify the
0N/A * date-time formatting data. For instance, you can replace the localized
0N/A * date-time format pattern characters with the ones that you feel easy
0N/A * to remember. Or you can change the representative cities
0N/A * to your favorite ones.
0N/A *
0N/A * <p>
0N/A * New <code>DateFormatSymbols</code> subclasses may be added to support
0N/A * <code>SimpleDateFormat</code> for date-time formatting for additional locales.
0N/A
0N/A * @see DateFormat
0N/A * @see SimpleDateFormat
0N/A * @see java.util.SimpleTimeZone
0N/A * @author Chen-Lieh Huang
0N/A */
0N/Apublic class DateFormatSymbols implements Serializable, Cloneable {
0N/A
0N/A /**
0N/A * Construct a DateFormatSymbols object by loading format data from
0N/A * resources for the default locale. This constructor can only
0N/A * construct instances for the locales supported by the Java
0N/A * runtime environment, not for those supported by installed
0N/A * {@link java.text.spi.DateFormatSymbolsProvider DateFormatSymbolsProvider}
0N/A * implementations. For full locale coverage, use the
0N/A * {@link #getInstance(Locale) getInstance} method.
0N/A *
0N/A * @see #getInstance()
0N/A * @exception java.util.MissingResourceException
0N/A * if the resources for the default locale cannot be
0N/A * found or cannot be loaded.
0N/A */
0N/A public DateFormatSymbols()
0N/A {
2700N/A initializeData(Locale.getDefault(Locale.Category.FORMAT));
0N/A }
0N/A
0N/A /**
0N/A * Construct a DateFormatSymbols object by loading format data from
0N/A * resources for the given locale. This constructor can only
0N/A * construct instances for the locales supported by the Java
0N/A * runtime environment, not for those supported by installed
0N/A * {@link java.text.spi.DateFormatSymbolsProvider DateFormatSymbolsProvider}
0N/A * implementations. For full locale coverage, use the
0N/A * {@link #getInstance(Locale) getInstance} method.
0N/A *
0N/A * @see #getInstance(Locale)
0N/A * @exception java.util.MissingResourceException
0N/A * if the resources for the specified locale cannot be
0N/A * found or cannot be loaded.
0N/A */
0N/A public DateFormatSymbols(Locale locale)
0N/A {
0N/A initializeData(locale);
0N/A }
0N/A
0N/A /**
0N/A * Era strings. For example: "AD" and "BC". An array of 2 strings,
0N/A * indexed by <code>Calendar.BC</code> and <code>Calendar.AD</code>.
0N/A * @serial
0N/A */
0N/A String eras[] = null;
0N/A
0N/A /**
0N/A * Month strings. For example: "January", "February", etc. An array
0N/A * of 13 strings (some calendars have 13 months), indexed by
0N/A * <code>Calendar.JANUARY</code>, <code>Calendar.FEBRUARY</code>, etc.
0N/A * @serial
0N/A */
0N/A String months[] = null;
0N/A
0N/A /**
0N/A * Short month strings. For example: "Jan", "Feb", etc. An array of
0N/A * 13 strings (some calendars have 13 months), indexed by
0N/A * <code>Calendar.JANUARY</code>, <code>Calendar.FEBRUARY</code>, etc.
0N/A
0N/A * @serial
0N/A */
0N/A String shortMonths[] = null;
0N/A
0N/A /**
0N/A * Weekday strings. For example: "Sunday", "Monday", etc. An array
0N/A * of 8 strings, indexed by <code>Calendar.SUNDAY</code>,
0N/A * <code>Calendar.MONDAY</code>, etc.
0N/A * The element <code>weekdays[0]</code> is ignored.
0N/A * @serial
0N/A */
0N/A String weekdays[] = null;
0N/A
0N/A /**
0N/A * Short weekday strings. For example: "Sun", "Mon", etc. An array
0N/A * of 8 strings, indexed by <code>Calendar.SUNDAY</code>,
0N/A * <code>Calendar.MONDAY</code>, etc.
0N/A * The element <code>shortWeekdays[0]</code> is ignored.
0N/A * @serial
0N/A */
0N/A String shortWeekdays[] = null;
0N/A
0N/A /**
0N/A * AM and PM strings. For example: "AM" and "PM". An array of
0N/A * 2 strings, indexed by <code>Calendar.AM</code> and
0N/A * <code>Calendar.PM</code>.
0N/A * @serial
0N/A */
0N/A String ampms[] = null;
0N/A
0N/A /**
0N/A * Localized names of time zones in this locale. This is a
0N/A * two-dimensional array of strings of size <em>n</em> by <em>m</em>,
0N/A * where <em>m</em> is at least 5. Each of the <em>n</em> rows is an
0N/A * entry containing the localized names for a single <code>TimeZone</code>.
0N/A * Each such row contains (with <code>i</code> ranging from
0N/A * 0..<em>n</em>-1):
0N/A * <ul>
0N/A * <li><code>zoneStrings[i][0]</code> - time zone ID</li>
0N/A * <li><code>zoneStrings[i][1]</code> - long name of zone in standard
0N/A * time</li>
0N/A * <li><code>zoneStrings[i][2]</code> - short name of zone in
0N/A * standard time</li>
0N/A * <li><code>zoneStrings[i][3]</code> - long name of zone in daylight
0N/A * saving time</li>
0N/A * <li><code>zoneStrings[i][4]</code> - short name of zone in daylight
0N/A * saving time</li>
0N/A * </ul>
0N/A * The zone ID is <em>not</em> localized; it's one of the valid IDs of
0N/A * the {@link java.util.TimeZone TimeZone} class that are not
0N/A * <a href="../java/util/TimeZone.html#CustomID">custom IDs</a>.
0N/A * All other entries are localized names.
0N/A * @see java.util.TimeZone
0N/A * @serial
0N/A */
0N/A String zoneStrings[][] = null;
0N/A
0N/A /**
0N/A * Indicates that zoneStrings is set externally with setZoneStrings() method.
0N/A */
0N/A transient boolean isZoneStringsSet = false;
0N/A
0N/A /**
0N/A * Unlocalized date-time pattern characters. For example: 'y', 'd', etc.
0N/A * All locales use the same these unlocalized pattern characters.
0N/A */
2708N/A static final String patternChars = "GyMdkHmsSEDFwWahKzZYuX";
2702N/A
2702N/A static final int PATTERN_ERA = 0; // G
2702N/A static final int PATTERN_YEAR = 1; // y
2702N/A static final int PATTERN_MONTH = 2; // M
2702N/A static final int PATTERN_DAY_OF_MONTH = 3; // d
2702N/A static final int PATTERN_HOUR_OF_DAY1 = 4; // k
2702N/A static final int PATTERN_HOUR_OF_DAY0 = 5; // H
2702N/A static final int PATTERN_MINUTE = 6; // m
2702N/A static final int PATTERN_SECOND = 7; // s
2702N/A static final int PATTERN_MILLISECOND = 8; // S
2702N/A static final int PATTERN_DAY_OF_WEEK = 9; // E
2702N/A static final int PATTERN_DAY_OF_YEAR = 10; // D
2702N/A static final int PATTERN_DAY_OF_WEEK_IN_MONTH = 11; // F
2702N/A static final int PATTERN_WEEK_OF_YEAR = 12; // w
2702N/A static final int PATTERN_WEEK_OF_MONTH = 13; // W
2702N/A static final int PATTERN_AM_PM = 14; // a
2702N/A static final int PATTERN_HOUR1 = 15; // h
2702N/A static final int PATTERN_HOUR0 = 16; // K
2702N/A static final int PATTERN_ZONE_NAME = 17; // z
2702N/A static final int PATTERN_ZONE_VALUE = 18; // Z
2702N/A static final int PATTERN_WEEK_YEAR = 19; // Y
2702N/A static final int PATTERN_ISO_DAY_OF_WEEK = 20; // u
2708N/A static final int PATTERN_ISO_ZONE = 21; // X
0N/A
0N/A /**
0N/A * Localized date-time pattern characters. For example, a locale may
0N/A * wish to use 'u' rather than 'y' to represent years in its date format
0N/A * pattern strings.
0N/A * This string must be exactly 18 characters long, with the index of
0N/A * the characters described by <code>DateFormat.ERA_FIELD</code>,
0N/A * <code>DateFormat.YEAR_FIELD</code>, etc. Thus, if the string were
0N/A * "Xz...", then localized patterns would use 'X' for era and 'z' for year.
0N/A * @serial
0N/A */
0N/A String localPatternChars = null;
0N/A
0N/A /**
0N/A * The locale which is used for initializing this DateFormatSymbols object.
0N/A *
0N/A * @since 1.6
0N/A * @serial
0N/A */
0N/A Locale locale = null;
0N/A
0N/A /* use serialVersionUID from JDK 1.1.4 for interoperability */
0N/A static final long serialVersionUID = -5987973545549424702L;
0N/A
0N/A /**
0N/A * Returns an array of all locales for which the
0N/A * <code>getInstance</code> methods of this class can return
0N/A * localized instances.
0N/A * The returned array represents the union of locales supported by the
0N/A * Java runtime and by installed
0N/A * {@link java.text.spi.DateFormatSymbolsProvider DateFormatSymbolsProvider}
0N/A * implementations. It must contain at least a <code>Locale</code>
0N/A * instance equal to {@link java.util.Locale#US Locale.US}.
0N/A *
0N/A * @return An array of locales for which localized
0N/A * <code>DateFormatSymbols</code> instances are available.
0N/A * @since 1.6
0N/A */
0N/A public static Locale[] getAvailableLocales() {
0N/A LocaleServiceProviderPool pool=
0N/A LocaleServiceProviderPool.getPool(DateFormatSymbolsProvider.class);
0N/A return pool.getAvailableLocales();
0N/A }
0N/A
0N/A /**
0N/A * Gets the <code>DateFormatSymbols</code> instance for the default
0N/A * locale. This method provides access to <code>DateFormatSymbols</code>
0N/A * instances for locales supported by the Java runtime itself as well
0N/A * as for those supported by installed
0N/A * {@link java.text.spi.DateFormatSymbolsProvider DateFormatSymbolsProvider}
0N/A * implementations.
0N/A * @return a <code>DateFormatSymbols</code> instance.
0N/A * @since 1.6
0N/A */
0N/A public static final DateFormatSymbols getInstance() {
2700N/A return getInstance(Locale.getDefault(Locale.Category.FORMAT));
0N/A }
0N/A
0N/A /**
0N/A * Gets the <code>DateFormatSymbols</code> instance for the specified
0N/A * locale. This method provides access to <code>DateFormatSymbols</code>
0N/A * instances for locales supported by the Java runtime itself as well
0N/A * as for those supported by installed
0N/A * {@link java.text.spi.DateFormatSymbolsProvider DateFormatSymbolsProvider}
0N/A * implementations.
0N/A * @param locale the given locale.
0N/A * @return a <code>DateFormatSymbols</code> instance.
0N/A * @exception NullPointerException if <code>locale</code> is null
0N/A * @since 1.6
0N/A */
0N/A public static final DateFormatSymbols getInstance(Locale locale) {
2962N/A DateFormatSymbols dfs = getProviderInstance(locale);
2962N/A if (dfs != null) {
2962N/A return dfs;
2962N/A }
2962N/A return (DateFormatSymbols) getCachedInstance(locale).clone();
2962N/A }
2962N/A
2962N/A /**
2962N/A * Returns a DateFormatSymbols provided by a provider or found in
2962N/A * the cache. Note that this method returns a cached instance,
2962N/A * not its clone. Therefore, the instance should never be given to
2962N/A * an application.
2962N/A */
2962N/A static final DateFormatSymbols getInstanceRef(Locale locale) {
2962N/A DateFormatSymbols dfs = getProviderInstance(locale);
2962N/A if (dfs != null) {
2962N/A return dfs;
2962N/A }
2962N/A return getCachedInstance(locale);
2962N/A }
2962N/A
2962N/A private static DateFormatSymbols getProviderInstance(Locale locale) {
2962N/A DateFormatSymbols providersInstance = null;
0N/A
0N/A // Check whether a provider can provide an implementation that's closer
0N/A // to the requested locale than what the Java runtime itself can provide.
0N/A LocaleServiceProviderPool pool =
0N/A LocaleServiceProviderPool.getPool(DateFormatSymbolsProvider.class);
0N/A if (pool.hasProviders()) {
2962N/A providersInstance = pool.getLocalizedObject(
2962N/A DateFormatSymbolsGetter.INSTANCE, locale);
2962N/A }
2962N/A return providersInstance;
2962N/A }
2962N/A
2962N/A /**
2962N/A * Returns a cached DateFormatSymbols if it's found in the
2962N/A * cache. Otherwise, this method returns a newly cached instance
2962N/A * for the given locale.
2962N/A */
2962N/A private static DateFormatSymbols getCachedInstance(Locale locale) {
2962N/A SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale);
2962N/A DateFormatSymbols dfs = null;
2962N/A if (ref == null || (dfs = ref.get()) == null) {
2962N/A dfs = new DateFormatSymbols(locale);
2962N/A ref = new SoftReference<DateFormatSymbols>(dfs);
2962N/A SoftReference<DateFormatSymbols> x = cachedInstances.putIfAbsent(locale, ref);
2962N/A if (x != null) {
2962N/A DateFormatSymbols y = x.get();
2962N/A if (y != null) {
2962N/A dfs = y;
2962N/A } else {
2962N/A // Replace the empty SoftReference with ref.
2962N/A cachedInstances.put(locale, ref);
2962N/A }
0N/A }
0N/A }
2962N/A return dfs;
0N/A }
0N/A
0N/A /**
0N/A * Gets era strings. For example: "AD" and "BC".
0N/A * @return the era strings.
0N/A */
0N/A public String[] getEras() {
0N/A return Arrays.copyOf(eras, eras.length);
0N/A }
0N/A
0N/A /**
0N/A * Sets era strings. For example: "AD" and "BC".
0N/A * @param newEras the new era strings.
0N/A */
0N/A public void setEras(String[] newEras) {
0N/A eras = Arrays.copyOf(newEras, newEras.length);
0N/A }
0N/A
0N/A /**
0N/A * Gets month strings. For example: "January", "February", etc.
0N/A * @return the month strings.
0N/A */
0N/A public String[] getMonths() {
0N/A return Arrays.copyOf(months, months.length);
0N/A }
0N/A
0N/A /**
0N/A * Sets month strings. For example: "January", "February", etc.
0N/A * @param newMonths the new month strings.
0N/A */
0N/A public void setMonths(String[] newMonths) {
0N/A months = Arrays.copyOf(newMonths, newMonths.length);
0N/A }
0N/A
0N/A /**
0N/A * Gets short month strings. For example: "Jan", "Feb", etc.
0N/A * @return the short month strings.
0N/A */
0N/A public String[] getShortMonths() {
0N/A return Arrays.copyOf(shortMonths, shortMonths.length);
0N/A }
0N/A
0N/A /**
0N/A * Sets short month strings. For example: "Jan", "Feb", etc.
0N/A * @param newShortMonths the new short month strings.
0N/A */
0N/A public void setShortMonths(String[] newShortMonths) {
0N/A shortMonths = Arrays.copyOf(newShortMonths, newShortMonths.length);
0N/A }
0N/A
0N/A /**
0N/A * Gets weekday strings. For example: "Sunday", "Monday", etc.
0N/A * @return the weekday strings. Use <code>Calendar.SUNDAY</code>,
0N/A * <code>Calendar.MONDAY</code>, etc. to index the result array.
0N/A */
0N/A public String[] getWeekdays() {
0N/A return Arrays.copyOf(weekdays, weekdays.length);
0N/A }
0N/A
0N/A /**
0N/A * Sets weekday strings. For example: "Sunday", "Monday", etc.
0N/A * @param newWeekdays the new weekday strings. The array should
0N/A * be indexed by <code>Calendar.SUNDAY</code>,
0N/A * <code>Calendar.MONDAY</code>, etc.
0N/A */
0N/A public void setWeekdays(String[] newWeekdays) {
0N/A weekdays = Arrays.copyOf(newWeekdays, newWeekdays.length);
0N/A }
0N/A
0N/A /**
0N/A * Gets short weekday strings. For example: "Sun", "Mon", etc.
0N/A * @return the short weekday strings. Use <code>Calendar.SUNDAY</code>,
0N/A * <code>Calendar.MONDAY</code>, etc. to index the result array.
0N/A */
0N/A public String[] getShortWeekdays() {
0N/A return Arrays.copyOf(shortWeekdays, shortWeekdays.length);
0N/A }
0N/A
0N/A /**
0N/A * Sets short weekday strings. For example: "Sun", "Mon", etc.
0N/A * @param newShortWeekdays the new short weekday strings. The array should
0N/A * be indexed by <code>Calendar.SUNDAY</code>,
0N/A * <code>Calendar.MONDAY</code>, etc.
0N/A */
0N/A public void setShortWeekdays(String[] newShortWeekdays) {
0N/A shortWeekdays = Arrays.copyOf(newShortWeekdays, newShortWeekdays.length);
0N/A }
0N/A
0N/A /**
0N/A * Gets ampm strings. For example: "AM" and "PM".
0N/A * @return the ampm strings.
0N/A */
0N/A public String[] getAmPmStrings() {
0N/A return Arrays.copyOf(ampms, ampms.length);
0N/A }
0N/A
0N/A /**
0N/A * Sets ampm strings. For example: "AM" and "PM".
0N/A * @param newAmpms the new ampm strings.
0N/A */
0N/A public void setAmPmStrings(String[] newAmpms) {
0N/A ampms = Arrays.copyOf(newAmpms, newAmpms.length);
0N/A }
0N/A
0N/A /**
0N/A * Gets time zone strings. Use of this method is discouraged; use
0N/A * {@link java.util.TimeZone#getDisplayName() TimeZone.getDisplayName()}
0N/A * instead.
0N/A * <p>
0N/A * The value returned is a
0N/A * two-dimensional array of strings of size <em>n</em> by <em>m</em>,
0N/A * where <em>m</em> is at least 5. Each of the <em>n</em> rows is an
0N/A * entry containing the localized names for a single <code>TimeZone</code>.
0N/A * Each such row contains (with <code>i</code> ranging from
0N/A * 0..<em>n</em>-1):
0N/A * <ul>
0N/A * <li><code>zoneStrings[i][0]</code> - time zone ID</li>
0N/A * <li><code>zoneStrings[i][1]</code> - long name of zone in standard
0N/A * time</li>
0N/A * <li><code>zoneStrings[i][2]</code> - short name of zone in
0N/A * standard time</li>
0N/A * <li><code>zoneStrings[i][3]</code> - long name of zone in daylight
0N/A * saving time</li>
0N/A * <li><code>zoneStrings[i][4]</code> - short name of zone in daylight
0N/A * saving time</li>
0N/A * </ul>
0N/A * The zone ID is <em>not</em> localized; it's one of the valid IDs of
0N/A * the {@link java.util.TimeZone TimeZone} class that are not
0N/A * <a href="../util/TimeZone.html#CustomID">custom IDs</a>.
0N/A * All other entries are localized names. If a zone does not implement
0N/A * daylight saving time, the daylight saving time names should not be used.
0N/A * <p>
0N/A * If {@link #setZoneStrings(String[][]) setZoneStrings} has been called
0N/A * on this <code>DateFormatSymbols</code> instance, then the strings
0N/A * provided by that call are returned. Otherwise, the returned array
0N/A * contains names provided by the Java runtime and by installed
0N/A * {@link java.util.spi.TimeZoneNameProvider TimeZoneNameProvider}
0N/A * implementations.
0N/A *
0N/A * @return the time zone strings.
0N/A * @see #setZoneStrings(String[][])
0N/A */
0N/A public String[][] getZoneStrings() {
0N/A return getZoneStringsImpl(true);
0N/A }
0N/A
0N/A /**
0N/A * Sets time zone strings. The argument must be a
0N/A * two-dimensional array of strings of size <em>n</em> by <em>m</em>,
0N/A * where <em>m</em> is at least 5. Each of the <em>n</em> rows is an
0N/A * entry containing the localized names for a single <code>TimeZone</code>.
0N/A * Each such row contains (with <code>i</code> ranging from
0N/A * 0..<em>n</em>-1):
0N/A * <ul>
0N/A * <li><code>zoneStrings[i][0]</code> - time zone ID</li>
0N/A * <li><code>zoneStrings[i][1]</code> - long name of zone in standard
0N/A * time</li>
0N/A * <li><code>zoneStrings[i][2]</code> - short name of zone in
0N/A * standard time</li>
0N/A * <li><code>zoneStrings[i][3]</code> - long name of zone in daylight
0N/A * saving time</li>
0N/A * <li><code>zoneStrings[i][4]</code> - short name of zone in daylight
0N/A * saving time</li>
0N/A * </ul>
0N/A * The zone ID is <em>not</em> localized; it's one of the valid IDs of
0N/A * the {@link java.util.TimeZone TimeZone} class that are not
0N/A * <a href="../util/TimeZone.html#CustomID">custom IDs</a>.
0N/A * All other entries are localized names.
0N/A *
0N/A * @param newZoneStrings the new time zone strings.
0N/A * @exception IllegalArgumentException if the length of any row in
0N/A * <code>newZoneStrings</code> is less than 5
0N/A * @exception NullPointerException if <code>newZoneStrings</code> is null
0N/A * @see #getZoneStrings()
0N/A */
0N/A public void setZoneStrings(String[][] newZoneStrings) {
0N/A String[][] aCopy = new String[newZoneStrings.length][];
0N/A for (int i = 0; i < newZoneStrings.length; ++i) {
0N/A int len = newZoneStrings[i].length;
0N/A if (len < 5) {
0N/A throw new IllegalArgumentException();
0N/A }
0N/A aCopy[i] = Arrays.copyOf(newZoneStrings[i], len);
0N/A }
0N/A zoneStrings = aCopy;
0N/A isZoneStringsSet = true;
0N/A }
0N/A
0N/A /**
0N/A * Gets localized date-time pattern characters. For example: 'u', 't', etc.
0N/A * @return the localized date-time pattern characters.
0N/A */
0N/A public String getLocalPatternChars() {
2702N/A return localPatternChars;
0N/A }
0N/A
0N/A /**
0N/A * Sets localized date-time pattern characters. For example: 'u', 't', etc.
0N/A * @param newLocalPatternChars the new localized date-time
0N/A * pattern characters.
0N/A */
0N/A public void setLocalPatternChars(String newLocalPatternChars) {
2702N/A // Call toString() to throw an NPE in case the argument is null
2702N/A localPatternChars = newLocalPatternChars.toString();
0N/A }
0N/A
0N/A /**
0N/A * Overrides Cloneable
0N/A */
0N/A public Object clone()
0N/A {
0N/A try
0N/A {
0N/A DateFormatSymbols other = (DateFormatSymbols)super.clone();
0N/A copyMembers(this, other);
0N/A return other;
0N/A } catch (CloneNotSupportedException e) {
0N/A throw new InternalError();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Override hashCode.
0N/A * Generates a hash code for the DateFormatSymbols object.
0N/A */
0N/A public int hashCode() {
0N/A int hashcode = 0;
0N/A String[][] zoneStrings = getZoneStringsWrapper();
0N/A for (int index = 0; index < zoneStrings[0].length; ++index)
0N/A hashcode ^= zoneStrings[0][index].hashCode();
0N/A return hashcode;
0N/A }
0N/A
0N/A /**
0N/A * Override equals
0N/A */
0N/A public boolean equals(Object obj)
0N/A {
0N/A if (this == obj) return true;
0N/A if (obj == null || getClass() != obj.getClass()) return false;
0N/A DateFormatSymbols that = (DateFormatSymbols) obj;
0N/A return (Arrays.equals(eras, that.eras)
0N/A && Arrays.equals(months, that.months)
0N/A && Arrays.equals(shortMonths, that.shortMonths)
0N/A && Arrays.equals(weekdays, that.weekdays)
0N/A && Arrays.equals(shortWeekdays, that.shortWeekdays)
0N/A && Arrays.equals(ampms, that.ampms)
0N/A && Arrays.deepEquals(getZoneStringsWrapper(), that.getZoneStringsWrapper())
0N/A && ((localPatternChars != null
0N/A && localPatternChars.equals(that.localPatternChars))
0N/A || (localPatternChars == null
0N/A && that.localPatternChars == null)));
0N/A }
0N/A
0N/A // =======================privates===============================
0N/A
0N/A /**
0N/A * Useful constant for defining time zone offsets.
0N/A */
0N/A static final int millisPerHour = 60*60*1000;
0N/A
0N/A /**
2962N/A * Cache to hold DateFormatSymbols instances per Locale.
0N/A */
2962N/A private static final ConcurrentMap<Locale, SoftReference<DateFormatSymbols>> cachedInstances
2962N/A = new ConcurrentHashMap<Locale, SoftReference<DateFormatSymbols>>(3);
0N/A
5521N/A private transient int lastZoneIndex = 0;
5521N/A
0N/A private void initializeData(Locale desiredLocale) {
2962N/A locale = desiredLocale;
0N/A
2962N/A // Copy values of a cached instance if any.
2962N/A SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale);
2962N/A DateFormatSymbols dfs;
2962N/A if (ref != null && (dfs = ref.get()) != null) {
2962N/A copyMembers(dfs, this);
2962N/A return;
2962N/A }
2962N/A
2962N/A // Initialize the fields from the ResourceBundle for locale.
2962N/A ResourceBundle resource = LocaleData.getDateFormatData(locale);
2962N/A
2962N/A eras = resource.getStringArray("Eras");
0N/A months = resource.getStringArray("MonthNames");
0N/A shortMonths = resource.getStringArray("MonthAbbreviations");
0N/A ampms = resource.getStringArray("AmPmMarkers");
0N/A localPatternChars = resource.getString("DateTimePatternChars");
0N/A
2962N/A // Day of week names are stored in a 1-based array.
2962N/A weekdays = toOneBasedArray(resource.getStringArray("DayNames"));
2962N/A shortWeekdays = toOneBasedArray(resource.getStringArray("DayAbbreviations"));
2962N/A }
2962N/A
2962N/A private static String[] toOneBasedArray(String[] src) {
2962N/A int len = src.length;
2962N/A String[] dst = new String[len + 1];
2962N/A dst[0] = "";
2962N/A for (int i = 0; i < len; i++) {
2962N/A dst[i + 1] = src[i];
2962N/A }
2962N/A return dst;
0N/A }
0N/A
0N/A /**
0N/A * Package private: used by SimpleDateFormat
0N/A * Gets the index for the given time zone ID to obtain the time zone
0N/A * strings for formatting. The time zone ID is just for programmatic
0N/A * lookup. NOT LOCALIZED!!!
0N/A * @param ID the given time zone ID.
0N/A * @return the index of the given time zone ID. Returns -1 if
0N/A * the given time zone ID can't be located in the DateFormatSymbols object.
0N/A * @see java.util.SimpleTimeZone
0N/A */
5521N/A final int getZoneIndex(String ID) {
0N/A String[][] zoneStrings = getZoneStringsWrapper();
5521N/A
5521N/A /*
5521N/A * getZoneIndex has been re-written for performance reasons. instead of
5521N/A * traversing the zoneStrings array every time, we cache the last used zone
5521N/A * index
5521N/A */
5521N/A if (lastZoneIndex < zoneStrings.length && ID.equals(zoneStrings[lastZoneIndex][0])) {
5521N/A return lastZoneIndex;
5521N/A }
5521N/A
5521N/A /* slow path, search entire list */
5521N/A for (int index = 0; index < zoneStrings.length; index++) {
5521N/A if (ID.equals(zoneStrings[index][0])) {
5521N/A lastZoneIndex = index;
5521N/A return index;
5521N/A }
0N/A }
0N/A
0N/A return -1;
0N/A }
0N/A
0N/A /**
0N/A * Wrapper method to the getZoneStrings(), which is called from inside
0N/A * the java.text package and not to mutate the returned arrays, so that
0N/A * it does not need to create a defensive copy.
0N/A */
0N/A final String[][] getZoneStringsWrapper() {
0N/A if (isSubclassObject()) {
0N/A return getZoneStrings();
0N/A } else {
0N/A return getZoneStringsImpl(false);
0N/A }
0N/A }
0N/A
0N/A private final String[][] getZoneStringsImpl(boolean needsCopy) {
0N/A if (zoneStrings == null) {
0N/A zoneStrings = TimeZoneNameUtility.getZoneStrings(locale);
0N/A }
0N/A
0N/A if (!needsCopy) {
0N/A return zoneStrings;
0N/A }
0N/A
0N/A int len = zoneStrings.length;
0N/A String[][] aCopy = new String[len][];
0N/A for (int i = 0; i < len; i++) {
0N/A aCopy[i] = Arrays.copyOf(zoneStrings[i], zoneStrings[i].length);
0N/A }
0N/A return aCopy;
0N/A }
0N/A
0N/A private final boolean isSubclassObject() {
0N/A return !getClass().getName().equals("java.text.DateFormatSymbols");
0N/A }
0N/A
0N/A /**
0N/A * Clones all the data members from the source DateFormatSymbols to
0N/A * the target DateFormatSymbols. This is only for subclasses.
0N/A * @param src the source DateFormatSymbols.
0N/A * @param dst the target DateFormatSymbols.
0N/A */
0N/A private final void copyMembers(DateFormatSymbols src, DateFormatSymbols dst)
0N/A {
0N/A dst.eras = Arrays.copyOf(src.eras, src.eras.length);
0N/A dst.months = Arrays.copyOf(src.months, src.months.length);
0N/A dst.shortMonths = Arrays.copyOf(src.shortMonths, src.shortMonths.length);
0N/A dst.weekdays = Arrays.copyOf(src.weekdays, src.weekdays.length);
0N/A dst.shortWeekdays = Arrays.copyOf(src.shortWeekdays, src.shortWeekdays.length);
0N/A dst.ampms = Arrays.copyOf(src.ampms, src.ampms.length);
0N/A if (src.zoneStrings != null) {
0N/A dst.zoneStrings = src.getZoneStringsImpl(true);
0N/A } else {
0N/A dst.zoneStrings = null;
0N/A }
2702N/A dst.localPatternChars = src.localPatternChars;
0N/A }
0N/A
0N/A /**
0N/A * Write out the default serializable data, after ensuring the
0N/A * <code>zoneStrings</code> field is initialized in order to make
0N/A * sure the backward compatibility.
0N/A *
0N/A * @since 1.6
0N/A */
0N/A private void writeObject(ObjectOutputStream stream) throws IOException {
0N/A if (zoneStrings == null) {
0N/A zoneStrings = TimeZoneNameUtility.getZoneStrings(locale);
0N/A }
0N/A stream.defaultWriteObject();
0N/A }
0N/A
0N/A /**
0N/A * Obtains a DateFormatSymbols instance from a DateFormatSymbolsProvider
0N/A * implementation.
0N/A */
0N/A private static class DateFormatSymbolsGetter
0N/A implements LocaleServiceProviderPool.LocalizedObjectGetter<DateFormatSymbolsProvider,
0N/A DateFormatSymbols> {
0N/A private static final DateFormatSymbolsGetter INSTANCE =
0N/A new DateFormatSymbolsGetter();
0N/A
0N/A public DateFormatSymbols getObject(DateFormatSymbolsProvider dateFormatSymbolsProvider,
0N/A Locale locale,
0N/A String key,
0N/A Object... params) {
0N/A assert params.length == 0;
0N/A return dateFormatSymbolsProvider.getInstance(locale);
0N/A }
0N/A }
0N/A}