]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - jars/icu4j-52_1/main/classes/core/src/com/ibm/icu/text/ChineseDateFormat.java
Upgrade ICU4J.
[Dictionary.git] / jars / icu4j-52_1 / main / classes / core / src / com / ibm / icu / text / ChineseDateFormat.java
similarity index 76%
rename from jars/icu4j-4_8_1_1/main/classes/core/src/com/ibm/icu/text/ChineseDateFormat.java
rename to jars/icu4j-52_1/main/classes/core/src/com/ibm/icu/text/ChineseDateFormat.java
index 0691a2dac644ff1e4fdc3c612b62d72ead1fbfa6..869d76b833f3949150938daa35bbafec79d1881a 100644 (file)
@@ -1,5 +1,5 @@
 /*********************************************************************
- * Copyright (C) 2000-2011, International Business Machines Corporation and
+ * Copyright (C) 2000-2012, International Business Machines Corporation and
  * others. All Rights Reserved.
  *********************************************************************
  */
@@ -7,10 +7,8 @@ package com.ibm.icu.text;
 
 import java.io.InvalidObjectException;
 import java.text.FieldPosition;
-import java.text.ParsePosition;
 import java.util.Locale;
 
-import com.ibm.icu.impl.PatternProps;
 import com.ibm.icu.util.Calendar;
 import com.ibm.icu.util.ChineseCalendar;
 import com.ibm.icu.util.TimeZone;
@@ -42,7 +40,7 @@ import com.ibm.icu.util.ULocale;
  * @see com.ibm.icu.util.ChineseCalendar
  * @see ChineseDateFormatSymbols
  * @author Alan Liu
- * @stable ICU 2.0
+ * @deprecated ICU 50 Use SimpleDateFormat instead.
  */
 public class ChineseDateFormat extends SimpleDateFormat {
     // Generated by serialver from JDK 1.4.1_01
@@ -54,7 +52,7 @@ public class ChineseDateFormat extends SimpleDateFormat {
      * Construct a ChineseDateFormat from a date format pattern and locale
      * @param pattern the pattern
      * @param locale the locale
-     * @stable ICU 2.0
+     * @deprecated ICU 50
      */
    public ChineseDateFormat(String pattern, Locale locale) {
        this(pattern, ULocale.forLocale(locale));
@@ -64,7 +62,7 @@ public class ChineseDateFormat extends SimpleDateFormat {
      * Construct a ChineseDateFormat from a date format pattern and locale
      * @param pattern the pattern
      * @param locale the locale
-     * @stable ICU 3.2
+     * @deprecated ICU 50
      */
    public ChineseDateFormat(String pattern, ULocale locale) {
        this(pattern, null, locale);
@@ -81,7 +79,7 @@ public class ChineseDateFormat extends SimpleDateFormat {
      *         string by separating them with a semi-colon. For example, the override string "m=thai;y=deva" would format using
      *         Thai digits for the month and Devanagari digits for the year.
      * @param locale the locale
-     * @stable ICU 4.2
+     * @deprecated ICU 50
      */
    public ChineseDateFormat(String pattern, String override, ULocale locale) {
        super(pattern, new ChineseDateFormatSymbols(locale), 
@@ -118,22 +116,16 @@ public class ChineseDateFormat extends SimpleDateFormat {
      */
     protected void subFormat(StringBuffer buf,
                              char ch, int count, int beginOffset,
+                             int fieldNum, DisplayContext capitalizationContext,
                              FieldPosition pos,
                              Calendar cal) {
 
-        switch (ch) {
-        case 'G': // 'G' - ERA
-            zeroPaddingNumber(numberFormat,buf, cal.get(Calendar.ERA), 1, 9);
-            break;
-        case 'l': // 'l' - IS_LEAP_MONTH
-            buf.append(((ChineseDateFormatSymbols) getSymbols()).
-                       getLeapMonth(cal.get(ChineseCalendar.IS_LEAP_MONTH)));
-            break;
-        default:
-            super.subFormat(buf, ch, count, beginOffset, pos, cal);
-            break;
-        }
+        // Logic to handle 'G' for chinese calendar is moved into SimpleDateFormat,
+        // and obsolete pattern char 'l' is now ignored in SimpleDateFormat, so we
+        // just use its implementation
+        super.subFormat(buf, ch, count, beginOffset, fieldNum, capitalizationContext, pos, cal);
 
+        // The following is no longer an issue for this subclass...
         // TODO: add code to set FieldPosition for 'G' and 'l' fields. This
         // is a DESIGN FLAW -- subclasses shouldn't have to duplicate the
         // code that handles this at the end of SimpleDateFormat.subFormat.
@@ -143,67 +135,26 @@ public class ChineseDateFormat extends SimpleDateFormat {
     /**
      * {@inheritDoc}
      * 
-     * @stable ICU 2.0
+     * @deprecated ICU 50
      */
     protected int subParse(String text, int start, char ch, int count, boolean obeyCount, boolean allowNegative,
             boolean[] ambiguousYear, Calendar cal) {
-        if (ch != 'G' && ch != 'l' && ch != 'y') {
-            return super.subParse(text, start, ch, count, obeyCount, allowNegative, ambiguousYear, cal);
-        }
-
-        // Skip whitespace
-        start = PatternProps.skipWhiteSpace(text, start);
-
-        ParsePosition pos = new ParsePosition(start);
-
-        switch (ch) {
-        case 'G': // 'G' - ERA
-        case 'y': // 'y' - YEAR, but without the 2-digit Y2K adjustment
-        {
-            Number number = null;
-            if (obeyCount) {
-                if ((start + count) > text.length()) {
-                    return -start;
-                }
-                number = numberFormat.parse(text.substring(0, start + count), pos);
-            } else {
-                number = numberFormat.parse(text, pos);
-            }
-            if (number == null) {
-                return -start;
-            }
-            int value = number.intValue();
-            cal.set(ch == 'G' ? Calendar.ERA : Calendar.YEAR, value);
-            return pos.getIndex();
-        }
-        case 'l': // 'l' - IS_LEAP_MONTH
-        {
-            ChineseDateFormatSymbols symbols = (ChineseDateFormatSymbols) getSymbols();
-            int result = matchString(text, start, ChineseCalendar.IS_LEAP_MONTH, symbols.isLeapMonth, cal);
-            // Treat the absence of any matching string as setting
-            // IS_LEAP_MONTH to false.
-            if (result < 0) {
-                cal.set(ChineseCalendar.IS_LEAP_MONTH, 0);
-                result = start;
-            }
-            return result;
-        }
-            ///CLOVER:OFF
-        default:
-            return 0; // This can never happen
-            ///CLOVER:ON
-        }
+        // Logic to handle numeric 'G' eras for chinese calendar, and to skip special 2-digit year
+        // handling for chinese calendar, is moved into SimpleDateFormat, so delete here.
+        // Obsolete pattern char 'l' is now ignored for parsing in SimpleDateFormat, no handling
+        // needed here.
+        // So just use SimpleDateFormat implementation for this.
+        // just use its implementation
+        return super.subParse(text, start, ch, count, obeyCount, allowNegative, ambiguousYear, cal);
     }
 
     /**
      * {@inheritDoc}
      * 
-     * @stable ICU 3.8
+     * @deprecated ICU 50
      */
     protected DateFormat.Field patternCharToDateFormatField(char ch) {
-        if (ch == 'l') {
-            return ChineseDateFormat.Field.IS_LEAP_MONTH;
-        }
+        // no longer any field corresponding to pattern char 'l'
         return super.patternCharToDateFormatField(ch);
     }
 
@@ -215,7 +166,7 @@ public class ChineseDateFormat extends SimpleDateFormat {
      * There is no public constructor to this class, the only instances are the
      * constants defined here.
      * <p>
-     * @stable ICU 3.8
+     * @deprecated ICU 50
      */
     public static class Field extends DateFormat.Field {
 
@@ -223,7 +174,7 @@ public class ChineseDateFormat extends SimpleDateFormat {
 
         /**
          * Constant identifying the leap month marker.
-         * @stable ICU 3.8
+         * @deprecated ICU 50 This field is only used by the deprecated ChineseDateFormat class.
          */
         public static final Field IS_LEAP_MONTH = new Field("is leap month", ChineseCalendar.IS_LEAP_MONTH);
 
@@ -236,7 +187,7 @@ public class ChineseDateFormat extends SimpleDateFormat {
          * @param name          Name of the attribute
          * @param calendarField <code>Calendar</code> field constant
          * 
-         * @stable ICU 3.8
+         * @deprecated ICU 50
          */
         protected Field(String name, int calendarField) {
             super(name, calendarField);
@@ -253,9 +204,11 @@ public class ChineseDateFormat extends SimpleDateFormat {
          * @throws IllegalArgumentException if <code>calendarField</code> is not
          * a valid <code>Calendar</code> field constant.
          * 
-         * @stable ICU 3.8
+         * @deprecated ICU 50
          */
         public static DateFormat.Field ofCalendarField(int calendarField) {
+            // Should we remove the following, since there is no longer a specific
+            // date format field for leap month (since 'l' pattern char is obsolete)?
             if (calendarField == ChineseCalendar.IS_LEAP_MONTH) {
                 return IS_LEAP_MONTH;
             }
@@ -265,7 +218,7 @@ public class ChineseDateFormat extends SimpleDateFormat {
         /**
          * {@inheritDoc}
          * 
-         * @stable ICU 3.8
+         * @deprecated ICU 50
          */
         ///CLOVER:OFF
         protected Object readResolve() throws InvalidObjectException {