1 /* GENERATED SOURCE. DO NOT MODIFY. */ 2 // © 2016 and later: Unicode, Inc. and others. 3 // License & terms of use: http://www.unicode.org/copyright.html#License 4 /********************************************************************* 5 * Copyright (C) 2000-2014, International Business Machines Corporation and 6 * others. All Rights Reserved. 7 ********************************************************************* 8 */ 9 package ohos.global.icu.text; 10 11 import java.io.InvalidObjectException; 12 import java.text.FieldPosition; 13 import java.util.Locale; 14 15 import ohos.global.icu.util.Calendar; 16 import ohos.global.icu.util.ChineseCalendar; 17 import ohos.global.icu.util.TimeZone; 18 import ohos.global.icu.util.ULocale; 19 20 /** 21 * A concrete {@link DateFormat} for {@link ohos.global.icu.util.ChineseCalendar}. 22 * This class handles a <code>ChineseCalendar</code>-specific field, 23 * <code>ChineseCalendar.IS_LEAP_MONTH</code>. It also redefines the 24 * handling of two fields, <code>ERA</code> and <code>YEAR</code>. The 25 * former is displayed numerically, instead of symbolically, since it is 26 * the numeric cycle number in <code>ChineseCalendar</code>. The latter is 27 * numeric, as before, but has no special 2-digit Y2K behavior. 28 * 29 * <p>With regard to <code>ChineseCalendar.IS_LEAP_MONTH</code>, this 30 * class handles parsing specially. If no string symbol is found at all, 31 * this is taken as equivalent to an <code>IS_LEAP_MONTH</code> value of 32 * zero. This allows formats to display a special string (e.g., "*") for 33 * leap months, but no string for normal months. 34 * 35 * <p>Summary of field changes vs. {@link SimpleDateFormat}:<pre> 36 * Symbol Meaning Presentation Example 37 * ------ ------- ------------ ------- 38 * G cycle (Number) 78 39 * y year of cycle (1..60) (Number) 17 40 * l is leap month (Text) 4637 41 * </pre> 42 * 43 * @see ohos.global.icu.util.ChineseCalendar 44 * @see ChineseDateFormatSymbols 45 * @author Alan Liu 46 * @deprecated ICU 50 Use SimpleDateFormat instead. 47 * @hide exposed on OHOS 48 */ 49 @Deprecated 50 public class ChineseDateFormat extends SimpleDateFormat { 51 // Generated by serialver from JDK 1.4.1_01 52 static final long serialVersionUID = -4610300753104099899L; 53 54 // TODO Finish the constructors 55 56 /** 57 * Construct a ChineseDateFormat from a date format pattern and locale 58 * @param pattern the pattern 59 * @param locale the locale 60 * @deprecated ICU 50 61 */ 62 @Deprecated ChineseDateFormat(String pattern, Locale locale)63 public ChineseDateFormat(String pattern, Locale locale) { 64 this(pattern, ULocale.forLocale(locale)); 65 } 66 67 /** 68 * Construct a ChineseDateFormat from a date format pattern and locale 69 * @param pattern the pattern 70 * @param locale the locale 71 * @deprecated ICU 50 72 */ 73 @Deprecated ChineseDateFormat(String pattern, ULocale locale)74 public ChineseDateFormat(String pattern, ULocale locale) { 75 this(pattern, null, locale); 76 } 77 78 /** 79 * Construct a ChineseDateFormat from a date format pattern, numbering system override and locale 80 * @param pattern the pattern 81 * @param override The override string. A numbering system override string can take one of the following forms: 82 * 1). If just a numbering system name is specified, it applies to all numeric fields in the date format pattern. 83 * 2). To specify an alternate numbering system on a field by field basis, use the field letters from the pattern 84 * followed by an = sign, followed by the numbering system name. For example, to specify that just the year 85 * be formatted using Hebrew digits, use the override "y=hebr". Multiple overrides can be specified in a single 86 * string by separating them with a semi-colon. For example, the override string "m=thai;y=deva" would format using 87 * Thai digits for the month and Devanagari digits for the year. 88 * @param locale the locale 89 * @deprecated ICU 50 90 */ 91 @Deprecated ChineseDateFormat(String pattern, String override, ULocale locale)92 public ChineseDateFormat(String pattern, String override, ULocale locale) { 93 super(pattern, new ChineseDateFormatSymbols(locale), 94 new ChineseCalendar(TimeZone.getDefault(), locale), locale, true, override); 95 } 96 97 // NOTE: This API still exists; we just inherit it from SimpleDateFormat 98 // as of ICU 3.0 99 // /** 100 // * @stable ICU 2.0 101 // */ 102 // protected String subFormat(char ch, int count, int beginOffset, 103 // FieldPosition pos, DateFormatSymbols formatData, 104 // Calendar cal) { 105 // switch (ch) { 106 // case 'G': // 'G' - ERA 107 // return zeroPaddingNumber(cal.get(Calendar.ERA), 1, 9); 108 // case 'l': // 'l' - IS_LEAP_MONTH 109 // { 110 // ChineseDateFormatSymbols symbols = 111 // (ChineseDateFormatSymbols) formatData; 112 // return symbols.getLeapMonth(cal.get( 113 // ChineseCalendar.IS_LEAP_MONTH)); 114 // } 115 // default: 116 // return super.subFormat(ch, count, beginOffset, pos, formatData, cal); 117 // } 118 // } 119 120 /** 121 * {@inheritDoc} 122 * @deprecated This API is ICU internal only. 123 * @hide draft / provisional / internal are hidden on OHOS 124 */ 125 @Override 126 @Deprecated subFormat(StringBuffer buf, char ch, int count, int beginOffset, int fieldNum, DisplayContext capitalizationContext, FieldPosition pos, char patternCharToOutput, Calendar cal)127 protected void subFormat(StringBuffer buf, 128 char ch, int count, int beginOffset, 129 int fieldNum, DisplayContext capitalizationContext, 130 FieldPosition pos, 131 char patternCharToOutput, 132 Calendar cal) { 133 134 // Logic to handle 'G' for chinese calendar is moved into SimpleDateFormat, 135 // and obsolete pattern char 'l' is now ignored in SimpleDateFormat, so we 136 // just use its implementation 137 super.subFormat(buf, ch, count, beginOffset, fieldNum, capitalizationContext, pos, patternCharToOutput, cal); 138 139 // The following is no longer an issue for this subclass... 140 // TODO: add code to set FieldPosition for 'G' and 'l' fields. This 141 // is a DESIGN FLAW -- subclasses shouldn't have to duplicate the 142 // code that handles this at the end of SimpleDateFormat.subFormat. 143 // The logic should be moved up into SimpleDateFormat.format. 144 } 145 146 /** 147 * {@inheritDoc} 148 * 149 * @deprecated ICU 50 150 */ 151 @Deprecated 152 @Override subParse(String text, int start, char ch, int count, boolean obeyCount, boolean allowNegative, boolean[] ambiguousYear, Calendar cal)153 protected int subParse(String text, int start, char ch, int count, boolean obeyCount, boolean allowNegative, 154 boolean[] ambiguousYear, Calendar cal) { 155 // Logic to handle numeric 'G' eras for chinese calendar, and to skip special 2-digit year 156 // handling for chinese calendar, is moved into SimpleDateFormat, so delete here. 157 // Obsolete pattern char 'l' is now ignored for parsing in SimpleDateFormat, no handling 158 // needed here. 159 // So just use SimpleDateFormat implementation for this. 160 // just use its implementation 161 return super.subParse(text, start, ch, count, obeyCount, allowNegative, ambiguousYear, cal); 162 } 163 164 /** 165 * {@inheritDoc} 166 * 167 * @deprecated ICU 50 168 */ 169 @Override 170 @Deprecated patternCharToDateFormatField(char ch)171 protected DateFormat.Field patternCharToDateFormatField(char ch) { 172 // no longer any field corresponding to pattern char 'l' 173 return super.patternCharToDateFormatField(ch); 174 } 175 176 /** 177 * The instances of this inner class are used as attribute keys and values 178 * in AttributedCharacterIterator that 179 * ChineseDateFormat.formatToCharacterIterator() method returns. 180 * <p> 181 * There is no public constructor to this class, the only instances are the 182 * constants defined here. 183 * <p> 184 * @deprecated ICU 50 185 * @hide exposed on OHOS 186 */ 187 @Deprecated 188 public static class Field extends DateFormat.Field { 189 190 private static final long serialVersionUID = -5102130532751400330L; 191 192 /** 193 * Constant identifying the leap month marker. 194 * @deprecated ICU 50 This field is only used by the deprecated ChineseDateFormat class. 195 */ 196 @Deprecated 197 public static final Field IS_LEAP_MONTH = new Field("is leap month", ChineseCalendar.IS_LEAP_MONTH); 198 199 /** 200 * Constructs a <code>ChineseDateFormat.Field</code> with the given name and 201 * the <code>ChineseCalendar</code> field which this attribute represents. 202 * Use -1 for <code>calendarField</code> if this field does not have a 203 * corresponding <code>ChineseCalendar</code> field. 204 * 205 * @param name Name of the attribute 206 * @param calendarField <code>Calendar</code> field constant 207 * 208 * @deprecated ICU 50 209 */ 210 @Deprecated Field(String name, int calendarField)211 protected Field(String name, int calendarField) { 212 super(name, calendarField); 213 } 214 215 /** 216 * Returns the <code>Field</code> constant that corresponds to the <code> 217 * ChineseCalendar</code> field <code>calendarField</code>. If there is no 218 * corresponding <code>Field</code> is available, null is returned. 219 * 220 * @param calendarField <code>ChineseCalendar</code> field constant 221 * @return <code>Field</code> associated with the <code>calendarField</code>, 222 * or null if no associated <code>Field</code> is available. 223 * @throws IllegalArgumentException if <code>calendarField</code> is not 224 * a valid <code>Calendar</code> field constant. 225 * 226 * @deprecated ICU 50 227 */ 228 @Deprecated ofCalendarField(int calendarField)229 public static DateFormat.Field ofCalendarField(int calendarField) { 230 // Should we remove the following, since there is no longer a specific 231 // date format field for leap month (since 'l' pattern char is obsolete)? 232 if (calendarField == ChineseCalendar.IS_LEAP_MONTH) { 233 return IS_LEAP_MONTH; 234 } 235 return DateFormat.Field.ofCalendarField(calendarField); 236 } 237 238 /** 239 * {@inheritDoc} 240 * 241 * @deprecated ICU 50 242 */ 243 @Override 244 @Deprecated 245 ///CLOVER:OFF readResolve()246 protected Object readResolve() throws InvalidObjectException { 247 if (this.getClass() != ChineseDateFormat.Field.class) { 248 throw new InvalidObjectException("A subclass of ChineseDateFormat.Field must implement readResolve."); 249 } 250 if (this.getName().equals(IS_LEAP_MONTH.getName())) { 251 return IS_LEAP_MONTH; 252 } else { 253 throw new InvalidObjectException("Unknown attribute name."); 254 } 255 } 256 ///CLOVER:ON 257 } 258 } 259