1/****************************************************************************
2 * Copyright (C) 2000-2014, International Business Machines Corporation and
3 * others. All Rights Reserved.
4 ****************************************************************************
5 */
6
7package com.ibm.icu.text;
8
9import java.util.Locale;
10
11import com.ibm.icu.impl.CalendarData;
12import com.ibm.icu.util.Calendar;
13import com.ibm.icu.util.ChineseCalendar;
14import com.ibm.icu.util.ULocale;
15import com.ibm.icu.util.ULocale.Category;
16
17/**
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.
21 *
22 * @see ChineseDateFormat
23 * @see com.ibm.icu.util.ChineseCalendar
24 * @author Alan Liu
25 * @deprecated ICU 50
26 */
27@Deprecated
28public class ChineseDateFormatSymbols extends DateFormatSymbols {
29    // Generated by serialver from JDK 1.4.1_01
30    static final long serialVersionUID = 6827816119783952890L;
31
32    /*
33     * Package-private array that ChineseDateFormat needs to be able to
34     * read.
35     */
36    String[] isLeapMonth;
37
38    /**
39     * Construct a ChineseDateFormatSymbols for the default <code>FORMAT</code> locale.
40     * @see Category#FORMAT
41     * @deprecated ICU 50
42     */
43    @Deprecated
44    public ChineseDateFormatSymbols() {
45        this(ULocale.getDefault(Category.FORMAT));
46    }
47
48    /**
49     * Construct a ChineseDateFormatSymbols for the provided locale.
50     * @param locale the locale
51     * @deprecated ICU 50
52     */
53    @Deprecated
54    public ChineseDateFormatSymbols(Locale locale) {
55        super(ChineseCalendar.class, ULocale.forLocale(locale));
56    }
57
58    /**
59     * Construct a ChineseDateFormatSymbols for the provided locale.
60     * @param locale the locale
61     * @deprecated ICU 50
62     */
63    @Deprecated
64    public ChineseDateFormatSymbols(ULocale locale) {
65        super(ChineseCalendar.class, locale);
66    }
67
68    /**
69     * Construct a ChineseDateFormatSymbols for the provided calendar and locale.
70     * @param cal the Calendar
71     * @param locale the locale
72     * @deprecated ICU 50
73     */
74    @Deprecated
75    public ChineseDateFormatSymbols(Calendar cal, Locale locale) {
76        // NPE is thrown here when cal is null, like the super class does
77        super(cal.getClass(), locale);
78    }
79
80    /**
81     * Construct a ChineseDateFormatSymbols for the provided calendar and locale.
82     * @param cal the Calendar
83     * @param locale the locale
84     * @deprecated ICU 50
85     */
86    @Deprecated
87    public ChineseDateFormatSymbols(Calendar cal, ULocale locale) {
88        // NPE is thrown here when cal is null, like the super class does
89        super(cal.getClass(), locale);
90    }
91
92    // New API
93    /**
94     * @deprecated ICU 50
95     */
96    @Deprecated
97    public String getLeapMonth(int leap) {
98        return isLeapMonth[leap];
99    }
100
101    /**
102     * {@inheritDoc}
103     * @deprecated ICU 50
104     */
105    @Deprecated
106    protected void initializeData(ULocale loc, CalendarData calData) {
107        super.initializeData(loc, calData);
108        initializeIsLeapMonth();
109    }
110
111    void initializeData(DateFormatSymbols dfs) {
112        super.initializeData(dfs);
113        if (dfs instanceof ChineseDateFormatSymbols) {
114            // read-only array, no need to clone
115            this.isLeapMonth = ((ChineseDateFormatSymbols)dfs).isLeapMonth;
116        } else {
117            initializeIsLeapMonth();
118        }
119    }
120
121    private void initializeIsLeapMonth() {
122        // The old way, obsolete:
123        //isLeapMonth = calData.getStringArray("isLeapMonth");
124        // The new way to fake this for backward compatibility (no longer used to format/parse):
125
126        isLeapMonth = new String[2];
127        isLeapMonth[0] = "";
128        isLeapMonth[1] = (leapMonthPatterns != null)? leapMonthPatterns[DT_LEAP_MONTH_PATTERN_FORMAT_WIDE].replace("{0}", ""): "";
129    }
130}
131