src/share/classes/java/text/DateFormatSymbols.java

Print this page
rev 6352 : imported patch 7162007


  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.text.spi.DateFormatSymbolsProvider;
  46 import java.util.Arrays;
  47 import java.util.Locale;
  48 import java.util.Objects;
  49 import java.util.ResourceBundle;
  50 import java.util.TimeZone;
  51 import java.util.concurrent.ConcurrentHashMap;
  52 import java.util.concurrent.ConcurrentMap;
  53 import sun.util.locale.provider.LocaleProviderAdapter;
  54 import sun.util.locale.provider.LocaleServiceProviderPool;

  55 import sun.util.locale.provider.TimeZoneNameUtility;
  56 
  57 /**
  58  * <code>DateFormatSymbols</code> is a public class for encapsulating
  59  * localizable date-time formatting data, such as the names of the
  60  * months, the names of the days of the week, and the time zone data.
  61  * <code>DateFormat</code> and <code>SimpleDateFormat</code> both use
  62  * <code>DateFormatSymbols</code> to encapsulate this information.
  63  *
  64  * <p>
  65  * Typically you shouldn't use <code>DateFormatSymbols</code> directly.
  66  * Rather, you are encouraged to create a date-time formatter with the
  67  * <code>DateFormat</code> class's factory methods: <code>getTimeInstance</code>,
  68  * <code>getDateInstance</code>, or <code>getDateTimeInstance</code>.
  69  * These methods automatically create a <code>DateFormatSymbols</code> for
  70  * the formatter so that you don't have to. After the
  71  * formatter is created, you may modify its format pattern using the
  72  * <code>setPattern</code> method. For more information about
  73  * creating formatters using <code>DateFormat</code>'s factory methods,
  74  * see {@link DateFormat}.


 663 
 664     /**
 665      * Cached hash code
 666      */
 667     transient volatile int cachedHashCode = 0;
 668 
 669     private void initializeData(Locale desiredLocale) {
 670         locale = desiredLocale;
 671 
 672         // Copy values of a cached instance if any.
 673         SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale);
 674         DateFormatSymbols dfs;
 675         if (ref != null && (dfs = ref.get()) != null) {
 676             copyMembers(dfs, this);
 677             return;
 678         }
 679 
 680         // Initialize the fields from the ResourceBundle for locale.
 681         LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale);
 682         // Avoid any potential recursions
 683         switch (adapter.getAdapterType()) {
 684         case HOST:
 685         case SPI:
 686             adapter = LocaleProviderAdapter.getResourceBundleBased();
 687             break;
 688         }
 689         ResourceBundle resource = adapter.getLocaleData().getDateFormatData(locale);
 690 
 691         // JRE and CLDR use different keys
 692         // JRE: Eras, short.Eras and narrow.Eras
 693         // CLDR: long.Eras, Eras and narrow.Eras
 694         if (resource.containsKey("Eras")) {
 695             eras = resource.getStringArray("Eras");
 696         } else if (resource.containsKey("long.Eras")) {
 697             eras = resource.getStringArray("long.Eras");
 698         } else if (resource.containsKey("short.Eras")) {
 699             eras = resource.getStringArray("short.Eras");
 700         }
 701         months = resource.getStringArray("MonthNames");
 702         shortMonths = resource.getStringArray("MonthAbbreviations");
 703         ampms = resource.getStringArray("AmPmMarkers");
 704         localPatternChars = resource.getString("DateTimePatternChars");
 705 
 706         // Day of week names are stored in a 1-based array.
 707         weekdays = toOneBasedArray(resource.getStringArray("DayNames"));
 708         shortWeekdays = toOneBasedArray(resource.getStringArray("DayAbbreviations"));
 709 




  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.text.spi.DateFormatSymbolsProvider;
  46 import java.util.Arrays;
  47 import java.util.Locale;
  48 import java.util.Objects;
  49 import java.util.ResourceBundle;
  50 import java.util.TimeZone;
  51 import java.util.concurrent.ConcurrentHashMap;
  52 import java.util.concurrent.ConcurrentMap;
  53 import sun.util.locale.provider.LocaleProviderAdapter;
  54 import sun.util.locale.provider.LocaleServiceProviderPool;
  55 import sun.util.locale.provider.ResourceBundleBasedAdapter;
  56 import sun.util.locale.provider.TimeZoneNameUtility;
  57 
  58 /**
  59  * <code>DateFormatSymbols</code> is a public class for encapsulating
  60  * localizable date-time formatting data, such as the names of the
  61  * months, the names of the days of the week, and the time zone data.
  62  * <code>DateFormat</code> and <code>SimpleDateFormat</code> both use
  63  * <code>DateFormatSymbols</code> to encapsulate this information.
  64  *
  65  * <p>
  66  * Typically you shouldn't use <code>DateFormatSymbols</code> directly.
  67  * Rather, you are encouraged to create a date-time formatter with the
  68  * <code>DateFormat</code> class's factory methods: <code>getTimeInstance</code>,
  69  * <code>getDateInstance</code>, or <code>getDateTimeInstance</code>.
  70  * These methods automatically create a <code>DateFormatSymbols</code> for
  71  * the formatter so that you don't have to. After the
  72  * formatter is created, you may modify its format pattern using the
  73  * <code>setPattern</code> method. For more information about
  74  * creating formatters using <code>DateFormat</code>'s factory methods,
  75  * see {@link DateFormat}.


 664 
 665     /**
 666      * Cached hash code
 667      */
 668     transient volatile int cachedHashCode = 0;
 669 
 670     private void initializeData(Locale desiredLocale) {
 671         locale = desiredLocale;
 672 
 673         // Copy values of a cached instance if any.
 674         SoftReference<DateFormatSymbols> ref = cachedInstances.get(locale);
 675         DateFormatSymbols dfs;
 676         if (ref != null && (dfs = ref.get()) != null) {
 677             copyMembers(dfs, this);
 678             return;
 679         }
 680 
 681         // Initialize the fields from the ResourceBundle for locale.
 682         LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(DateFormatSymbolsProvider.class, locale);
 683         // Avoid any potential recursions
 684         if (!(adapter instanceof ResourceBundleBasedAdapter)) {


 685             adapter = LocaleProviderAdapter.getResourceBundleBased();

 686         }
 687         ResourceBundle resource = ((ResourceBundleBasedAdapter)adapter).getLocaleData().getDateFormatData(locale);
 688 
 689         // JRE and CLDR use different keys
 690         // JRE: Eras, short.Eras and narrow.Eras
 691         // CLDR: long.Eras, Eras and narrow.Eras
 692         if (resource.containsKey("Eras")) {
 693             eras = resource.getStringArray("Eras");
 694         } else if (resource.containsKey("long.Eras")) {
 695             eras = resource.getStringArray("long.Eras");
 696         } else if (resource.containsKey("short.Eras")) {
 697             eras = resource.getStringArray("short.Eras");
 698         }
 699         months = resource.getStringArray("MonthNames");
 700         shortMonths = resource.getStringArray("MonthAbbreviations");
 701         ampms = resource.getStringArray("AmPmMarkers");
 702         localPatternChars = resource.getString("DateTimePatternChars");
 703 
 704         // Day of week names are stored in a 1-based array.
 705         weekdays = toOneBasedArray(resource.getStringArray("DayNames"));
 706         shortWeekdays = toOneBasedArray(resource.getStringArray("DayAbbreviations"));
 707