2 *******************************************************************************
\r
3 * Copyright (C) 1996-2010, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
8 package com.ibm.icu.text;
\r
10 import java.io.IOException;
\r
11 import java.io.ObjectInputStream;
\r
12 import java.io.Serializable;
\r
13 import java.util.Locale;
\r
14 import java.util.MissingResourceException;
\r
15 import java.util.ResourceBundle;
\r
17 import com.ibm.icu.impl.CalendarData;
\r
18 import com.ibm.icu.impl.CalendarUtil;
\r
19 import com.ibm.icu.impl.ICUCache;
\r
20 import com.ibm.icu.impl.ICUResourceBundle;
\r
21 import com.ibm.icu.impl.SimpleCache;
\r
22 import com.ibm.icu.impl.Utility;
\r
23 import com.ibm.icu.impl.ZoneMeta;
\r
24 import com.ibm.icu.impl.ZoneStringFormat;
\r
25 import com.ibm.icu.util.Calendar;
\r
26 import com.ibm.icu.util.ULocale;
\r
27 import com.ibm.icu.util.UResourceBundle;
\r
30 * {@icuenhanced java.text.DateFormatSymbols}.{@icu _usage_}
\r
32 * <p><code>DateFormatSymbols</code> is a public class for encapsulating
\r
33 * localizable date-time formatting data, such as the names of the
\r
34 * months, the names of the days of the week, and the time zone data.
\r
35 * <code>DateFormat</code> and <code>SimpleDateFormat</code> both use
\r
36 * <code>DateFormatSymbols</code> to encapsulate this information.
\r
38 * <p>Typically you shouldn't use <code>DateFormatSymbols</code> directly.
\r
39 * Rather, you are encouraged to create a date-time formatter with the
\r
40 * <code>DateFormat</code> class's factory methods: <code>getTimeInstance</code>,
\r
41 * <code>getDateInstance</code>, or <code>getDateTimeInstance</code>.
\r
42 * These methods automatically create a <code>DateFormatSymbols</code> for
\r
43 * the formatter so that you don't have to. After the
\r
44 * formatter is created, you may modify its format pattern using the
\r
45 * <code>setPattern</code> method. For more information about
\r
46 * creating formatters using <code>DateFormat</code>'s factory methods,
\r
47 * see {@link DateFormat}.
\r
49 * <p>If you decide to create a date-time formatter with a specific
\r
50 * format pattern for a specific locale, you can do so with:
\r
53 * new SimpleDateFormat(aPattern, new DateFormatSymbols(aLocale)).
\r
57 * <p><code>DateFormatSymbols</code> objects are clonable. When you obtain
\r
58 * a <code>DateFormatSymbols</code> object, feel free to modify the
\r
59 * date-time formatting data. For instance, you can replace the localized
\r
60 * date-time format pattern characters with the ones that you feel easy
\r
61 * to remember. Or you can change the representative cities
\r
62 * to your favorite ones.
\r
64 * <p>New <code>DateFormatSymbols</code> subclasses may be added to support
\r
65 * <code>SimpleDateFormat</code> for date-time formatting for additional locales.
\r
68 * @see SimpleDateFormat
\r
69 * @see com.ibm.icu.util.SimpleTimeZone
\r
70 * @author Chen-Lieh Huang
\r
73 public class DateFormatSymbols implements Serializable, Cloneable {
\r
75 // TODO make sure local pattern char string is 18 characters long,
\r
76 // that is, that it encompasses the new 'u' char for
\r
77 // EXTENDED_YEAR. Two options: 1. Make sure resource data is
\r
78 // correct; 2. Make code add in 'u' at end if len == 17.
\r
80 // Constants for context
\r
82 * {@icu} Constant for context.
\r
85 public static final int FORMAT = 0;
\r
88 * {@icu} Constant for context.
\r
91 public static final int STANDALONE = 1;
\r
94 * {@icu} Constant for context.
\r
96 * @deprecated This API is ICU internal only.
\r
98 public static final int DT_CONTEXT_COUNT = 2;
\r
100 // Constants for width
\r
103 * {@icu} Constant for width.
\r
106 public static final int ABBREVIATED = 0;
\r
109 * {@icu} Constant for width.
\r
112 public static final int WIDE = 1;
\r
115 * {@icu} Constant for width.
\r
118 public static final int NARROW = 2;
\r
121 * {@icu} Constant for width.
\r
123 * @deprecated This API is ICU internal only.
\r
125 public static final int DT_WIDTH_COUNT = 3;
\r
128 * Constructs a DateFormatSymbols object by loading format data from
\r
129 * resources for the default locale.
\r
131 * @throws java.util.MissingResourceException if the resources for the default locale
\r
132 * cannot be found or cannot be loaded.
\r
135 public DateFormatSymbols()
\r
137 this(ULocale.getDefault());
\r
141 * Constructs a DateFormatSymbols object by loading format data from
\r
142 * resources for the given locale.
\r
144 * @throws java.util.MissingResourceException if the resources for the specified
\r
145 * locale cannot be found or cannot be loaded.
\r
148 public DateFormatSymbols(Locale locale)
\r
150 this(ULocale.forLocale(locale));
\r
154 * {@icu} Constructs a DateFormatSymbols object by loading format data from
\r
155 * resources for the given ulocale.
\r
157 * @throws java.util.MissingResourceException if the resources for the specified
\r
158 * locale cannot be found or cannot be loaded.
\r
161 public DateFormatSymbols(ULocale locale)
\r
163 initializeData(locale, CalendarUtil.getCalendarType(locale));
\r
167 * Returns a DateFormatSymbols instance for the default locale.
\r
169 * {@icunote} Unlike <code>java.text.DateFormatSymbols#getInstance</code>,
\r
170 * this method simply returns <code>new com.ibm.icu.text.DateFormatSymbols()</code>.
\r
171 * ICU does not support <code>DateFormatSymbolsProvider</code> introduced in Java 6
\r
172 * or its equivalent implementation for now.
\r
174 * @return A DateFormatSymbols instance.
\r
177 public static DateFormatSymbols getInstance() {
\r
178 return new DateFormatSymbols();
\r
182 * Returns a DateFormatSymbols instance for the given locale.
\r
184 * {@icunote} Unlike <code>java.text.DateFormatSymbols#getInstance</code>,
\r
185 * this method simply returns <code>new com.ibm.icu.text.DateFormatSymbols(locale)</code>.
\r
186 * ICU does not support <code>DateFormatSymbolsProvider</code> introduced in Java 6
\r
187 * or its equivalent implementation for now.
\r
189 * @param locale the locale.
\r
190 * @return A DateFormatSymbols instance.
\r
193 public static DateFormatSymbols getInstance(Locale locale) {
\r
194 return new DateFormatSymbols(locale);
\r
198 * {@icu} Returns a DateFormatSymbols instance for the given locale.
\r
200 * {@icunote} Unlike <code>java.text.DateFormatSymbols#getInstance</code>,
\r
201 * this method simply returns <code>new com.ibm.icu.text.DateFormatSymbols(locale)</code>.
\r
202 * ICU does not support <code>DateFormatSymbolsProvider</code> introduced in Java 6
\r
203 * or its equivalent implementation for now.
\r
205 * @param locale the locale.
\r
206 * @return A DateFormatSymbols instance.
\r
209 public static DateFormatSymbols getInstance(ULocale locale) {
\r
210 return new DateFormatSymbols(locale);
\r
214 * Returns an array of all locales for which the <code>getInstance</code> methods of
\r
215 * this class can return localized instances.
\r
217 * {@icunote} Unlike <code>java.text.DateFormatSymbols#getAvailableLocales</code>,
\r
218 * this method simply returns the array of <code>Locale</code>s available in this
\r
219 * class. ICU does not support <code>DateFormatSymbolsProvider</code> introduced in
\r
220 * Java 6 or its equivalent implementation for now.
\r
222 * @return An array of <code>Locale</code>s for which localized
\r
223 * <code>DateFormatSymbols</code> instances are available.
\r
226 public static Locale[] getAvailableLocales() {
\r
227 return ICUResourceBundle.getAvailableLocales();
\r
231 * {@icu} Returns an array of all locales for which the <code>getInstance</code>
\r
232 * methods of this class can return localized instances.
\r
234 * {@icunote} Unlike <code>java.text.DateFormatSymbols#getAvailableLocales</code>,
\r
235 * this method simply returns the array of <code>ULocale</code>s available in this
\r
236 * class. ICU does not support <code>DateFormatSymbolsProvider</code> introduced in
\r
237 * Java 6 or its equivalent implementation for now.
\r
239 * @return An array of <code>ULocale</code>s for which localized
\r
240 * <code>DateFormatSymbols</code> instances are available.
\r
241 * @draft ICU 3.8 (retain)
\r
242 * @provisional This API might change or be removed in a future release.
\r
244 public static ULocale[] getAvailableULocales() {
\r
245 return ICUResourceBundle.getAvailableULocales();
\r
249 * Era strings. For example: "AD" and "BC". An array of 2 strings,
\r
250 * indexed by <code>Calendar.BC</code> and <code>Calendar.AD</code>.
\r
253 String eras[] = null;
\r
256 * Era name strings. For example: "Anno Domini" and "Before Christ". An array of 2 strings,
\r
257 * indexed by <code>Calendar.BC</code> and <code>Calendar.AD</code>.
\r
260 String eraNames[] = null;
\r
263 * Narrow era names. For example: "A" and "B". An array of 2 strings,
\r
264 * indexed by <code>Calendar.BC</code> and <code>Calendar.AD</code>.
\r
267 String narrowEras[] = null;
\r
270 * Month strings. For example: "January", "February", etc. An array
\r
271 * of 13 strings (some calendars have 13 months), indexed by
\r
272 * <code>Calendar.JANUARY</code>, <code>Calendar.FEBRUARY</code>, etc.
\r
275 String months[] = null;
\r
278 * Short month strings. For example: "Jan", "Feb", etc. An array of
\r
279 * 13 strings (some calendars have 13 months), indexed by
\r
280 * <code>Calendar.JANUARY</code>, <code>Calendar.FEBRUARY</code>, etc.
\r
284 String shortMonths[] = null;
\r
287 * Narrow month strings. For example: "J", "F", etc. An array of
\r
288 * 13 strings (some calendars have 13 months), indexed by
\r
289 * <code>Calendar.JANUARY</code>, <code>Calendar.FEBRUARY</code>, etc.
\r
293 String narrowMonths[] = null;
\r
296 * Standalone month strings. For example: "January", "February", etc. An array
\r
297 * of 13 strings (some calendars have 13 months), indexed by
\r
298 * <code>Calendar.JANUARY</code>, <code>Calendar.FEBRUARY</code>, etc.
\r
301 String standaloneMonths[] = null;
\r
304 * Standalone short month strings. For example: "Jan", "Feb", etc. An array of
\r
305 * 13 strings (some calendars have 13 months), indexed by
\r
306 * <code>Calendar.JANUARY</code>, <code>Calendar.FEBRUARY</code>, etc.
\r
310 String standaloneShortMonths[] = null;
\r
313 * Standalone narrow month strings. For example: "J", "F", etc. An array of
\r
314 * 13 strings (some calendars have 13 months), indexed by
\r
315 * <code>Calendar.JANUARY</code>, <code>Calendar.FEBRUARY</code>, etc.
\r
319 String standaloneNarrowMonths[] = null;
\r
322 * Weekday strings. For example: "Sunday", "Monday", etc. An array
\r
323 * of 8 strings, indexed by <code>Calendar.SUNDAY</code>,
\r
324 * <code>Calendar.MONDAY</code>, etc.
\r
325 * The element <code>weekdays[0]</code> is ignored.
\r
328 String weekdays[] = null;
\r
331 * Short weekday strings. For example: "Sun", "Mon", etc. An array
\r
332 * of 8 strings, indexed by <code>Calendar.SUNDAY</code>,
\r
333 * <code>Calendar.MONDAY</code>, etc.
\r
334 * The element <code>shortWeekdays[0]</code> is ignored.
\r
337 String shortWeekdays[] = null;
\r
340 * Narrow weekday strings. For example: "S", "M", etc. An array
\r
341 * of 8 strings, indexed by <code>Calendar.SUNDAY</code>,
\r
342 * <code>Calendar.MONDAY</code>, etc.
\r
343 * The element <code>narrowWeekdays[0]</code> is ignored.
\r
346 String narrowWeekdays[] = null;
\r
349 * Standalone weekday strings. For example: "Sunday", "Monday", etc. An array
\r
350 * of 8 strings, indexed by <code>Calendar.SUNDAY</code>,
\r
351 * <code>Calendar.MONDAY</code>, etc.
\r
352 * The element <code>standaloneWeekdays[0]</code> is ignored.
\r
355 String standaloneWeekdays[] = null;
\r
358 * Standalone short weekday strings. For example: "Sun", "Mon", etc. An array
\r
359 * of 8 strings, indexed by <code>Calendar.SUNDAY</code>,
\r
360 * <code>Calendar.MONDAY</code>, etc.
\r
361 * The element <code>standaloneShortWeekdays[0]</code> is ignored.
\r
364 String standaloneShortWeekdays[] = null;
\r
367 * Standalone narrow weekday strings. For example: "S", "M", etc. An array
\r
368 * of 8 strings, indexed by <code>Calendar.SUNDAY</code>,
\r
369 * <code>Calendar.MONDAY</code>, etc.
\r
370 * The element <code>standaloneNarrowWeekdays[0]</code> is ignored.
\r
373 String standaloneNarrowWeekdays[] = null;
\r
376 * AM and PM strings. For example: "AM" and "PM". An array of
\r
377 * 2 strings, indexed by <code>Calendar.AM</code> and
\r
378 * <code>Calendar.PM</code>.
\r
381 String ampms[] = null;
\r
384 * Abbreviated quarter names. For example: "Q1", "Q2", "Q3", "Q4". An array
\r
385 * of 4 strings indexed by the month divided by 3.
\r
388 String shortQuarters[] = null;
\r
391 * Full quarter names. For example: "1st Quarter", "2nd Quarter", "3rd Quarter",
\r
392 * "4th Quarter". An array of 4 strings, indexed by the month divided by 3.
\r
395 String quarters[] = null;
\r
398 * Standalone abbreviated quarter names. For example: "Q1", "Q2", "Q3", "Q4". An array
\r
399 * of 4 strings indexed by the month divided by 3.
\r
402 String standaloneShortQuarters[] = null;
\r
405 * Standalone full quarter names. For example: "1st Quarter", "2nd Quarter", "3rd Quarter",
\r
406 * "4th Quarter". An array of 4 strings, indexed by the month divided by 3.
\r
409 String standaloneQuarters[] = null;
\r
412 * Pattern string used for localized time zone GMT format. For example, "GMT{0}"
\r
415 String gmtFormat = null;
\r
418 * Pattern strings used for formatting zone offset in a localized time zone GMT string.
\r
419 * This is 2x2 String array holding followings
\r
420 * [0][0] Negative H + m + s
\r
421 * [0][1] Negative H + m
\r
422 * [1][0] Positive H + m + s
\r
423 * [1][1] Positive H + m
\r
426 String gmtHourFormats[][] = null;
\r
429 * Localized names of time zones in this locale. This is a
\r
430 * two-dimensional array of strings of size <em>n</em> by <em>m</em>,
\r
431 * where <em>m</em> is at least 5 and up to 7. Each of the <em>n</em> rows is an
\r
432 * entry containing the localized names for a single <code>TimeZone</code>.
\r
433 * Each such row contains (with <code>i</code> ranging from
\r
434 * 0..<em>n</em>-1):
\r
436 * <li><code>zoneStrings[i][0]</code> - time zone ID</li>
\r
437 * <li><code>zoneStrings[i][1]</code> - long name of zone in standard
\r
439 * <li><code>zoneStrings[i][2]</code> - short name of zone in
\r
440 * standard time</li>
\r
441 * <li><code>zoneStrings[i][3]</code> - long name of zone in daylight
\r
442 * savings time</li>
\r
443 * <li><code>zoneStrings[i][4]</code> - short name of zone in daylight
\r
444 * savings time</li>
\r
445 * <li><code>zoneStrings[i][5]</code> - location name of zone</li>
\r
446 * <li><code>zoneStrings[i][6]</code> - long generic name of zone</li>
\r
447 * <li><code>zoneStrings[i][7]</code> - short generic of zone</li>
\r
448 * The zone ID is <em>not</em> localized; it corresponds to the ID
\r
449 * value associated with a system time zone object. All other entries
\r
450 * are localized names. If a zone does not implement daylight savings
\r
451 * time, the daylight savings time names are ignored.
\r
452 * <em>Note:</em>CLDR 1.5 introduced metazone and its historical mappings.
\r
453 * This simple two-dimensional array is no longer sufficient to represent
\r
454 * localized names and its historic changes. Since ICU 3.8.1, localized
\r
455 * zone names extracted from ICU locale data is stored in a ZoneStringFormat
\r
456 * instance. But we still need to support the old way of customizing
\r
457 * localized zone names, so we keep this field for the purpose.
\r
458 * @see com.ibm.icu.util.TimeZone
\r
461 private String zoneStrings[][] = null;
\r
464 * Since ICU 3.8.1, we use ZoneStringFormat to access localized
\r
465 * zone names. This field remains null unless setZoneStrings is
\r
468 private transient ZoneStringFormat zsformat = null;
\r
471 * Unlocalized date-time pattern characters. For example: 'y', 'd', etc.
\r
472 * All locales use the same unlocalized pattern characters.
\r
474 static final String patternChars = "GyMdkHmsSEDFwWahKzYeugAZvcLQqV";
\r
477 * Localized date-time pattern characters. For example, a locale may
\r
478 * wish to use 'u' rather than 'y' to represent years in its date format
\r
480 * This string must be exactly 18 characters long, with the index of
\r
481 * the characters described by <code>DateFormat.ERA_FIELD</code>,
\r
482 * <code>DateFormat.YEAR_FIELD</code>, etc. Thus, if the string were
\r
483 * "Xz...", then localized patterns would use 'X' for era and 'z' for year.
\r
486 String localPatternChars = null;
\r
488 /* use serialVersionUID from JDK 1.1.4 for interoperability */
\r
489 private static final long serialVersionUID = -5987973545549424702L;
\r
492 * Returns era strings. For example: "AD" and "BC".
\r
493 * @return the era strings.
\r
496 public String[] getEras() {
\r
497 return duplicate(eras);
\r
501 * Sets era strings. For example: "AD" and "BC".
\r
502 * @param newEras the new era strings.
\r
505 public void setEras(String[] newEras) {
\r
506 eras = duplicate(newEras);
\r
510 * {@icu} Returns era name strings. For example: "Anno Domini" and "Before Christ".
\r
511 * @return the era strings.
\r
514 public String[] getEraNames() {
\r
515 return duplicate(eraNames);
\r
519 * {@icu} Sets era name strings. For example: "Anno Domini" and "Before Christ".
\r
520 * @param newEraNames the new era strings.
\r
523 public void setEraNames(String[] newEraNames) {
\r
524 eraNames = duplicate(newEraNames);
\r
528 * Returns month strings. For example: "January", "February", etc.
\r
529 * @return the month strings.
\r
532 public String[] getMonths() {
\r
533 return duplicate(months);
\r
537 * Returns month strings. For example: "January", "February", etc.
\r
538 * @param context The month context, FORMAT or STANDALONE.
\r
539 * @param width The width or the returned month string,
\r
540 * either WIDE, ABBREVIATED, or NARROW.
\r
541 * @return the month strings.
\r
544 public String[] getMonths(int context, int width) {
\r
545 String [] returnValue = null;
\r
550 returnValue = months;
\r
553 returnValue = shortMonths;
\r
556 returnValue = narrowMonths;
\r
563 returnValue = standaloneMonths;
\r
566 returnValue = standaloneShortMonths;
\r
569 returnValue = standaloneNarrowMonths;
\r
574 return duplicate(returnValue);
\r
578 * Sets month strings. For example: "January", "February", etc.
\r
579 * @param newMonths the new month strings.
\r
582 public void setMonths(String[] newMonths) {
\r
583 months = duplicate(newMonths);
\r
587 * Sets month strings. For example: "January", "February", etc.
\r
588 * @param newMonths the new month strings.
\r
589 * @param context The formatting context, FORMAT or STANDALONE.
\r
590 * @param width The width of the month string,
\r
591 * either WIDE, ABBREVIATED, or NARROW.
\r
594 public void setMonths(String[] newMonths, int context, int width) {
\r
599 months = duplicate(newMonths);
\r
602 shortMonths = duplicate(newMonths);
\r
605 narrowMonths = duplicate(newMonths);
\r
612 standaloneMonths = duplicate(newMonths);
\r
615 standaloneShortMonths = duplicate(newMonths);
\r
618 standaloneNarrowMonths = duplicate(newMonths);
\r
626 * Returns short month strings. For example: "Jan", "Feb", etc.
\r
627 * @return the short month strings.
\r
630 public String[] getShortMonths() {
\r
631 return duplicate(shortMonths);
\r
635 * Sets short month strings. For example: "Jan", "Feb", etc.
\r
636 * @param newShortMonths the new short month strings.
\r
639 public void setShortMonths(String[] newShortMonths) {
\r
640 shortMonths = duplicate(newShortMonths);
\r
644 * Returns weekday strings. For example: "Sunday", "Monday", etc.
\r
645 * @return the weekday strings. Use <code>Calendar.SUNDAY</code>,
\r
646 * <code>Calendar.MONDAY</code>, etc. to index the result array.
\r
649 public String[] getWeekdays() {
\r
650 return duplicate(weekdays);
\r
654 * Returns weekday strings. For example: "Sunday", "Monday", etc.
\r
655 * @return the weekday strings. Use <code>Calendar.SUNDAY</code>,
\r
656 * <code>Calendar.MONDAY</code>, etc. to index the result array.
\r
657 * @param context Formatting context, either FORMAT or STANDALONE.
\r
658 * @param width Width of strings to be returned, either
\r
659 * WIDE, ABBREVIATED, or NARROW
\r
662 public String[] getWeekdays(int context, int width) {
\r
663 String [] returnValue = null;
\r
668 returnValue = weekdays;
\r
671 returnValue = shortWeekdays;
\r
674 returnValue = narrowWeekdays;
\r
681 returnValue = standaloneWeekdays;
\r
684 returnValue = standaloneShortWeekdays;
\r
687 returnValue = standaloneNarrowWeekdays;
\r
692 return duplicate(returnValue);
\r
696 * Sets weekday strings. For example: "Sunday", "Monday", etc.
\r
697 * @param newWeekdays The new weekday strings.
\r
698 * @param context The formatting context, FORMAT or STANDALONE.
\r
699 * @param width The width of the strings,
\r
700 * either WIDE, ABBREVIATED, or NARROW.
\r
703 public void setWeekdays(String[] newWeekdays, int context, int width) {
\r
708 weekdays = duplicate(newWeekdays);
\r
711 shortWeekdays = duplicate(newWeekdays);
\r
714 narrowWeekdays = duplicate(newWeekdays);
\r
721 standaloneWeekdays = duplicate(newWeekdays);
\r
724 standaloneShortWeekdays = duplicate(newWeekdays);
\r
727 standaloneNarrowWeekdays = duplicate(newWeekdays);
\r
735 * Sets weekday strings. For example: "Sunday", "Monday", etc.
\r
736 * @param newWeekdays the new weekday strings. The array should
\r
737 * be indexed by <code>Calendar.SUNDAY</code>,
\r
738 * <code>Calendar.MONDAY</code>, etc.
\r
741 public void setWeekdays(String[] newWeekdays) {
\r
742 weekdays = duplicate(newWeekdays);
\r
746 * Returns short weekday strings. For example: "Sun", "Mon", etc.
\r
747 * @return the short weekday strings. Use <code>Calendar.SUNDAY</code>,
\r
748 * <code>Calendar.MONDAY</code>, etc. to index the result array.
\r
751 public String[] getShortWeekdays() {
\r
752 return duplicate(shortWeekdays);
\r
756 * Sets short weekday strings. For example: "Sun", "Mon", etc.
\r
757 * @param newShortWeekdays the new short weekday strings. The array should
\r
758 * be indexed by <code>Calendar.SUNDAY</code>,
\r
759 * <code>Calendar.MONDAY</code>, etc.
\r
762 public void setShortWeekdays(String[] newShortWeekdays) {
\r
763 shortWeekdays = duplicate(newShortWeekdays);
\r
766 * {@icu} Returns quarter strings. For example: "1st Quarter", "2nd Quarter", etc.
\r
767 * @param context The quarter context, FORMAT or STANDALONE.
\r
768 * @param width The width or the returned quarter string,
\r
769 * either WIDE or ABBREVIATED. There are no NARROW quarters.
\r
770 * @return the quarter strings.
\r
773 public String[] getQuarters(int context, int width) {
\r
774 String [] returnValue = null;
\r
779 returnValue = quarters;
\r
782 returnValue = shortQuarters;
\r
785 returnValue = null;
\r
793 returnValue = standaloneQuarters;
\r
796 returnValue = standaloneShortQuarters;
\r
799 returnValue = null;
\r
804 return duplicate(returnValue);
\r
808 * {@icu} Sets quarter strings. For example: "1st Quarter", "2nd Quarter", etc.
\r
809 * @param newQuarters the new quarter strings.
\r
810 * @param context The formatting context, FORMAT or STANDALONE.
\r
811 * @param width The width of the quarter string,
\r
812 * either WIDE or ABBREVIATED. There are no NARROW quarters.
\r
815 public void setQuarters(String[] newQuarters, int context, int width) {
\r
820 quarters = duplicate(newQuarters);
\r
823 shortQuarters = duplicate(newQuarters);
\r
826 //narrowQuarters = duplicate(newQuarters);
\r
833 standaloneQuarters = duplicate(newQuarters);
\r
836 standaloneShortQuarters = duplicate(newQuarters);
\r
839 //standaloneNarrowQuarters = duplicate(newQuarters);
\r
847 * Returns am/pm strings. For example: "AM" and "PM".
\r
848 * @return the weekday strings.
\r
851 public String[] getAmPmStrings() {
\r
852 return duplicate(ampms);
\r
856 * Sets am/pm strings. For example: "AM" and "PM".
\r
857 * @param newAmpms the new ampm strings.
\r
860 public void setAmPmStrings(String[] newAmpms) {
\r
861 ampms = duplicate(newAmpms);
\r
865 * Returns timezone strings.
\r
866 * @return the timezone strings.
\r
869 public String[][] getZoneStrings() {
\r
870 if (zoneStrings != null) {
\r
871 return duplicate(zoneStrings);
\r
873 return ZoneStringFormat.getInstance(requestedLocale).getZoneStrings();
\r
877 * Sets timezone strings.
\r
878 * @param newZoneStrings the new timezone strings.
\r
881 public void setZoneStrings(String[][] newZoneStrings) {
\r
882 zoneStrings = duplicate(newZoneStrings);
\r
883 zsformat = new ZoneStringFormat(zoneStrings);
\r
887 * Returns localized date-time pattern characters. For example: 'u', 't', etc.
\r
889 * <p>Note: ICU no longer provides localized date-time pattern characters for a locale
\r
890 * starting ICU 3.8. This method returns the non-localized date-time pattern
\r
891 * characters unless user defined localized data is set by setLocalPatternChars.
\r
892 * @return the localized date-time pattern characters.
\r
895 public String getLocalPatternChars() {
\r
896 return localPatternChars;
\r
900 * Sets localized date-time pattern characters. For example: 'u', 't', etc.
\r
901 * @param newLocalPatternChars the new localized date-time
\r
902 * pattern characters.
\r
905 public void setLocalPatternChars(String newLocalPatternChars) {
\r
906 localPatternChars = newLocalPatternChars;
\r
913 public Object clone()
\r
916 DateFormatSymbols other = (DateFormatSymbols)super.clone();
\r
918 } catch (CloneNotSupportedException e) {
\r
920 throw new IllegalStateException();
\r
926 * Override hashCode.
\r
927 * Generates a hash code for the DateFormatSymbols object.
\r
930 public int hashCode() {
\r
931 // Is this sufficient?
\r
932 return requestedLocale.toString().hashCode();
\r
936 * Overrides equals.
\r
939 public boolean equals(Object obj)
\r
941 if (this == obj) return true;
\r
942 if (obj == null || getClass() != obj.getClass()) return false;
\r
943 DateFormatSymbols that = (DateFormatSymbols) obj;
\r
944 return (Utility.arrayEquals(eras, that.eras)
\r
945 && Utility.arrayEquals(eraNames, that.eraNames)
\r
946 && Utility.arrayEquals(months, that.months)
\r
947 && Utility.arrayEquals(shortMonths, that.shortMonths)
\r
948 && Utility.arrayEquals(narrowMonths, that.narrowMonths)
\r
949 && Utility.arrayEquals(standaloneMonths, that.standaloneMonths)
\r
950 && Utility.arrayEquals(standaloneShortMonths, that.standaloneShortMonths)
\r
951 && Utility.arrayEquals(standaloneNarrowMonths, that.standaloneNarrowMonths)
\r
952 && Utility.arrayEquals(weekdays, that.weekdays)
\r
953 && Utility.arrayEquals(shortWeekdays, that.shortWeekdays)
\r
954 && Utility.arrayEquals(narrowWeekdays, that.narrowWeekdays)
\r
955 && Utility.arrayEquals(standaloneWeekdays, that.standaloneWeekdays)
\r
956 && Utility.arrayEquals(standaloneShortWeekdays, that.standaloneShortWeekdays)
\r
957 && Utility.arrayEquals(standaloneNarrowWeekdays, that.standaloneNarrowWeekdays)
\r
958 && Utility.arrayEquals(ampms, that.ampms)
\r
959 && gmtFormat.equals(that.gmtFormat)
\r
960 && arrayOfArrayEquals(gmtHourFormats, that.gmtHourFormats)
\r
961 && arrayOfArrayEquals(zoneStrings, that.zoneStrings)
\r
962 // getDiplayName maps deprecated country and language codes to the current ones
\r
963 // too bad there is no way to get the current codes!
\r
964 // I thought canolicalize() would map the codes but .. alas! it doesn't.
\r
965 && requestedLocale.getDisplayName().equals(that.requestedLocale.getDisplayName())
\r
966 && Utility.arrayEquals(localPatternChars,
\r
967 that.localPatternChars));
\r
970 // =======================privates===============================
\r
973 * Useful constant for defining timezone offsets.
\r
975 static final int millisPerHour = 60*60*1000;
\r
977 // DateFormatSymbols cache
\r
978 private static ICUCache<String, DateFormatSymbols> DFSCACHE =
\r
979 new SimpleCache<String, DateFormatSymbols>();
\r
982 * Initializes format symbols for the locale and calendar type
\r
983 * @param desiredLocale The locale whose symbols are desired.
\r
984 * @param type The calendar type whose date format symbols are desired.
\r
987 //TODO: This protected seems to be marked as @stable accidentally.
\r
988 // We may need to deescalate this API to @internal.
\r
989 protected void initializeData(ULocale desiredLocale, String type)
\r
991 String key = desiredLocale.toString() + "+" + type;
\r
992 DateFormatSymbols dfs = DFSCACHE.get(key);
\r
994 // Initialize data from scratch put a clone of this instance into the cache
\r
995 CalendarData calData = new CalendarData(desiredLocale, type);
\r
996 initializeData(desiredLocale, calData);
\r
997 dfs = (DateFormatSymbols)this.clone();
\r
998 DFSCACHE.put(key, dfs);
\r
1000 initializeData(dfs);
\r
1005 * Initializes format symbols using another instance.
\r
1007 * TODO Clean up initialization methods for subclasses
\r
1009 void initializeData(DateFormatSymbols dfs) {
\r
1010 this.eras = dfs.eras;
\r
1011 this.eraNames = dfs.eraNames;
\r
1012 this.narrowEras = dfs.narrowEras;
\r
1013 this.months = dfs.months;
\r
1014 this.shortMonths = dfs.shortMonths;
\r
1015 this.narrowMonths = dfs.narrowMonths;
\r
1016 this.standaloneMonths = dfs.standaloneMonths;
\r
1017 this.standaloneShortMonths = dfs.standaloneShortMonths;
\r
1018 this.standaloneNarrowMonths = dfs.standaloneNarrowMonths;
\r
1019 this.weekdays = dfs.weekdays;
\r
1020 this.shortWeekdays = dfs.shortWeekdays;
\r
1021 this.narrowWeekdays = dfs.narrowWeekdays;
\r
1022 this.standaloneWeekdays = dfs.standaloneWeekdays;
\r
1023 this.standaloneShortWeekdays = dfs.standaloneShortWeekdays;
\r
1024 this.standaloneNarrowWeekdays = dfs.standaloneNarrowWeekdays;
\r
1025 this.ampms = dfs.ampms;
\r
1026 this.shortQuarters = dfs.shortQuarters;
\r
1027 this.quarters = dfs.quarters;
\r
1028 this.standaloneShortQuarters = dfs.standaloneShortQuarters;
\r
1029 this.standaloneQuarters = dfs.standaloneQuarters;
\r
1031 this.gmtFormat = dfs.gmtFormat;
\r
1032 this.gmtHourFormats = dfs.gmtHourFormats;
\r
1034 this.zoneStrings = dfs.zoneStrings; // always null at initialization time for now
\r
1035 this.localPatternChars = dfs.localPatternChars;
\r
1037 this.actualLocale = dfs.actualLocale;
\r
1038 this.validLocale = dfs.validLocale;
\r
1039 this.requestedLocale = dfs.requestedLocale;
\r
1043 * Initializes format symbols for the locale and calendar type
\r
1044 * @param desiredLocale The locale whose symbols are desired.
\r
1045 * @param calData The calendar resource data
\r
1047 * @deprecated This API is ICU internal only.
\r
1049 // This API was accidentally marked as @stable ICU 3.0 formerly.
\r
1050 protected void initializeData(ULocale desiredLocale, CalendarData calData)
\r
1052 // FIXME: cache only ResourceBundle. Hence every time, will do
\r
1053 // getObject(). This won't be necessary if the Resource itself
\r
1055 eras = calData.getEras("abbreviated");
\r
1058 eraNames = calData.getEras("wide");
\r
1060 catch (MissingResourceException e) {
\r
1061 eraNames = calData.getEras("abbreviated");
\r
1064 // NOTE: since the above code assumes that abbreviated
\r
1065 // era names exist, we make the same assumption here too.
\r
1067 narrowEras = calData.getEras("narrow");
\r
1068 } catch (MissingResourceException e) {
\r
1069 narrowEras = calData.getEras("abbreviated");
\r
1072 months = calData.getStringArray("monthNames", "wide");
\r
1073 shortMonths = calData.getStringArray("monthNames", "abbreviated");
\r
1076 narrowMonths = calData.getStringArray("monthNames", "narrow");
\r
1078 catch (MissingResourceException e) {
\r
1080 narrowMonths = calData.getStringArray("monthNames", "stand-alone", "narrow");
\r
1082 catch (MissingResourceException e1) {
\r
1083 narrowMonths = calData.getStringArray("monthNames", "abbreviated");
\r
1088 standaloneMonths = calData.getStringArray("monthNames", "stand-alone", "wide");
\r
1090 catch (MissingResourceException e) {
\r
1091 standaloneMonths = calData.getStringArray("monthNames", "format", "wide");
\r
1095 standaloneShortMonths =
\r
1096 calData.getStringArray("monthNames", "stand-alone", "abbreviated");
\r
1098 catch (MissingResourceException e) {
\r
1099 standaloneShortMonths = calData.getStringArray("monthNames", "format", "abbreviated");
\r
1103 standaloneNarrowMonths = calData.getStringArray("monthNames", "stand-alone", "narrow");
\r
1105 catch (MissingResourceException e) {
\r
1107 standaloneNarrowMonths = calData.getStringArray("monthNames", "format", "narrow");
\r
1109 catch (MissingResourceException e1) {
\r
1110 standaloneNarrowMonths =
\r
1111 calData.getStringArray("monthNames", "format", "abbreviated");
\r
1115 String[] lWeekdays = calData.getStringArray("dayNames", "wide");
\r
1116 weekdays = new String[8];
\r
1117 weekdays[0] = ""; // 1-based
\r
1118 System.arraycopy(lWeekdays, 0, weekdays, 1, lWeekdays.length);
\r
1120 String[] sWeekdays = calData.getStringArray("dayNames", "abbreviated");
\r
1121 shortWeekdays = new String[8];
\r
1122 shortWeekdays[0] = ""; // 1-based
\r
1123 System.arraycopy(sWeekdays, 0, shortWeekdays, 1, sWeekdays.length);
\r
1125 String [] nWeekdays = null;
\r
1127 nWeekdays = calData.getStringArray("dayNames", "narrow");
\r
1129 catch (MissingResourceException e) {
\r
1131 nWeekdays = calData.getStringArray("dayNames", "stand-alone", "narrow");
\r
1133 catch (MissingResourceException e1) {
\r
1134 nWeekdays = calData.getStringArray("dayNames", "abbreviated");
\r
1137 narrowWeekdays = new String[8];
\r
1138 narrowWeekdays[0] = ""; // 1-based
\r
1139 System.arraycopy(nWeekdays, 0, narrowWeekdays, 1, nWeekdays.length);
\r
1141 String [] saWeekdays = null;
\r
1143 saWeekdays = calData.getStringArray("dayNames", "stand-alone", "wide");
\r
1145 catch (MissingResourceException e) {
\r
1146 saWeekdays = calData.getStringArray("dayNames", "format", "wide");
\r
1148 standaloneWeekdays = new String[8];
\r
1149 standaloneWeekdays[0] = ""; // 1-based
\r
1150 System.arraycopy(saWeekdays, 0, standaloneWeekdays, 1, saWeekdays.length);
\r
1152 String [] ssWeekdays = null;
\r
1154 ssWeekdays = calData.getStringArray("dayNames", "stand-alone", "abbreviated");
\r
1156 catch (MissingResourceException e) {
\r
1157 ssWeekdays = calData.getStringArray("dayNames", "format", "abbreviated");
\r
1159 standaloneShortWeekdays = new String[8];
\r
1160 standaloneShortWeekdays[0] = ""; // 1-based
\r
1161 System.arraycopy(ssWeekdays, 0, standaloneShortWeekdays, 1, ssWeekdays.length);
\r
1163 String [] snWeekdays = null;
\r
1165 snWeekdays = calData.getStringArray("dayNames", "stand-alone", "narrow");
\r
1167 catch (MissingResourceException e) {
\r
1169 snWeekdays = calData.getStringArray("dayNames", "format", "narrow");
\r
1171 catch (MissingResourceException e1) {
\r
1172 snWeekdays = calData.getStringArray("dayNames", "format", "abbreviated");
\r
1175 standaloneNarrowWeekdays = new String[8];
\r
1176 standaloneNarrowWeekdays[0] = ""; // 1-based
\r
1177 System.arraycopy(snWeekdays, 0, standaloneNarrowWeekdays, 1, snWeekdays.length);
\r
1179 ampms = calData.getStringArray("AmPmMarkers");
\r
1181 quarters = calData.getStringArray("quarters", "wide");
\r
1182 shortQuarters = calData.getStringArray("quarters", "abbreviated");
\r
1185 standaloneQuarters = calData.getStringArray("quarters", "stand-alone", "wide");
\r
1187 catch (MissingResourceException e) {
\r
1188 standaloneQuarters = calData.getStringArray("quarters", "format", "wide");
\r
1192 standaloneShortQuarters = calData.getStringArray("quarters", "stand-alone", "abbreviated");
\r
1194 catch (MissingResourceException e) {
\r
1195 standaloneShortQuarters = calData.getStringArray("quarters", "format", "abbreviated");
\r
1198 // Initialize localized GMT format patterns
\r
1199 initializeGMTFormat(desiredLocale);
\r
1201 requestedLocale = desiredLocale;
\r
1203 ICUResourceBundle rb =
\r
1204 (ICUResourceBundle)UResourceBundle.getBundleInstance(
\r
1205 ICUResourceBundle.ICU_BASE_NAME, desiredLocale);
\r
1207 // Because localized date/time pattern characters will be obsolete in CLDR,
\r
1208 // we decided not to maintain localized pattern characters in ICU any more.
\r
1209 // We always use the base pattern characters by default. (ticket#5597)
\r
1211 //localPatternChars = rb.getString("localPatternChars");
\r
1212 localPatternChars = patternChars;
\r
1214 // TODO: obtain correct actual/valid locale later
\r
1215 ULocale uloc = rb.getULocale();
\r
1216 setLocale(uloc, uloc);
\r
1219 static final String DEFAULT_GMT_PATTERN = "GMT{0}";
\r
1220 static final String[][] DEFAULT_GMT_HOUR_PATTERNS = {
\r
1221 {"-HH:mm:ss", "-HH:mm"},
\r
1222 {"+HH:mm:ss", "+HH:mm"}
\r
1226 * Initializes localized GMT format patterns
\r
1228 private void initializeGMTFormat(ULocale desiredLocale) {
\r
1229 // TimeZone format localization is not included in CalendarData
\r
1230 gmtFormat = ZoneMeta.getTZLocalizationInfo(desiredLocale, ZoneMeta.GMT);
\r
1231 if (gmtFormat == null) {
\r
1232 gmtFormat = DEFAULT_GMT_PATTERN;
\r
1236 String offsetHM = ZoneMeta.getTZLocalizationInfo(desiredLocale, ZoneMeta.HOUR);
\r
1237 gmtHourFormats = new String[2][2];
\r
1238 int sepIdx = offsetHM.indexOf(';');
\r
1239 if (sepIdx != -1) {
\r
1240 gmtHourFormats[OFFSET_POSITIVE][OFFSET_HM] = offsetHM.substring(0, sepIdx);
\r
1241 gmtHourFormats[OFFSET_NEGATIVE][OFFSET_HM] = offsetHM.substring(sepIdx + 1);
\r
1243 gmtHourFormats[OFFSET_POSITIVE][OFFSET_HM] = "+HH:mm";
\r
1244 gmtHourFormats[OFFSET_NEGATIVE][OFFSET_HM] = "-HH:mm";
\r
1246 // CLDR 1.5 does not have GMT offset pattern including second field.
\r
1247 // For now, append "ss" to the end.
\r
1248 if (gmtHourFormats[OFFSET_POSITIVE][OFFSET_HM].indexOf(':') != -1) {
\r
1249 gmtHourFormats[OFFSET_POSITIVE][OFFSET_HMS] =
\r
1250 gmtHourFormats[OFFSET_POSITIVE][OFFSET_HM] + ":ss";
\r
1251 } else if (gmtHourFormats[OFFSET_POSITIVE][OFFSET_HM].indexOf('.') != -1) {
\r
1252 gmtHourFormats[OFFSET_POSITIVE][OFFSET_HMS] =
\r
1253 gmtHourFormats[OFFSET_POSITIVE][OFFSET_HM] + ".ss";
\r
1255 gmtHourFormats[OFFSET_POSITIVE][OFFSET_HMS] =
\r
1256 gmtHourFormats[OFFSET_POSITIVE][OFFSET_HM] + "ss";
\r
1258 if (gmtHourFormats[OFFSET_NEGATIVE][OFFSET_HM].indexOf(':') != -1) {
\r
1259 gmtHourFormats[OFFSET_NEGATIVE][OFFSET_HMS] =
\r
1260 gmtHourFormats[OFFSET_NEGATIVE][OFFSET_HM] + ":ss";
\r
1261 } else if (gmtHourFormats[OFFSET_NEGATIVE][OFFSET_HM].indexOf('.') != -1) {
\r
1262 gmtHourFormats[OFFSET_NEGATIVE][OFFSET_HMS] =
\r
1263 gmtHourFormats[OFFSET_NEGATIVE][OFFSET_HM] + ".ss";
\r
1265 gmtHourFormats[OFFSET_NEGATIVE][OFFSET_HMS] =
\r
1266 gmtHourFormats[OFFSET_NEGATIVE][OFFSET_HM] + "ss";
\r
1268 } catch (MissingResourceException e) {
\r
1269 gmtHourFormats = DEFAULT_GMT_HOUR_PATTERNS;
\r
1273 private static final boolean arrayOfArrayEquals(Object[][] aa1, Object[][]aa2) {
\r
1274 if (aa1 == aa2) { // both are null
\r
1277 if (aa1 == null || aa2 == null) { // one is null and the other is not
\r
1280 if (aa1.length != aa2.length) {
\r
1283 boolean equal = true;
\r
1284 for (int i = 0; i < aa1.length; i++) {
\r
1285 equal = Utility.arrayEquals(aa1[i], aa2[i]);
\r
1294 * Package local method (for now) to get localized GMT format pattern.
\r
1296 String getGmtFormat() {
\r
1300 static final int OFFSET_HMS = 0;
\r
1301 static final int OFFSET_HM = 1;
\r
1302 static final int OFFSET_NEGATIVE = 0;
\r
1303 static final int OFFSET_POSITIVE = 1;
\r
1306 * Package local method (for now) to get hour format pattern used by localized
\r
1309 String getGmtHourFormat(int sign, int width) {
\r
1310 return gmtHourFormats[sign][width];
\r
1314 * Package local method to access ZoneStringFormat used by this
\r
1315 * DateFormatSymbols instance.
\r
1317 ZoneStringFormat getZoneStringFormat() {
\r
1318 if (zsformat != null) {
\r
1321 if (zoneStrings != null) {
\r
1322 zsformat = new ZoneStringFormat(zoneStrings);
\r
1325 // We do not want to hold the reference to an instance of
\r
1326 // ZoneStringFormat. An instance of ZoneStringFormat for
\r
1327 // a locale is shared and cached in ZoneStringFormat class
\r
1329 return ZoneStringFormat.getInstance(requestedLocale);
\r
1333 * save the input locale
\r
1335 private ULocale requestedLocale;
\r
1338 * Clones an array of Strings.
\r
1339 * @param srcArray the source array to be cloned.
\r
1340 * @return a cloned array.
\r
1342 private final String[] duplicate(String[] srcArray)
\r
1344 return srcArray.clone();
\r
1347 private final String[][] duplicate(String[][] srcArray)
\r
1349 String[][] aCopy = new String[srcArray.length][];
\r
1350 for (int i = 0; i < srcArray.length; ++i)
\r
1351 aCopy[i] = duplicate(srcArray[i]);
\r
1356 * Compares the equality of the two arrays of String.
\r
1357 * @param current this String array.
\r
1358 * @param other that String array.
\r
1359 private final boolean equals(String[] current, String[] other)
\r
1361 int count = current.length;
\r
1363 for (int i = 0; i < count; ++i)
\r
1364 if (!current[i].equals(other[i]))
\r
1370 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
\r
1373 * Returns the {@link DateFormatSymbols} object that should be used to format a
\r
1374 * calendar system's dates in the given locale.
\r
1376 * <b>Subclassing:</b><br>
\r
1377 * When creating a new Calendar subclass, you must create the
\r
1378 * {@link ResourceBundle ResourceBundle}
\r
1379 * containing its {@link DateFormatSymbols DateFormatSymbols} in a specific place.
\r
1380 * The resource bundle name is based on the calendar's fully-specified
\r
1381 * class name, with ".resources" inserted at the end of the package name
\r
1382 * (just before the class name) and "Symbols" appended to the end.
\r
1383 * For example, the bundle corresponding to "com.ibm.icu.util.HebrewCalendar"
\r
1384 * is "com.ibm.icu.impl.data.HebrewCalendarSymbols".
\r
1386 * Within the ResourceBundle, this method searches for five keys:
\r
1388 * <li><b>DayNames</b> -
\r
1389 * An array of strings corresponding to each possible
\r
1390 * value of the <code>DAY_OF_WEEK</code> field. Even though
\r
1391 * <code>DAY_OF_WEEK</code> starts with <code>SUNDAY</code> = 1,
\r
1392 * This array is 0-based; the name for Sunday goes in the
\r
1393 * first position, at index 0. If this key is not found
\r
1394 * in the bundle, the day names are inherited from the
\r
1395 * default <code>DateFormatSymbols</code> for the requested locale.
\r
1397 * <li><b>DayAbbreviations</b> -
\r
1398 * An array of abbreviated day names corresponding
\r
1399 * to the values in the "DayNames" array. If this key
\r
1400 * is not found in the resource bundle, the "DayNames"
\r
1401 * values are used instead. If neither key is found,
\r
1402 * the day abbreviations are inherited from the default
\r
1403 * <code>DateFormatSymbols</code> for the locale.
\r
1405 * <li><b>MonthNames</b> -
\r
1406 * An array of strings corresponding to each possible
\r
1407 * value of the <code>MONTH</code> field. If this key is not found
\r
1408 * in the bundle, the month names are inherited from the
\r
1409 * default <code>DateFormatSymbols</code> for the requested locale.
\r
1411 * <li><b>MonthAbbreviations</b> -
\r
1412 * An array of abbreviated day names corresponding
\r
1413 * to the values in the "MonthNames" array. If this key
\r
1414 * is not found in the resource bundle, the "MonthNames"
\r
1415 * values are used instead. If neither key is found,
\r
1416 * the day abbreviations are inherited from the default
\r
1417 * <code>DateFormatSymbols</code> for the locale.
\r
1419 * <li><b>Eras</b> -
\r
1420 * An array of strings corresponding to each possible
\r
1421 * value of the <code>ERA</code> field. If this key is not found
\r
1422 * in the bundle, the era names are inherited from the
\r
1423 * default <code>DateFormatSymbols</code> for the requested locale.
\r
1426 * @param cal The calendar system whose date format symbols are desired.
\r
1427 * @param locale The locale whose symbols are desired.
\r
1429 * @see DateFormatSymbols#DateFormatSymbols(java.util.Locale)
\r
1432 public DateFormatSymbols(Calendar cal, Locale locale) {
\r
1433 initializeData(ULocale.forLocale(locale), cal.getType());
\r
1437 * Returns the {@link DateFormatSymbols} object that should be used to format a
\r
1438 * calendar system's dates in the given locale.
\r
1440 * <b>Subclassing:</b><br>
\r
1441 * When creating a new Calendar subclass, you must create the
\r
1442 * {@link ResourceBundle ResourceBundle}
\r
1443 * containing its {@link DateFormatSymbols DateFormatSymbols} in a specific place.
\r
1444 * The resource bundle name is based on the calendar's fully-specified
\r
1445 * class name, with ".resources" inserted at the end of the package name
\r
1446 * (just before the class name) and "Symbols" appended to the end.
\r
1447 * For example, the bundle corresponding to "com.ibm.icu.util.HebrewCalendar"
\r
1448 * is "com.ibm.icu.impl.data.HebrewCalendarSymbols".
\r
1450 * Within the ResourceBundle, this method searches for five keys:
\r
1452 * <li><b>DayNames</b> -
\r
1453 * An array of strings corresponding to each possible
\r
1454 * value of the <code>DAY_OF_WEEK</code> field. Even though
\r
1455 * <code>DAY_OF_WEEK</code> starts with <code>SUNDAY</code> = 1,
\r
1456 * This array is 0-based; the name for Sunday goes in the
\r
1457 * first position, at index 0. If this key is not found
\r
1458 * in the bundle, the day names are inherited from the
\r
1459 * default <code>DateFormatSymbols</code> for the requested locale.
\r
1461 * <li><b>DayAbbreviations</b> -
\r
1462 * An array of abbreviated day names corresponding
\r
1463 * to the values in the "DayNames" array. If this key
\r
1464 * is not found in the resource bundle, the "DayNames"
\r
1465 * values are used instead. If neither key is found,
\r
1466 * the day abbreviations are inherited from the default
\r
1467 * <code>DateFormatSymbols</code> for the locale.
\r
1469 * <li><b>MonthNames</b> -
\r
1470 * An array of strings corresponding to each possible
\r
1471 * value of the <code>MONTH</code> field. If this key is not found
\r
1472 * in the bundle, the month names are inherited from the
\r
1473 * default <code>DateFormatSymbols</code> for the requested locale.
\r
1475 * <li><b>MonthAbbreviations</b> -
\r
1476 * An array of abbreviated day names corresponding
\r
1477 * to the values in the "MonthNames" array. If this key
\r
1478 * is not found in the resource bundle, the "MonthNames"
\r
1479 * values are used instead. If neither key is found,
\r
1480 * the day abbreviations are inherited from the default
\r
1481 * <code>DateFormatSymbols</code> for the locale.
\r
1483 * <li><b>Eras</b> -
\r
1484 * An array of strings corresponding to each possible
\r
1485 * value of the <code>ERA</code> field. If this key is not found
\r
1486 * in the bundle, the era names are inherited from the
\r
1487 * default <code>DateFormatSymbols</code> for the requested locale.
\r
1490 * @param cal The calendar system whose date format symbols are desired.
\r
1491 * @param locale The ulocale whose symbols are desired.
\r
1493 * @see DateFormatSymbols#DateFormatSymbols(java.util.Locale)
\r
1496 public DateFormatSymbols(Calendar cal, ULocale locale) {
\r
1497 initializeData(locale, cal.getType());
\r
1501 * Variant of DateFormatSymbols(Calendar, Locale) that takes the Calendar class
\r
1502 * instead of a Calandar instance.
\r
1503 * @see #DateFormatSymbols(Calendar, Locale)
\r
1506 public DateFormatSymbols(Class<? extends Calendar> calendarClass, Locale locale) {
\r
1507 this(calendarClass, ULocale.forLocale(locale));
\r
1511 * Variant of DateFormatSymbols(Calendar, ULocale) that takes the Calendar class
\r
1512 * instead of a Calandar instance.
\r
1513 * @see #DateFormatSymbols(Calendar, Locale)
\r
1516 public DateFormatSymbols(Class<? extends Calendar> calendarClass, ULocale locale) {
\r
1517 String fullName = calendarClass.getName();
\r
1518 int lastDot = fullName.lastIndexOf('.');
\r
1519 String className = fullName.substring(lastDot+1);
\r
1520 String calType = className.replaceAll("Calendar", "").toLowerCase();
\r
1522 initializeData(locale, calType);
\r
1526 * Fetches a custom calendar's DateFormatSymbols out of the given resource
\r
1527 * bundle. Symbols that are not overridden are inherited from the
\r
1528 * default DateFormatSymbols for the locale.
\r
1529 * @see DateFormatSymbols#DateFormatSymbols(java.util.Locale)
\r
1532 public DateFormatSymbols(ResourceBundle bundle, Locale locale) {
\r
1533 this(bundle, ULocale.forLocale(locale));
\r
1537 * Fetches a custom calendar's DateFormatSymbols out of the given resource
\r
1538 * bundle. Symbols that are not overridden are inherited from the
\r
1539 * default DateFormatSymbols for the locale.
\r
1540 * @see DateFormatSymbols#DateFormatSymbols(java.util.Locale)
\r
1543 public DateFormatSymbols(ResourceBundle bundle, ULocale locale) {
\r
1544 initializeData(locale,
\r
1545 new CalendarData((ICUResourceBundle)bundle, CalendarUtil.getCalendarType(locale)));
\r
1549 * Finds the ResourceBundle containing the date format information for
\r
1550 * a specified calendar subclass in a given locale.
\r
1552 * The resource bundle name is based on the calendar's fully-specified
\r
1553 * class name, with ".resources" inserted at the end of the package name
\r
1554 * (just before the class name) and "Symbols" appended to the end.
\r
1555 * For example, the bundle corresponding to "com.ibm.icu.util.HebrewCalendar"
\r
1556 * is "com.ibm.icu.impl.data.HebrewCalendarSymbols".
\r
1558 * <b>Note:</b>Because of the structural changes in the ICU locale bundle,
\r
1559 * this API no longer works as described. This method always returns null.
\r
1560 * @deprecated ICU 4.0
\r
1562 // This API was formerly @stable ICU 2.0
\r
1563 static public ResourceBundle getDateFormatBundle(Class<? extends Calendar> calendarClass,
\r
1565 throws MissingResourceException {
\r
1570 * Finds the ResourceBundle containing the date format information for
\r
1571 * a specified calendar subclass in a given locale.
\r
1573 * The resource bundle name is based on the calendar's fully-specified
\r
1574 * class name, with ".resources" inserted at the end of the package name
\r
1575 * (just before the class name) and "Symbols" appended to the end.
\r
1576 * For example, the bundle corresponding to "com.ibm.icu.util.HebrewCalendar"
\r
1577 * is "com.ibm.icu.impl.data.HebrewCalendarSymbols".
\r
1579 * <b>Note:</b>Because of the structural changes in the ICU locale bundle,
\r
1580 * this API no longer works as described. This method always returns null.
\r
1581 * @deprecated ICU 4.0
\r
1583 // This API was formerly @stable ICU 3.2
\r
1584 static public ResourceBundle getDateFormatBundle(Class<? extends Calendar> calendarClass,
\r
1586 throws MissingResourceException {
\r
1591 * Variant of getDateFormatBundle(java.lang.Class, java.util.Locale) that takes
\r
1592 * a Calendar instance instead of a Calendar class.
\r
1594 * <b>Note:</b>Because of the structural changes in the ICU locale bundle,
\r
1595 * this API no longer works as described. This method always returns null.
\r
1596 * @see #getDateFormatBundle(java.lang.Class, java.util.Locale)
\r
1597 * @deprecated ICU 4.0
\r
1599 // This API was formerly @stable ICU 2.2
\r
1600 public static ResourceBundle getDateFormatBundle(Calendar cal, Locale locale)
\r
1601 throws MissingResourceException {
\r
1606 * Variant of getDateFormatBundle(java.lang.Class, java.util.Locale) that takes
\r
1607 * a Calendar instance instead of a Calendar class.
\r
1609 * <b>Note:</b>Because of the structural changes in the ICU locale bundle,
\r
1610 * this API no longer works as described. This method always returns null.
\r
1611 * @see #getDateFormatBundle(java.lang.Class, java.util.Locale)
\r
1612 * @deprecated ICU 4.0
\r
1614 // This API was formerly @stable ICU 3.2
\r
1615 public static ResourceBundle getDateFormatBundle(Calendar cal, ULocale locale)
\r
1616 throws MissingResourceException {
\r
1620 // -------- BEGIN ULocale boilerplate --------
\r
1623 * Returns the locale that was used to create this object, or null.
\r
1624 * This may may differ from the locale requested at the time of
\r
1625 * this object's creation. For example, if an object is created
\r
1626 * for locale <tt>en_US_CALIFORNIA</tt>, the actual data may be
\r
1627 * drawn from <tt>en</tt> (the <i>actual</i> locale), and
\r
1628 * <tt>en_US</tt> may be the most specific locale that exists (the
\r
1629 * <i>valid</i> locale).
\r
1631 * <p>Note: This method will be implemented in ICU 3.0; ICU 2.8
\r
1632 * contains a partial preview implementation. The * <i>actual</i>
\r
1633 * locale is returned correctly, but the <i>valid</i> locale is
\r
1634 * not, in most cases.
\r
1635 * @param type type of information requested, either {@link
\r
1636 * com.ibm.icu.util.ULocale#VALID_LOCALE} or {@link
\r
1637 * com.ibm.icu.util.ULocale#ACTUAL_LOCALE}.
\r
1638 * @return the information specified by <i>type</i>, or null if
\r
1639 * this object was not constructed from locale data.
\r
1640 * @see com.ibm.icu.util.ULocale
\r
1641 * @see com.ibm.icu.util.ULocale#VALID_LOCALE
\r
1642 * @see com.ibm.icu.util.ULocale#ACTUAL_LOCALE
\r
1643 * @draft ICU 2.8 (retain)
\r
1644 * @provisional This API might change or be removed in a future release.
\r
1646 public final ULocale getLocale(ULocale.Type type) {
\r
1647 return type == ULocale.ACTUAL_LOCALE ?
\r
1648 this.actualLocale : this.validLocale;
\r
1652 * Sets information about the locales that were used to create this
\r
1653 * object. If the object was not constructed from locale data,
\r
1654 * both arguments should be set to null. Otherwise, neither
\r
1655 * should be null. The actual locale must be at the same level or
\r
1656 * less specific than the valid locale. This method is intended
\r
1657 * for use by factories or other entities that create objects of
\r
1659 * @param valid the most specific locale containing any resource
\r
1661 * @param actual the locale containing data used to construct this
\r
1663 * @see com.ibm.icu.util.ULocale
\r
1664 * @see com.ibm.icu.util.ULocale#VALID_LOCALE
\r
1665 * @see com.ibm.icu.util.ULocale#ACTUAL_LOCALE
\r
1667 final void setLocale(ULocale valid, ULocale actual) {
\r
1668 // Change the following to an assertion later
\r
1669 if ((valid == null) != (actual == null)) {
\r
1671 throw new IllegalArgumentException();
\r
1674 // Another check we could do is that the actual locale is at
\r
1675 // the same level or less specific than the valid locale.
\r
1676 this.validLocale = valid;
\r
1677 this.actualLocale = actual;
\r
1681 * The most specific locale containing any resource data, or null.
\r
1682 * @see com.ibm.icu.util.ULocale
\r
1684 private ULocale validLocale;
\r
1687 * The locale containing data used to construct this object, or
\r
1689 * @see com.ibm.icu.util.ULocale
\r
1691 private ULocale actualLocale;
\r
1693 // -------- END ULocale boilerplate --------
\r
1696 * 3.8 or older version did not have localized GMT format
\r
1699 private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
\r
1700 stream.defaultReadObject();
\r
1701 if (gmtFormat == null) {
\r
1702 initializeGMTFormat(requestedLocale);
\r