-//##header\r
-/*********************************************************************\r
- * Copyright (C) 2000-2009, International Business Machines Corporation and\r
- * others. All Rights Reserved.\r
- *********************************************************************\r
- */\r
-package com.ibm.icu.text;\r
-import com.ibm.icu.util.*;\r
-import com.ibm.icu.impl.Utility;\r
-\r
-import java.text.FieldPosition;\r
-import java.text.ParsePosition;\r
-import java.util.Locale;\r
-//#if defined(FOUNDATION10) || defined(J2SE13)\r
-//#else\r
-import java.io.InvalidObjectException;\r
-//#endif\r
-\r
-/**\r
- * A concrete {@link DateFormat} for {@link com.ibm.icu.util.ChineseCalendar}.\r
- * This class handles a <code>ChineseCalendar</code>-specific field,\r
- * <code>ChineseCalendar.IS_LEAP_MONTH</code>. It also redefines the\r
- * handling of two fields, <code>ERA</code> and <code>YEAR</code>. The\r
- * former is displayed numerically, instead of symbolically, since it is\r
- * the numeric cycle number in <code>ChineseCalendar</code>. The latter is\r
- * numeric, as before, but has no special 2-digit Y2K behavior.\r
- *\r
- * <p>With regard to <code>ChineseCalendar.IS_LEAP_MONTH</code>, this\r
- * class handles parsing specially. If no string symbol is found at all,\r
- * this is taken as equivalent to an <code>IS_LEAP_MONTH</code> value of\r
- * zero. This allows formats to display a special string (e.g., "*") for\r
- * leap months, but no string for normal months.\r
- *\r
- * <p>Summary of field changes vs. {@link SimpleDateFormat}:<pre>\r
- * Symbol Meaning Presentation Example\r
- * ------ ------- ------------ -------\r
- * G cycle (Number) 78\r
- * y year of cycle (1..60) (Number) 17\r
- * l is leap month (Text) 4637\r
- * </pre>\r
- *\r
- * @see com.ibm.icu.util.ChineseCalendar\r
- * @see ChineseDateFormatSymbols\r
- * @author Alan Liu\r
- * @stable ICU 2.0\r
- */\r
-public class ChineseDateFormat extends SimpleDateFormat {\r
- // Generated by serialver from JDK 1.4.1_01\r
- static final long serialVersionUID = -4610300753104099899L;\r
- \r
- // TODO Finish the constructors\r
-\r
- /**\r
- * Construct a ChineseDateFormat from a date format pattern and locale\r
- * @param pattern the pattern\r
- * @param locale the locale\r
- * @stable ICU 2.0\r
- */\r
- public ChineseDateFormat(String pattern, Locale locale) {\r
- this(pattern, ULocale.forLocale(locale));\r
- }\r
-\r
- /**\r
- * Construct a ChineseDateFormat from a date format pattern and locale\r
- * @param pattern the pattern\r
- * @param locale the locale\r
- * @stable ICU 3.2\r
- */\r
- public ChineseDateFormat(String pattern, ULocale locale) {\r
- this(pattern, null, locale);\r
- }\r
-\r
- /**\r
- * Construct a ChineseDateFormat from a date format pattern and locale\r
- * @param pattern the pattern\r
- * @param locale the locale\r
- * @stable ICU 3.2\r
- */\r
- public ChineseDateFormat(String pattern, String override, ULocale locale) {\r
- super(pattern, new ChineseDateFormatSymbols(locale), \r
- new ChineseCalendar(TimeZone.getDefault(), locale), locale, true, override);\r
- }\r
-\r
-// NOTE: This API still exists; we just inherit it from SimpleDateFormat\r
-// as of ICU 3.0\r
-// /**\r
-// * @stable ICU 2.0\r
-// */\r
-// protected String subFormat(char ch, int count, int beginOffset,\r
-// FieldPosition pos, DateFormatSymbols formatData,\r
-// Calendar cal) {\r
-// switch (ch) {\r
-// case 'G': // 'G' - ERA\r
-// return zeroPaddingNumber(cal.get(Calendar.ERA), 1, 9);\r
-// case 'l': // 'l' - IS_LEAP_MONTH\r
-// {\r
-// ChineseDateFormatSymbols symbols =\r
-// (ChineseDateFormatSymbols) formatData;\r
-// return symbols.getLeapMonth(cal.get(\r
-// ChineseCalendar.IS_LEAP_MONTH));\r
-// }\r
-// default:\r
-// return super.subFormat(ch, count, beginOffset, pos, formatData, cal);\r
-// }\r
-// } \r
-\r
- /**\r
- * {@inheritDoc}\r
- * @internal\r
- * @deprecated This API is ICU internal only.\r
- */\r
- protected void subFormat(StringBuffer buf,\r
- char ch, int count, int beginOffset,\r
- FieldPosition pos,\r
- Calendar cal) {\r
-\r
- switch (ch) {\r
- case 'G': // 'G' - ERA\r
- zeroPaddingNumber(numberFormat,buf, cal.get(Calendar.ERA), 1, 9);\r
- break;\r
- case 'l': // 'l' - IS_LEAP_MONTH\r
- buf.append(((ChineseDateFormatSymbols) getSymbols()).\r
- getLeapMonth(cal.get(ChineseCalendar.IS_LEAP_MONTH)));\r
- break;\r
- default:\r
- super.subFormat(buf, ch, count, beginOffset, pos, cal);\r
- break;\r
- }\r
-\r
- // TODO: add code to set FieldPosition for 'G' and 'l' fields. This\r
- // is a DESIGN FLAW -- subclasses shouldn't have to duplicate the\r
- // code that handles this at the end of SimpleDateFormat.subFormat.\r
- // The logic should be moved up into SimpleDateFormat.format.\r
- }\r
-\r
- /**\r
- * {@inheritDoc}\r
- * @stable ICU 2.0\r
- */\r
- protected int subParse(String text, int start, char ch, int count,\r
- boolean obeyCount, boolean allowNegative, boolean[] ambiguousYear, Calendar cal) {\r
- if (ch != 'G' && ch != 'l' && ch != 'y') {\r
- return super.subParse(text, start, ch, count, obeyCount, allowNegative, ambiguousYear, cal);\r
- }\r
-\r
- // Skip whitespace\r
- start = Utility.skipWhitespace(text, start);\r
-\r
- ParsePosition pos = new ParsePosition(start);\r
-\r
- switch (ch) {\r
- case 'G': // 'G' - ERA\r
- case 'y': // 'y' - YEAR, but without the 2-digit Y2K adjustment\r
- {\r
- Number number = null;\r
- if (obeyCount) {\r
- if ((start+count) > text.length()) {\r
- return -start;\r
- }\r
- number = numberFormat.parse(text.substring(0, start+count), pos);\r
- } else {\r
- number = numberFormat.parse(text, pos);\r
- }\r
- if (number == null) {\r
- return -start;\r
- }\r
- int value = number.intValue();\r
- cal.set(ch == 'G' ? Calendar.ERA : Calendar.YEAR, value);\r
- return pos.getIndex();\r
- }\r
- case 'l': // 'l' - IS_LEAP_MONTH\r
- {\r
- ChineseDateFormatSymbols symbols =\r
- (ChineseDateFormatSymbols) getSymbols();\r
- int result = matchString(text, start, ChineseCalendar.IS_LEAP_MONTH,\r
- symbols.isLeapMonth, cal);\r
- // Treat the absence of any matching string as setting\r
- // IS_LEAP_MONTH to false.\r
- if (result<0) {\r
- cal.set(ChineseCalendar.IS_LEAP_MONTH, 0);\r
- result = start;\r
- }\r
- return result;\r
- }\r
- default:\r
- ///CLOVER:OFF\r
- return 0; // This can never happen\r
- ///CLOVER:ON\r
- }\r
- }\r
-\r
-//#if defined(FOUNDATION10) || defined(J2SE13)\r
-//#else\r
- /**\r
- * {@inheritDoc}\r
- * \r
- * @stable ICU 3.8\r
- */\r
- protected DateFormat.Field patternCharToDateFormatField(char ch) {\r
- if (ch == 'l') {\r
- return ChineseDateFormat.Field.IS_LEAP_MONTH;\r
- }\r
- return super.patternCharToDateFormatField(ch);\r
- }\r
-\r
- /**\r
- * The instances of this inner class are used as attribute keys and values\r
- * in AttributedCharacterIterator that\r
- * ChineseDateFormat.formatToCharacterIterator() method returns.\r
- * <p>\r
- * There is no public constructor to this class, the only instances are the\r
- * constants defined here.\r
- * <p>\r
- * @stable ICU 3.8\r
- */\r
- public static class Field extends DateFormat.Field {\r
-\r
- private static final long serialVersionUID = -5102130532751400330L;\r
-\r
- /**\r
- * Constant identifying the leap month marker.\r
- * @stable ICU 3.8\r
- */\r
- public static final Field IS_LEAP_MONTH = new Field("is leap month", ChineseCalendar.IS_LEAP_MONTH);\r
-\r
- /**\r
- * Constructs a <code>ChineseDateFormat.Field</code> with the given name and\r
- * the <code>ChineseCalendar</code> field which this attribute represents.\r
- * Use -1 for <code>calendarField</code> if this field does not have a\r
- * corresponding <code>ChineseCalendar</code> field.\r
- * \r
- * @param name Name of the attribute\r
- * @param calendarField <code>Calendar</code> field constant\r
- * \r
- * @stable ICU 3.8\r
- */\r
- protected Field(String name, int calendarField) {\r
- super(name, calendarField);\r
- }\r
-\r
- /**\r
- * Returns the <code>Field</code> constant that corresponds to the <code>\r
- * ChineseCalendar</code> field <code>calendarField</code>. If there is no\r
- * corresponding <code>Field</code> is available, null is returned.\r
- * \r
- * @param calendarField <code>ChineseCalendar</code> field constant\r
- * @return <code>Field</code> associated with the <code>calendarField</code>,\r
- * or null if no associated <code>Field</code> is available.\r
- * @throws IllegalArgumentException if <code>calendarField</code> is not\r
- * a valid <code>Calendar</code> field constant.\r
- * \r
- * @stable ICU 3.8\r
- */\r
- public static DateFormat.Field ofCalendarField(int calendarField) {\r
- if (calendarField == ChineseCalendar.IS_LEAP_MONTH) {\r
- return IS_LEAP_MONTH;\r
- }\r
- return DateFormat.Field.ofCalendarField(calendarField);\r
- }\r
-\r
- /**\r
- * {@inheritDoc}\r
- * \r
- * @stable ICU 3.8\r
- */\r
- protected Object readResolve() throws InvalidObjectException {\r
- if (this.getClass() != ChineseDateFormat.Field.class) {\r
- throw new InvalidObjectException("A subclass of ChineseDateFormat.Field must implement readResolve.");\r
- }\r
- if (this.getName().equals(IS_LEAP_MONTH.getName())) {\r
- return IS_LEAP_MONTH;\r
- } else {\r
- throw new InvalidObjectException("Unknown attribute name.");\r
- }\r
- }\r
- }\r
-//#endif\r
-}\r
+//##header J2SE15
+/*********************************************************************
+ * Copyright (C) 2000-2009, International Business Machines Corporation and
+ * others. All Rights Reserved.
+ *********************************************************************
+ */
+package com.ibm.icu.text;
+import com.ibm.icu.util.*;
+import com.ibm.icu.impl.Utility;
+
+import java.text.FieldPosition;
+import java.text.ParsePosition;
+import java.util.Locale;
+//#if defined(FOUNDATION10) || defined(J2SE13)
+//#else
+import java.io.InvalidObjectException;
+//#endif
+
+/**
+ * A concrete {@link DateFormat} for {@link com.ibm.icu.util.ChineseCalendar}.
+ * This class handles a <code>ChineseCalendar</code>-specific field,
+ * <code>ChineseCalendar.IS_LEAP_MONTH</code>. It also redefines the
+ * handling of two fields, <code>ERA</code> and <code>YEAR</code>. The
+ * former is displayed numerically, instead of symbolically, since it is
+ * the numeric cycle number in <code>ChineseCalendar</code>. The latter is
+ * numeric, as before, but has no special 2-digit Y2K behavior.
+ *
+ * <p>With regard to <code>ChineseCalendar.IS_LEAP_MONTH</code>, this
+ * class handles parsing specially. If no string symbol is found at all,
+ * this is taken as equivalent to an <code>IS_LEAP_MONTH</code> value of
+ * zero. This allows formats to display a special string (e.g., "*") for
+ * leap months, but no string for normal months.
+ *
+ * <p>Summary of field changes vs. {@link SimpleDateFormat}:<pre>
+ * Symbol Meaning Presentation Example
+ * ------ ------- ------------ -------
+ * G cycle (Number) 78
+ * y year of cycle (1..60) (Number) 17
+ * l is leap month (Text) 4637
+ * </pre>
+ *
+ * @see com.ibm.icu.util.ChineseCalendar
+ * @see ChineseDateFormatSymbols
+ * @author Alan Liu
+ * @stable ICU 2.0
+ */
+public class ChineseDateFormat extends SimpleDateFormat {
+ // Generated by serialver from JDK 1.4.1_01
+ static final long serialVersionUID = -4610300753104099899L;
+
+ // TODO Finish the constructors
+
+ /**
+ * Construct a ChineseDateFormat from a date format pattern and locale
+ * @param pattern the pattern
+ * @param locale the locale
+ * @stable ICU 2.0
+ */
+ public ChineseDateFormat(String pattern, Locale locale) {
+ this(pattern, ULocale.forLocale(locale));
+ }
+
+ /**
+ * Construct a ChineseDateFormat from a date format pattern and locale
+ * @param pattern the pattern
+ * @param locale the locale
+ * @stable ICU 3.2
+ */
+ public ChineseDateFormat(String pattern, ULocale locale) {
+ this(pattern, null, locale);
+ }
+
+ /**
+ * Construct a ChineseDateFormat from a date format pattern and locale
+ * @param pattern the pattern
+ * @param locale the locale
+ * @stable ICU 3.2
+ */
+ public ChineseDateFormat(String pattern, String override, ULocale locale) {
+ super(pattern, new ChineseDateFormatSymbols(locale),
+ new ChineseCalendar(TimeZone.getDefault(), locale), locale, true, override);
+ }
+
+// NOTE: This API still exists; we just inherit it from SimpleDateFormat
+// as of ICU 3.0
+// /**
+// * @stable ICU 2.0
+// */
+// protected String subFormat(char ch, int count, int beginOffset,
+// FieldPosition pos, DateFormatSymbols formatData,
+// Calendar cal) {
+// switch (ch) {
+// case 'G': // 'G' - ERA
+// return zeroPaddingNumber(cal.get(Calendar.ERA), 1, 9);
+// case 'l': // 'l' - IS_LEAP_MONTH
+// {
+// ChineseDateFormatSymbols symbols =
+// (ChineseDateFormatSymbols) formatData;
+// return symbols.getLeapMonth(cal.get(
+// ChineseCalendar.IS_LEAP_MONTH));
+// }
+// default:
+// return super.subFormat(ch, count, beginOffset, pos, formatData, cal);
+// }
+// }
+
+ /**
+ * {@inheritDoc}
+ * @internal
+ * @deprecated This API is ICU internal only.
+ */
+ protected void subFormat(StringBuffer buf,
+ char ch, int count, int beginOffset,
+ 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;
+ }
+
+ // 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.
+ // The logic should be moved up into SimpleDateFormat.format.
+ }
+
+ /**
+ * {@inheritDoc}
+ * @stable ICU 2.0
+ */
+ 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 = Utility.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;
+ }
+ default:
+ ///CLOVER:OFF
+ return 0; // This can never happen
+ ///CLOVER:ON
+ }
+ }
+
+//#if defined(FOUNDATION10) || defined(J2SE13)
+//#else
+ /**
+ * {@inheritDoc}
+ *
+ * @stable ICU 3.8
+ */
+ protected DateFormat.Field patternCharToDateFormatField(char ch) {
+ if (ch == 'l') {
+ return ChineseDateFormat.Field.IS_LEAP_MONTH;
+ }
+ return super.patternCharToDateFormatField(ch);
+ }
+
+ /**
+ * The instances of this inner class are used as attribute keys and values
+ * in AttributedCharacterIterator that
+ * ChineseDateFormat.formatToCharacterIterator() method returns.
+ * <p>
+ * There is no public constructor to this class, the only instances are the
+ * constants defined here.
+ * <p>
+ * @stable ICU 3.8
+ */
+ public static class Field extends DateFormat.Field {
+
+ private static final long serialVersionUID = -5102130532751400330L;
+
+ /**
+ * Constant identifying the leap month marker.
+ * @stable ICU 3.8
+ */
+ public static final Field IS_LEAP_MONTH = new Field("is leap month", ChineseCalendar.IS_LEAP_MONTH);
+
+ /**
+ * Constructs a <code>ChineseDateFormat.Field</code> with the given name and
+ * the <code>ChineseCalendar</code> field which this attribute represents.
+ * Use -1 for <code>calendarField</code> if this field does not have a
+ * corresponding <code>ChineseCalendar</code> field.
+ *
+ * @param name Name of the attribute
+ * @param calendarField <code>Calendar</code> field constant
+ *
+ * @stable ICU 3.8
+ */
+ protected Field(String name, int calendarField) {
+ super(name, calendarField);
+ }
+
+ /**
+ * Returns the <code>Field</code> constant that corresponds to the <code>
+ * ChineseCalendar</code> field <code>calendarField</code>. If there is no
+ * corresponding <code>Field</code> is available, null is returned.
+ *
+ * @param calendarField <code>ChineseCalendar</code> field constant
+ * @return <code>Field</code> associated with the <code>calendarField</code>,
+ * or null if no associated <code>Field</code> is available.
+ * @throws IllegalArgumentException if <code>calendarField</code> is not
+ * a valid <code>Calendar</code> field constant.
+ *
+ * @stable ICU 3.8
+ */
+ public static DateFormat.Field ofCalendarField(int calendarField) {
+ if (calendarField == ChineseCalendar.IS_LEAP_MONTH) {
+ return IS_LEAP_MONTH;
+ }
+ return DateFormat.Field.ofCalendarField(calendarField);
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @stable ICU 3.8
+ */
+ protected Object readResolve() throws InvalidObjectException {
+ if (this.getClass() != ChineseDateFormat.Field.class) {
+ throw new InvalidObjectException("A subclass of ChineseDateFormat.Field must implement readResolve.");
+ }
+ if (this.getName().equals(IS_LEAP_MONTH.getName())) {
+ return IS_LEAP_MONTH;
+ } else {
+ throw new InvalidObjectException("Unknown attribute name.");
+ }
+ }
+ }
+//#endif
+}