Home | History | Annotate | Download | only in text
      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 android.icu.text;
     10 
     11 import java.io.InvalidObjectException;
     12 import java.text.FieldPosition;
     13 import java.util.Locale;
     14 
     15 import android.icu.util.Calendar;
     16 import android.icu.util.ChineseCalendar;
     17 import android.icu.util.TimeZone;
     18 import android.icu.util.ULocale;
     19 
     20 /**
     21  * A concrete {@link DateFormat} for {@link android.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 android.icu.util.ChineseCalendar
     44  * @see ChineseDateFormatSymbols
     45  * @author Alan Liu
     46  * @deprecated ICU 50 Use SimpleDateFormat instead.
     47  * @hide Only a subset of ICU is exposed in Android
     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
     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
     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
     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 Android
    124      */
    125     @Override
    126     @Deprecated
    127     protected void subFormat(StringBuffer buf,
    128                              char ch, int count, int beginOffset,
    129                              int fieldNum, DisplayContext capitalizationContext,
    130                              FieldPosition pos,
    131                              Calendar cal) {
    132 
    133         // Logic to handle 'G' for chinese calendar is moved into SimpleDateFormat,
    134         // and obsolete pattern char 'l' is now ignored in SimpleDateFormat, so we
    135         // just use its implementation
    136         super.subFormat(buf, ch, count, beginOffset, fieldNum, capitalizationContext, pos, cal);
    137 
    138         // The following is no longer an issue for this subclass...
    139         // TODO: add code to set FieldPosition for 'G' and 'l' fields. This
    140         // is a DESIGN FLAW -- subclasses shouldn't have to duplicate the
    141         // code that handles this at the end of SimpleDateFormat.subFormat.
    142         // The logic should be moved up into SimpleDateFormat.format.
    143     }
    144 
    145     /**
    146      * {@inheritDoc}
    147      *
    148      * @deprecated ICU 50
    149      */
    150     @Deprecated
    151     @Override
    152     protected int subParse(String text, int start, char ch, int count, boolean obeyCount, boolean allowNegative,
    153             boolean[] ambiguousYear, Calendar cal) {
    154         // Logic to handle numeric 'G' eras for chinese calendar, and to skip special 2-digit year
    155         // handling for chinese calendar, is moved into SimpleDateFormat, so delete here.
    156         // Obsolete pattern char 'l' is now ignored for parsing in SimpleDateFormat, no handling
    157         // needed here.
    158         // So just use SimpleDateFormat implementation for this.
    159         // just use its implementation
    160         return super.subParse(text, start, ch, count, obeyCount, allowNegative, ambiguousYear, cal);
    161     }
    162 
    163     /**
    164      * {@inheritDoc}
    165      *
    166      * @deprecated ICU 50
    167      */
    168     @Override
    169     @Deprecated
    170     protected DateFormat.Field patternCharToDateFormatField(char ch) {
    171         // no longer any field corresponding to pattern char 'l'
    172         return super.patternCharToDateFormatField(ch);
    173     }
    174 
    175     /**
    176      * The instances of this inner class are used as attribute keys and values
    177      * in AttributedCharacterIterator that
    178      * ChineseDateFormat.formatToCharacterIterator() method returns.
    179      * <p>
    180      * There is no public constructor to this class, the only instances are the
    181      * constants defined here.
    182      * <p>
    183      * @deprecated ICU 50
    184      */
    185     @Deprecated
    186     public static class Field extends DateFormat.Field {
    187 
    188         private static final long serialVersionUID = -5102130532751400330L;
    189 
    190         /**
    191          * Constant identifying the leap month marker.
    192          * @deprecated ICU 50 This field is only used by the deprecated ChineseDateFormat class.
    193          */
    194         @Deprecated
    195         public static final Field IS_LEAP_MONTH = new Field("is leap month", ChineseCalendar.IS_LEAP_MONTH);
    196 
    197         /**
    198          * Constructs a <code>ChineseDateFormat.Field</code> with the given name and
    199          * the <code>ChineseCalendar</code> field which this attribute represents.
    200          * Use -1 for <code>calendarField</code> if this field does not have a
    201          * corresponding <code>ChineseCalendar</code> field.
    202          *
    203          * @param name          Name of the attribute
    204          * @param calendarField <code>Calendar</code> field constant
    205          *
    206          * @deprecated ICU 50
    207          */
    208         @Deprecated
    209         protected Field(String name, int calendarField) {
    210             super(name, calendarField);
    211         }
    212 
    213         /**
    214          * Returns the <code>Field</code> constant that corresponds to the <code>
    215          * ChineseCalendar</code> field <code>calendarField</code>.  If there is no
    216          * corresponding <code>Field</code> is available, null is returned.
    217          *
    218          * @param calendarField <code>ChineseCalendar</code> field constant
    219          * @return <code>Field</code> associated with the <code>calendarField</code>,
    220          * or null if no associated <code>Field</code> is available.
    221          * @throws IllegalArgumentException if <code>calendarField</code> is not
    222          * a valid <code>Calendar</code> field constant.
    223          *
    224          * @deprecated ICU 50
    225          */
    226         @Deprecated
    227         public static DateFormat.Field ofCalendarField(int calendarField) {
    228             // Should we remove the following, since there is no longer a specific
    229             // date format field for leap month (since 'l' pattern char is obsolete)?
    230             if (calendarField == ChineseCalendar.IS_LEAP_MONTH) {
    231                 return IS_LEAP_MONTH;
    232             }
    233             return DateFormat.Field.ofCalendarField(calendarField);
    234         }
    235 
    236         /**
    237          * {@inheritDoc}
    238          *
    239          * @deprecated ICU 50
    240          */
    241         @Override
    242         @Deprecated
    243         ///CLOVER:OFF
    244         protected Object readResolve() throws InvalidObjectException {
    245             if (this.getClass() != ChineseDateFormat.Field.class) {
    246                 throw new InvalidObjectException("A subclass of ChineseDateFormat.Field must implement readResolve.");
    247             }
    248             if (this.getName().equals(IS_LEAP_MONTH.getName())) {
    249                 return IS_LEAP_MONTH;
    250             } else {
    251                 throw new InvalidObjectException("Unknown attribute name.");
    252             }
    253         }
    254         ///CLOVER:ON
    255     }
    256 }
    257