rt/emul/compact/src/main/java/java/text/DateFormatSymbols.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 04 Oct 2013 11:07:00 +0200
changeset 1339 8cc04f85a683
parent 1334 588d5bf7a560
permissions -rw-r--r--
Commenting out stuff in java.text so the classes compile
     1 /*
     2  * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    25 
    26 /*
    27  * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved
    28  * (C) Copyright IBM Corp. 1996 - All Rights Reserved
    29  *
    30  *   The original version of this source code and documentation is copyrighted
    31  * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
    32  * materials are provided under terms of a License Agreement between Taligent
    33  * and Sun. This technology is protected by multiple US and International
    34  * patents. This notice and attribution to Taligent may not be removed.
    35  *   Taligent is a registered trademark of Taligent, Inc.
    36  *
    37  */
    38 
    39 package java.text;
    40 
    41 import java.io.IOException;
    42 import java.io.ObjectOutputStream;
    43 import java.io.Serializable;
    44 import java.lang.ref.SoftReference;
    45 import java.util.Arrays;
    46 import java.util.Locale;
    47 import java.util.ResourceBundle;
    48 import java.util.concurrent.ConcurrentHashMap;
    49 import java.util.concurrent.ConcurrentMap;
    50 
    51 /**
    52  * <code>DateFormatSymbols</code> is a public class for encapsulating
    53  * localizable date-time formatting data, such as the names of the
    54  * months, the names of the days of the week, and the time zone data.
    55  * <code>DateFormat</code> and <code>SimpleDateFormat</code> both use
    56  * <code>DateFormatSymbols</code> to encapsulate this information.
    57  *
    58  * <p>
    59  * Typically you shouldn't use <code>DateFormatSymbols</code> directly.
    60  * Rather, you are encouraged to create a date-time formatter with the
    61  * <code>DateFormat</code> class's factory methods: <code>getTimeInstance</code>,
    62  * <code>getDateInstance</code>, or <code>getDateTimeInstance</code>.
    63  * These methods automatically create a <code>DateFormatSymbols</code> for
    64  * the formatter so that you don't have to. After the
    65  * formatter is created, you may modify its format pattern using the
    66  * <code>setPattern</code> method. For more information about
    67  * creating formatters using <code>DateFormat</code>'s factory methods,
    68  * see {@link DateFormat}.
    69  *
    70  * <p>
    71  * If you decide to create a date-time formatter with a specific
    72  * format pattern for a specific locale, you can do so with:
    73  * <blockquote>
    74  * <pre>
    75  * new SimpleDateFormat(aPattern, DateFormatSymbols.getInstance(aLocale)).
    76  * </pre>
    77  * </blockquote>
    78  *
    79  * <p>
    80  * <code>DateFormatSymbols</code> objects are cloneable. When you obtain
    81  * a <code>DateFormatSymbols</code> object, feel free to modify the
    82  * date-time formatting data. For instance, you can replace the localized
    83  * date-time format pattern characters with the ones that you feel easy
    84  * to remember. Or you can change the representative cities
    85  * to your favorite ones.
    86  *
    87  * <p>
    88  * New <code>DateFormatSymbols</code> subclasses may be added to support
    89  * <code>SimpleDateFormat</code> for date-time formatting for additional locales.
    90 
    91  * @see          DateFormat
    92  * @see          SimpleDateFormat
    93  * @see          java.util.SimpleTimeZone
    94  * @author       Chen-Lieh Huang
    95  */
    96 public class DateFormatSymbols implements Serializable, Cloneable {
    97 
    98     /**
    99      * Construct a DateFormatSymbols object by loading format data from
   100      * resources for the default locale. This constructor can only
   101      * construct instances for the locales supported by the Java
   102      * runtime environment, not for those supported by installed
   103      * {@link java.text.spi.DateFormatSymbolsProvider DateFormatSymbolsProvider}
   104      * implementations. For full locale coverage, use the
   105      * {@link #getInstance(Locale) getInstance} method.
   106      *
   107      * @see #getInstance()
   108      * @exception  java.util.MissingResourceException
   109      *             if the resources for the default locale cannot be
   110      *             found or cannot be loaded.
   111      */
   112     public DateFormatSymbols()
   113     {
   114         initializeData(Locale.getDefault(Locale.Category.FORMAT));
   115     }
   116 
   117     /**
   118      * Construct a DateFormatSymbols object by loading format data from
   119      * resources for the given locale. This constructor can only
   120      * construct instances for the locales supported by the Java
   121      * runtime environment, not for those supported by installed
   122      * {@link java.text.spi.DateFormatSymbolsProvider DateFormatSymbolsProvider}
   123      * implementations. For full locale coverage, use the
   124      * {@link #getInstance(Locale) getInstance} method.
   125      *
   126      * @see #getInstance(Locale)
   127      * @exception  java.util.MissingResourceException
   128      *             if the resources for the specified locale cannot be
   129      *             found or cannot be loaded.
   130      */
   131     public DateFormatSymbols(Locale locale)
   132     {
   133         initializeData(locale);
   134     }
   135 
   136     /**
   137      * Era strings. For example: "AD" and "BC".  An array of 2 strings,
   138      * indexed by <code>Calendar.BC</code> and <code>Calendar.AD</code>.
   139      * @serial
   140      */
   141     String eras[] = null;
   142 
   143     /**
   144      * Month strings. For example: "January", "February", etc.  An array
   145      * of 13 strings (some calendars have 13 months), indexed by
   146      * <code>Calendar.JANUARY</code>, <code>Calendar.FEBRUARY</code>, etc.
   147      * @serial
   148      */
   149     String months[] = null;
   150 
   151     /**
   152      * Short month strings. For example: "Jan", "Feb", etc.  An array of
   153      * 13 strings (some calendars have 13 months), indexed by
   154      * <code>Calendar.JANUARY</code>, <code>Calendar.FEBRUARY</code>, etc.
   155 
   156      * @serial
   157      */
   158     String shortMonths[] = null;
   159 
   160     /**
   161      * Weekday strings. For example: "Sunday", "Monday", etc.  An array
   162      * of 8 strings, indexed by <code>Calendar.SUNDAY</code>,
   163      * <code>Calendar.MONDAY</code>, etc.
   164      * The element <code>weekdays[0]</code> is ignored.
   165      * @serial
   166      */
   167     String weekdays[] = null;
   168 
   169     /**
   170      * Short weekday strings. For example: "Sun", "Mon", etc.  An array
   171      * of 8 strings, indexed by <code>Calendar.SUNDAY</code>,
   172      * <code>Calendar.MONDAY</code>, etc.
   173      * The element <code>shortWeekdays[0]</code> is ignored.
   174      * @serial
   175      */
   176     String shortWeekdays[] = null;
   177 
   178     /**
   179      * AM and PM strings. For example: "AM" and "PM".  An array of
   180      * 2 strings, indexed by <code>Calendar.AM</code> and
   181      * <code>Calendar.PM</code>.
   182      * @serial
   183      */
   184     String ampms[] = null;
   185 
   186     /**
   187      * Localized names of time zones in this locale.  This is a
   188      * two-dimensional array of strings of size <em>n</em> by <em>m</em>,
   189      * where <em>m</em> is at least 5.  Each of the <em>n</em> rows is an
   190      * entry containing the localized names for a single <code>TimeZone</code>.
   191      * Each such row contains (with <code>i</code> ranging from
   192      * 0..<em>n</em>-1):
   193      * <ul>
   194      * <li><code>zoneStrings[i][0]</code> - time zone ID</li>
   195      * <li><code>zoneStrings[i][1]</code> - long name of zone in standard
   196      * time</li>
   197      * <li><code>zoneStrings[i][2]</code> - short name of zone in
   198      * standard time</li>
   199      * <li><code>zoneStrings[i][3]</code> - long name of zone in daylight
   200      * saving time</li>
   201      * <li><code>zoneStrings[i][4]</code> - short name of zone in daylight
   202      * saving time</li>
   203      * </ul>
   204      * The zone ID is <em>not</em> localized; it's one of the valid IDs of
   205      * the {@link java.util.TimeZone TimeZone} class that are not
   206      * <a href="../java/util/TimeZone.html#CustomID">custom IDs</a>.
   207      * All other entries are localized names.
   208      * @see java.util.TimeZone
   209      * @serial
   210      */
   211     String zoneStrings[][] = null;
   212 
   213     /**
   214      * Indicates that zoneStrings is set externally with setZoneStrings() method.
   215      */
   216     transient boolean isZoneStringsSet = false;
   217 
   218     /**
   219      * Unlocalized date-time pattern characters. For example: 'y', 'd', etc.
   220      * All locales use the same these unlocalized pattern characters.
   221      */
   222     static final String  patternChars = "GyMdkHmsSEDFwWahKzZYuX";
   223 
   224     static final int PATTERN_ERA                  =  0; // G
   225     static final int PATTERN_YEAR                 =  1; // y
   226     static final int PATTERN_MONTH                =  2; // M
   227     static final int PATTERN_DAY_OF_MONTH         =  3; // d
   228     static final int PATTERN_HOUR_OF_DAY1         =  4; // k
   229     static final int PATTERN_HOUR_OF_DAY0         =  5; // H
   230     static final int PATTERN_MINUTE               =  6; // m
   231     static final int PATTERN_SECOND               =  7; // s
   232     static final int PATTERN_MILLISECOND          =  8; // S
   233     static final int PATTERN_DAY_OF_WEEK          =  9; // E
   234     static final int PATTERN_DAY_OF_YEAR          = 10; // D
   235     static final int PATTERN_DAY_OF_WEEK_IN_MONTH = 11; // F
   236     static final int PATTERN_WEEK_OF_YEAR         = 12; // w
   237     static final int PATTERN_WEEK_OF_MONTH        = 13; // W
   238     static final int PATTERN_AM_PM                = 14; // a
   239     static final int PATTERN_HOUR1                = 15; // h
   240     static final int PATTERN_HOUR0                = 16; // K
   241     static final int PATTERN_ZONE_NAME            = 17; // z
   242     static final int PATTERN_ZONE_VALUE           = 18; // Z
   243     static final int PATTERN_WEEK_YEAR            = 19; // Y
   244     static final int PATTERN_ISO_DAY_OF_WEEK      = 20; // u
   245     static final int PATTERN_ISO_ZONE             = 21; // X
   246 
   247     /**
   248      * Localized date-time pattern characters. For example, a locale may
   249      * wish to use 'u' rather than 'y' to represent years in its date format
   250      * pattern strings.
   251      * This string must be exactly 18 characters long, with the index of
   252      * the characters described by <code>DateFormat.ERA_FIELD</code>,
   253      * <code>DateFormat.YEAR_FIELD</code>, etc.  Thus, if the string were
   254      * "Xz...", then localized patterns would use 'X' for era and 'z' for year.
   255      * @serial
   256      */
   257     String  localPatternChars = null;
   258 
   259     /**
   260      * The locale which is used for initializing this DateFormatSymbols object.
   261      *
   262      * @since 1.6
   263      * @serial
   264      */
   265     Locale locale = null;
   266 
   267     /* use serialVersionUID from JDK 1.1.4 for interoperability */
   268     static final long serialVersionUID = -5987973545549424702L;
   269 
   270     /**
   271      * Returns an array of all locales for which the
   272      * <code>getInstance</code> methods of this class can return
   273      * localized instances.
   274      * The returned array represents the union of locales supported by the
   275      * Java runtime and by installed
   276      * {@link java.text.spi.DateFormatSymbolsProvider DateFormatSymbolsProvider}
   277      * implementations.  It must contain at least a <code>Locale</code>
   278      * instance equal to {@link java.util.Locale#US Locale.US}.
   279      *
   280      * @return An array of locales for which localized
   281      *         <code>DateFormatSymbols</code> instances are available.
   282      * @since 1.6
   283      */
   284     public static Locale[] getAvailableLocales() {
   285         return new Locale[] { Locale.US };
   286 //        LocaleServiceProviderPool pool=
   287 //            LocaleServiceProviderPool.getPool(DateFormatSymbolsProvider.class);
   288 //        return pool.getAvailableLocales();
   289     }
   290 
   291     /**
   292      * Gets the <code>DateFormatSymbols</code> instance for the default
   293      * locale.  This method provides access to <code>DateFormatSymbols</code>
   294      * instances for locales supported by the Java runtime itself as well
   295      * as for those supported by installed
   296      * {@link java.text.spi.DateFormatSymbolsProvider DateFormatSymbolsProvider}
   297      * implementations.
   298      * @return a <code>DateFormatSymbols</code> instance.
   299      * @since 1.6
   300      */
   301     public static final DateFormatSymbols getInstance() {
   302         return getInstance(Locale.getDefault(Locale.Category.FORMAT));
   303     }
   304 
   305     /**
   306      * Gets the <code>DateFormatSymbols</code> instance for the specified
   307      * locale.  This method provides access to <code>DateFormatSymbols</code>
   308      * instances for locales supported by the Java runtime itself as well
   309      * as for those supported by installed
   310      * {@link java.text.spi.DateFormatSymbolsProvider DateFormatSymbolsProvider}
   311      * implementations.
   312      * @param locale the given locale.
   313      * @return a <code>DateFormatSymbols</code> instance.
   314      * @exception NullPointerException if <code>locale</code> is null
   315      * @since 1.6
   316      */
   317     public static final DateFormatSymbols getInstance(Locale locale) {
   318         DateFormatSymbols dfs = getProviderInstance(locale);
   319         if (dfs != null) {
   320             return dfs;
   321         }
   322         return (DateFormatSymbols) getCachedInstance(locale).clone();
   323     }
   324 
   325     /**
   326      * Returns a DateFormatSymbols provided by a provider or found in
   327      * the cache. Note that this method returns a cached instance,
   328      * not its clone. Therefore, the instance should never be given to
   329      * an application.
   330      */
   331     static final DateFormatSymbols getInstanceRef(Locale locale) {
   332         DateFormatSymbols dfs = getProviderInstance(locale);
   333         if (dfs != null) {
   334             return dfs;
   335         }
   336         return getCachedInstance(locale);
   337     }
   338 
   339     private static DateFormatSymbols getProviderInstance(Locale locale) {
   340         DateFormatSymbols providersInstance = null;
   341 
   342         // Check whether a provider can provide an implementation that's closer
   343         // to the requested locale than what the Java runtime itself can provide.
   344 //        LocaleServiceProviderPool pool =
   345 //            LocaleServiceProviderPool.getPool(DateFormatSymbolsProvider.class);
   346 //        if (pool.hasProviders()) {
   347 //            providersInstance = pool.getLocalizedObject(
   348 //                                    DateFormatSymbolsGetter.INSTANCE, locale);
   349 //        }
   350         return providersInstance;
   351     }
   352 
   353     /**
   354      * Returns a cached DateFormatSymbols if it's found in the
   355      * cache. Otherwise, this method returns a newly cached instance
   356      * for the given locale.
   357      */
   358     private static DateFormatSymbols getCachedInstance(Locale locale) {
   359         SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale);
   360         DateFormatSymbols dfs = null;
   361         if (ref == null || (dfs = ref.get()) == null) {
   362             dfs = new DateFormatSymbols(locale);
   363             ref = new SoftReference<DateFormatSymbols>(dfs);
   364             SoftReference<DateFormatSymbols> x = cachedInstances.putIfAbsent(locale, ref);
   365             if (x != null) {
   366                 DateFormatSymbols y = x.get();
   367                 if (y != null) {
   368                     dfs = y;
   369                 } else {
   370                     // Replace the empty SoftReference with ref.
   371                     cachedInstances.put(locale, ref);
   372                 }
   373             }
   374         }
   375         return dfs;
   376     }
   377 
   378     /**
   379      * Gets era strings. For example: "AD" and "BC".
   380      * @return the era strings.
   381      */
   382     public String[] getEras() {
   383         return Arrays.copyOf(eras, eras.length);
   384     }
   385 
   386     /**
   387      * Sets era strings. For example: "AD" and "BC".
   388      * @param newEras the new era strings.
   389      */
   390     public void setEras(String[] newEras) {
   391         eras = Arrays.copyOf(newEras, newEras.length);
   392     }
   393 
   394     /**
   395      * Gets month strings. For example: "January", "February", etc.
   396      * @return the month strings.
   397      */
   398     public String[] getMonths() {
   399         return Arrays.copyOf(months, months.length);
   400     }
   401 
   402     /**
   403      * Sets month strings. For example: "January", "February", etc.
   404      * @param newMonths the new month strings.
   405      */
   406     public void setMonths(String[] newMonths) {
   407         months = Arrays.copyOf(newMonths, newMonths.length);
   408     }
   409 
   410     /**
   411      * Gets short month strings. For example: "Jan", "Feb", etc.
   412      * @return the short month strings.
   413      */
   414     public String[] getShortMonths() {
   415         return Arrays.copyOf(shortMonths, shortMonths.length);
   416     }
   417 
   418     /**
   419      * Sets short month strings. For example: "Jan", "Feb", etc.
   420      * @param newShortMonths the new short month strings.
   421      */
   422     public void setShortMonths(String[] newShortMonths) {
   423         shortMonths = Arrays.copyOf(newShortMonths, newShortMonths.length);
   424     }
   425 
   426     /**
   427      * Gets weekday strings. For example: "Sunday", "Monday", etc.
   428      * @return the weekday strings. Use <code>Calendar.SUNDAY</code>,
   429      * <code>Calendar.MONDAY</code>, etc. to index the result array.
   430      */
   431     public String[] getWeekdays() {
   432         return Arrays.copyOf(weekdays, weekdays.length);
   433     }
   434 
   435     /**
   436      * Sets weekday strings. For example: "Sunday", "Monday", etc.
   437      * @param newWeekdays the new weekday strings. The array should
   438      * be indexed by <code>Calendar.SUNDAY</code>,
   439      * <code>Calendar.MONDAY</code>, etc.
   440      */
   441     public void setWeekdays(String[] newWeekdays) {
   442         weekdays = Arrays.copyOf(newWeekdays, newWeekdays.length);
   443     }
   444 
   445     /**
   446      * Gets short weekday strings. For example: "Sun", "Mon", etc.
   447      * @return the short weekday strings. Use <code>Calendar.SUNDAY</code>,
   448      * <code>Calendar.MONDAY</code>, etc. to index the result array.
   449      */
   450     public String[] getShortWeekdays() {
   451         return Arrays.copyOf(shortWeekdays, shortWeekdays.length);
   452     }
   453 
   454     /**
   455      * Sets short weekday strings. For example: "Sun", "Mon", etc.
   456      * @param newShortWeekdays the new short weekday strings. The array should
   457      * be indexed by <code>Calendar.SUNDAY</code>,
   458      * <code>Calendar.MONDAY</code>, etc.
   459      */
   460     public void setShortWeekdays(String[] newShortWeekdays) {
   461         shortWeekdays = Arrays.copyOf(newShortWeekdays, newShortWeekdays.length);
   462     }
   463 
   464     /**
   465      * Gets ampm strings. For example: "AM" and "PM".
   466      * @return the ampm strings.
   467      */
   468     public String[] getAmPmStrings() {
   469         return Arrays.copyOf(ampms, ampms.length);
   470     }
   471 
   472     /**
   473      * Sets ampm strings. For example: "AM" and "PM".
   474      * @param newAmpms the new ampm strings.
   475      */
   476     public void setAmPmStrings(String[] newAmpms) {
   477         ampms = Arrays.copyOf(newAmpms, newAmpms.length);
   478     }
   479 
   480     /**
   481      * Gets time zone strings.  Use of this method is discouraged; use
   482      * {@link java.util.TimeZone#getDisplayName() TimeZone.getDisplayName()}
   483      * instead.
   484      * <p>
   485      * The value returned is a
   486      * two-dimensional array of strings of size <em>n</em> by <em>m</em>,
   487      * where <em>m</em> is at least 5.  Each of the <em>n</em> rows is an
   488      * entry containing the localized names for a single <code>TimeZone</code>.
   489      * Each such row contains (with <code>i</code> ranging from
   490      * 0..<em>n</em>-1):
   491      * <ul>
   492      * <li><code>zoneStrings[i][0]</code> - time zone ID</li>
   493      * <li><code>zoneStrings[i][1]</code> - long name of zone in standard
   494      * time</li>
   495      * <li><code>zoneStrings[i][2]</code> - short name of zone in
   496      * standard time</li>
   497      * <li><code>zoneStrings[i][3]</code> - long name of zone in daylight
   498      * saving time</li>
   499      * <li><code>zoneStrings[i][4]</code> - short name of zone in daylight
   500      * saving time</li>
   501      * </ul>
   502      * The zone ID is <em>not</em> localized; it's one of the valid IDs of
   503      * the {@link java.util.TimeZone TimeZone} class that are not
   504      * <a href="../util/TimeZone.html#CustomID">custom IDs</a>.
   505      * All other entries are localized names.  If a zone does not implement
   506      * daylight saving time, the daylight saving time names should not be used.
   507      * <p>
   508      * If {@link #setZoneStrings(String[][]) setZoneStrings} has been called
   509      * on this <code>DateFormatSymbols</code> instance, then the strings
   510      * provided by that call are returned. Otherwise, the returned array
   511      * contains names provided by the Java runtime and by installed
   512      * {@link java.util.spi.TimeZoneNameProvider TimeZoneNameProvider}
   513      * implementations.
   514      *
   515      * @return the time zone strings.
   516      * @see #setZoneStrings(String[][])
   517      */
   518     public String[][] getZoneStrings() {
   519         return getZoneStringsImpl(true);
   520     }
   521 
   522     /**
   523      * Sets time zone strings.  The argument must be a
   524      * two-dimensional array of strings of size <em>n</em> by <em>m</em>,
   525      * where <em>m</em> is at least 5.  Each of the <em>n</em> rows is an
   526      * entry containing the localized names for a single <code>TimeZone</code>.
   527      * Each such row contains (with <code>i</code> ranging from
   528      * 0..<em>n</em>-1):
   529      * <ul>
   530      * <li><code>zoneStrings[i][0]</code> - time zone ID</li>
   531      * <li><code>zoneStrings[i][1]</code> - long name of zone in standard
   532      * time</li>
   533      * <li><code>zoneStrings[i][2]</code> - short name of zone in
   534      * standard time</li>
   535      * <li><code>zoneStrings[i][3]</code> - long name of zone in daylight
   536      * saving time</li>
   537      * <li><code>zoneStrings[i][4]</code> - short name of zone in daylight
   538      * saving time</li>
   539      * </ul>
   540      * The zone ID is <em>not</em> localized; it's one of the valid IDs of
   541      * the {@link java.util.TimeZone TimeZone} class that are not
   542      * <a href="../util/TimeZone.html#CustomID">custom IDs</a>.
   543      * All other entries are localized names.
   544      *
   545      * @param newZoneStrings the new time zone strings.
   546      * @exception IllegalArgumentException if the length of any row in
   547      *    <code>newZoneStrings</code> is less than 5
   548      * @exception NullPointerException if <code>newZoneStrings</code> is null
   549      * @see #getZoneStrings()
   550      */
   551     public void setZoneStrings(String[][] newZoneStrings) {
   552         String[][] aCopy = new String[newZoneStrings.length][];
   553         for (int i = 0; i < newZoneStrings.length; ++i) {
   554             int len = newZoneStrings[i].length;
   555             if (len < 5) {
   556                 throw new IllegalArgumentException();
   557             }
   558             aCopy[i] = Arrays.copyOf(newZoneStrings[i], len);
   559         }
   560         zoneStrings = aCopy;
   561         isZoneStringsSet = true;
   562     }
   563 
   564     /**
   565      * Gets localized date-time pattern characters. For example: 'u', 't', etc.
   566      * @return the localized date-time pattern characters.
   567      */
   568     public String getLocalPatternChars() {
   569         return localPatternChars;
   570     }
   571 
   572     /**
   573      * Sets localized date-time pattern characters. For example: 'u', 't', etc.
   574      * @param newLocalPatternChars the new localized date-time
   575      * pattern characters.
   576      */
   577     public void setLocalPatternChars(String newLocalPatternChars) {
   578         // Call toString() to throw an NPE in case the argument is null
   579         localPatternChars = newLocalPatternChars.toString();
   580     }
   581 
   582     /**
   583      * Overrides Cloneable
   584      */
   585     public Object clone()
   586     {
   587         try
   588         {
   589             DateFormatSymbols other = (DateFormatSymbols)super.clone();
   590             copyMembers(this, other);
   591             return other;
   592         } catch (CloneNotSupportedException e) {
   593             throw new InternalError();
   594         }
   595     }
   596 
   597     /**
   598      * Override hashCode.
   599      * Generates a hash code for the DateFormatSymbols object.
   600      */
   601     public int hashCode() {
   602         int hashcode = 0;
   603         String[][] zoneStrings = getZoneStringsWrapper();
   604         for (int index = 0; index < zoneStrings[0].length; ++index)
   605             hashcode ^= zoneStrings[0][index].hashCode();
   606         return hashcode;
   607     }
   608 
   609     /**
   610      * Override equals
   611      */
   612     public boolean equals(Object obj)
   613     {
   614         if (this == obj) return true;
   615         if (obj == null || getClass() != obj.getClass()) return false;
   616         DateFormatSymbols that = (DateFormatSymbols) obj;
   617         return (Arrays.equals(eras, that.eras)
   618                 && Arrays.equals(months, that.months)
   619                 && Arrays.equals(shortMonths, that.shortMonths)
   620                 && Arrays.equals(weekdays, that.weekdays)
   621                 && Arrays.equals(shortWeekdays, that.shortWeekdays)
   622                 && Arrays.equals(ampms, that.ampms)
   623                 && Arrays.deepEquals(getZoneStringsWrapper(), that.getZoneStringsWrapper())
   624                 && ((localPatternChars != null
   625                   && localPatternChars.equals(that.localPatternChars))
   626                  || (localPatternChars == null
   627                   && that.localPatternChars == null)));
   628     }
   629 
   630     // =======================privates===============================
   631 
   632     /**
   633      * Useful constant for defining time zone offsets.
   634      */
   635     static final int millisPerHour = 60*60*1000;
   636 
   637     /**
   638      * Cache to hold DateFormatSymbols instances per Locale.
   639      */
   640     private static final ConcurrentMap<Locale, SoftReference<DateFormatSymbols>> cachedInstances
   641         = new ConcurrentHashMap<Locale, SoftReference<DateFormatSymbols>>(3);
   642 
   643     private void initializeData(Locale desiredLocale) {
   644         locale = desiredLocale;
   645 
   646         // Copy values of a cached instance if any.
   647         SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale);
   648         DateFormatSymbols dfs;
   649         if (ref != null && (dfs = ref.get()) != null) {
   650             copyMembers(dfs, this);
   651             return;
   652         }
   653 
   654         // Initialize the fields from the ResourceBundle for locale.
   655 //        ResourceBundle resource = LocaleData.getDateFormatData(locale);
   656 //
   657 //        eras = resource.getStringArray("Eras");
   658 //        months = resource.getStringArray("MonthNames");
   659 //        shortMonths = resource.getStringArray("MonthAbbreviations");
   660 //        ampms = resource.getStringArray("AmPmMarkers");
   661 //        localPatternChars = resource.getString("DateTimePatternChars");
   662 //
   663 //        // Day of week names are stored in a 1-based array.
   664 //        weekdays = toOneBasedArray(resource.getStringArray("DayNames"));
   665 //        shortWeekdays = toOneBasedArray(resource.getStringArray("DayAbbreviations"));
   666     }
   667 
   668     private static String[] toOneBasedArray(String[] src) {
   669         int len = src.length;
   670         String[] dst = new String[len + 1];
   671         dst[0] = "";
   672         for (int i = 0; i < len; i++) {
   673             dst[i + 1] = src[i];
   674         }
   675         return dst;
   676     }
   677 
   678     /**
   679      * Package private: used by SimpleDateFormat
   680      * Gets the index for the given time zone ID to obtain the time zone
   681      * strings for formatting. The time zone ID is just for programmatic
   682      * lookup. NOT LOCALIZED!!!
   683      * @param ID the given time zone ID.
   684      * @return the index of the given time zone ID.  Returns -1 if
   685      * the given time zone ID can't be located in the DateFormatSymbols object.
   686      * @see java.util.SimpleTimeZone
   687      */
   688     final int getZoneIndex(String ID)
   689     {
   690         String[][] zoneStrings = getZoneStringsWrapper();
   691         for (int index=0; index<zoneStrings.length; index++)
   692         {
   693             if (ID.equals(zoneStrings[index][0])) return index;
   694         }
   695 
   696         return -1;
   697     }
   698 
   699     /**
   700      * Wrapper method to the getZoneStrings(), which is called from inside
   701      * the java.text package and not to mutate the returned arrays, so that
   702      * it does not need to create a defensive copy.
   703      */
   704     final String[][] getZoneStringsWrapper() {
   705         if (isSubclassObject()) {
   706             return getZoneStrings();
   707         } else {
   708             return getZoneStringsImpl(false);
   709         }
   710     }
   711 
   712     private final String[][] getZoneStringsImpl(boolean needsCopy) {
   713         if (zoneStrings == null) {
   714 //            zoneStrings = TimeZoneNameUtility.getZoneStrings(locale);
   715         }
   716 
   717         if (!needsCopy) {
   718             return zoneStrings;
   719         }
   720 
   721         int len = zoneStrings.length;
   722         String[][] aCopy = new String[len][];
   723         for (int i = 0; i < len; i++) {
   724             aCopy[i] = Arrays.copyOf(zoneStrings[i], zoneStrings[i].length);
   725         }
   726         return aCopy;
   727     }
   728 
   729     private final boolean isSubclassObject() {
   730         return !getClass().getName().equals("java.text.DateFormatSymbols");
   731     }
   732 
   733     /**
   734      * Clones all the data members from the source DateFormatSymbols to
   735      * the target DateFormatSymbols. This is only for subclasses.
   736      * @param src the source DateFormatSymbols.
   737      * @param dst the target DateFormatSymbols.
   738      */
   739     private final void copyMembers(DateFormatSymbols src, DateFormatSymbols dst)
   740     {
   741         dst.eras = Arrays.copyOf(src.eras, src.eras.length);
   742         dst.months = Arrays.copyOf(src.months, src.months.length);
   743         dst.shortMonths = Arrays.copyOf(src.shortMonths, src.shortMonths.length);
   744         dst.weekdays = Arrays.copyOf(src.weekdays, src.weekdays.length);
   745         dst.shortWeekdays = Arrays.copyOf(src.shortWeekdays, src.shortWeekdays.length);
   746         dst.ampms = Arrays.copyOf(src.ampms, src.ampms.length);
   747         if (src.zoneStrings != null) {
   748             dst.zoneStrings = src.getZoneStringsImpl(true);
   749         } else {
   750             dst.zoneStrings = null;
   751         }
   752         dst.localPatternChars = src.localPatternChars;
   753     }
   754 
   755     /**
   756      * Write out the default serializable data, after ensuring the
   757      * <code>zoneStrings</code> field is initialized in order to make
   758      * sure the backward compatibility.
   759      *
   760      * @since 1.6
   761     private void writeObject(ObjectOutputStream stream) throws IOException {
   762         if (zoneStrings == null) {
   763             zoneStrings = TimeZoneNameUtility.getZoneStrings(locale);
   764         }
   765         stream.defaultWriteObject();
   766     }
   767 
   768     /**
   769      * Obtains a DateFormatSymbols instance from a DateFormatSymbolsProvider
   770      * implementation.
   771     private static class DateFormatSymbolsGetter
   772         implements LocaleServiceProviderPool.LocalizedObjectGetter<DateFormatSymbolsProvider,
   773                                                                    DateFormatSymbols> {
   774         private static final DateFormatSymbolsGetter INSTANCE =
   775             new DateFormatSymbolsGetter();
   776 
   777         public DateFormatSymbols getObject(DateFormatSymbolsProvider dateFormatSymbolsProvider,
   778                                 Locale locale,
   779                                 String key,
   780                                 Object... params) {
   781             assert params.length == 0;
   782             return dateFormatSymbolsProvider.getInstance(locale);
   783         }
   784     }
   785      */
   786 }