1 /****************************************************************************
2 * Copyright (C) 2000-2013, International Business Machines Corporation and
3 * others. All Rights Reserved.
4 ****************************************************************************
7 package com.ibm.icu.text;
9 import java.util.Locale;
11 import com.ibm.icu.impl.CalendarData;
12 import com.ibm.icu.util.Calendar;
13 import com.ibm.icu.util.ChineseCalendar;
14 import com.ibm.icu.util.ULocale;
15 import com.ibm.icu.util.ULocale.Category;
18 * A subclass of {@link DateFormatSymbols} for {@link ChineseDateFormat}.
19 * This class contains additional symbols corresponding to the
20 * <code>ChineseCalendar.IS_LEAP_MONTH</code> field.
22 * @see ChineseDateFormat
23 * @see com.ibm.icu.util.ChineseCalendar
27 public class ChineseDateFormatSymbols extends DateFormatSymbols {
28 // Generated by serialver from JDK 1.4.1_01
29 static final long serialVersionUID = 6827816119783952890L;
32 * Package-private array that ChineseDateFormat needs to be able to
38 * Construct a ChineseDateFormatSymbols for the default <code>FORMAT</code> locale.
39 * @see Category#FORMAT
42 public ChineseDateFormatSymbols() {
43 this(ULocale.getDefault(Category.FORMAT));
47 * Construct a ChineseDateFormatSymbols for the provided locale.
48 * @param locale the locale
51 public ChineseDateFormatSymbols(Locale locale) {
52 super(ChineseCalendar.class, ULocale.forLocale(locale));
56 * Construct a ChineseDateFormatSymbols for the provided locale.
57 * @param locale the locale
60 public ChineseDateFormatSymbols(ULocale locale) {
61 super(ChineseCalendar.class, locale);
65 * Construct a ChineseDateFormatSymbols for the provided calendar and locale.
66 * @param cal the Calendar
67 * @param locale the locale
70 public ChineseDateFormatSymbols(Calendar cal, Locale locale) {
71 // NPE is thrown here when cal is null, like the super class does
72 super(cal.getClass(), locale);
76 * Construct a ChineseDateFormatSymbols for the provided calendar and locale.
77 * @param cal the Calendar
78 * @param locale the locale
81 public ChineseDateFormatSymbols(Calendar cal, ULocale locale) {
82 // NPE is thrown here when cal is null, like the super class does
83 super(cal.getClass(), locale);
90 public String getLeapMonth(int leap) {
91 return isLeapMonth[leap];
98 protected void initializeData(ULocale loc, CalendarData calData) {
99 super.initializeData(loc, calData);
100 initializeIsLeapMonth();
103 void initializeData(DateFormatSymbols dfs) {
104 super.initializeData(dfs);
105 if (dfs instanceof ChineseDateFormatSymbols) {
106 // read-only array, no need to clone
107 this.isLeapMonth = ((ChineseDateFormatSymbols)dfs).isLeapMonth;
109 initializeIsLeapMonth();
113 private void initializeIsLeapMonth() {
114 // The old way, obsolete:
115 //isLeapMonth = calData.getStringArray("isLeapMonth");
116 // The new way to fake this for backward compatibility (no longer used to format/parse):
118 isLeapMonth = new String[2];
120 isLeapMonth[1] = (leapMonthPatterns != null)? leapMonthPatterns[DT_LEAP_MONTH_PATTERN_FORMAT_WIDE].replace("{0}", ""): "";