* Any characters in the pattern that are not in the ranges of ['a'..'z'] and
* ['A'..'Z'] will be treated as quoted text. For instance, characters like ':',
* '.', ' ', '#' and '@' will appear in the resulting time text even they are
* not embraced within single quotes.
- *
*
* A pattern containing any invalid pattern letter will result in an exception
* thrown during formatting or parsing.
- *
*
*
*
@@ -275,7 +262,6 @@ import org.apache.harmony.text.internal.nls.Messages;
* am/pm marker 'a' is left out from the format pattern while the
* "hour in am/pm" pattern symbol is used. This information loss can happen when
* formatting the time in PM.
- *
*
* When parsing a date string using the abbreviated year pattern ("yy"), {@code
* SimpleDateFormat} must interpret the abbreviated year relative to some
@@ -291,12 +277,10 @@ import org.apache.harmony.text.internal.nls.Messages;
* example, "-1"), is interpreted literally. So "01/02/3" or "01/02/003" are
* parsed, using the same pattern, as Jan 2, 3 AD. Likewise, "01/02/-3" is
* parsed as Jan 2, 4 BC.
- *
*
* If the year pattern does not have exactly two 'y' characters, the year is
* interpreted literally, regardless of the number of digits. So using the
* pattern "MM/dd/yyyy", "01/11/12" parses to Jan 11, 12 A.D.
- *
*
* When numeric fields are adjacent directly, with no intervening delimiter
* characters, they constitute a run of adjacent numeric fields. Such runs are
@@ -308,11 +292,9 @@ import org.apache.harmony.text.internal.nls.Messages;
* parsed again. This is repeated until either the parse succeeds or the
* leftmost field is one character in length. If the parse still fails at that
* point, the parse of the run fails.
- *
*
* For time zones that have no names, use the strings "GMT+hours:minutes" or
* "GMT-hours:minutes".
- *
*
* The calendar defines the first day of the week, the first week of the year,
* whether hours are zero based or not (0 vs. 12 or 24) and the time zone. There
@@ -324,17 +306,19 @@ import org.apache.harmony.text.internal.nls.Messages;
*
* @see Calendar
* @see GregorianCalendar
- * @see TimeZone
+ * @see java.util.TimeZone
* @see DateFormat
* @see DateFormatSymbols
* @see DecimalFormat
- * @since Android 1.0
*/
public class SimpleDateFormat extends DateFormat {
private static final long serialVersionUID = 4774881970558875024L;
+ // BEGIN android-changed
+ // private static final String patternChars = "GyMdkHmsSEDFwWahKzYeugAZvcLQqV"; //$NON-NLS-1$
private static final String patternChars = "GyMdkHmsSEDFwWahKzZ"; //$NON-NLS-1$
+ // END android-changed
private String pattern;
@@ -344,15 +328,21 @@ public class SimpleDateFormat extends DateFormat {
private Date defaultCenturyStart;
+ // BEGIN android-removed
+ // private transient String tzId;
+ //
+ // private transient com.ibm.icu.text.SimpleDateFormat icuFormat;
+ // END android-removed
+
/**
* Constructs a new {@code SimpleDateFormat} for formatting and parsing
* dates and times in the {@code SHORT} style for the default locale.
- *
- * @since Android 1.0
*/
public SimpleDateFormat() {
this(Locale.getDefault());
+ // BEGIN android-changed
pattern = defaultPattern();
+ // END android-changed
formatData = new DateFormatSymbols(Locale.getDefault());
}
@@ -363,35 +353,133 @@ public class SimpleDateFormat extends DateFormat {
*
* @param pattern
* the pattern.
- * @exception IllegalArgumentException
- * if {@code pattern} is not considered to be usable by this
- * formatter.
- * @since Android 1.0
+ * @throws NullPointerException
+ * if the pattern is {@code null}.
+ * @throws IllegalArgumentException
+ * if {@code pattern} is not considered to be usable by this
+ * formatter.
*/
public SimpleDateFormat(String pattern) {
this(pattern, Locale.getDefault());
}
+
+ /**
+ * Validates the format character.
+ *
+ * @param format
+ * the format character
+ *
+ * @throws IllegalArgumentException
+ * when the format character is invalid
+ */
+ private void validateFormat(char format) {
+ int index = patternChars.indexOf(format);
+ if (index == -1) {
+ // text.03=Unknown pattern character - '{0}'
+ throw new IllegalArgumentException(Messages.getString(
+ "text.03", format)); //$NON-NLS-1$
+ }
+ }
/**
+ * Validates the pattern.
+ *
+ * @param template
+ * the pattern to validate.
+ *
+ * @throws NullPointerException
+ * if the pattern is null
+ * @throws IllegalArgumentException
+ * if the pattern is invalid
+ */
+ private void validatePattern(String template) {
+ boolean quote = false;
+ int next, last = -1, count = 0;
+
+ final int patternLength = template.length();
+ for (int i = 0; i < patternLength; i++) {
+ next = (template.charAt(i));
+ if (next == '\'') {
+ if (count > 0) {
+ validateFormat((char) last);
+ count = 0;
+ }
+ if (last == next) {
+ last = -1;
+ } else {
+ last = next;
+ }
+ quote = !quote;
+ continue;
+ }
+ if (!quote
+ && (last == next || (next >= 'a' && next <= 'z') || (next >= 'A' && next <= 'Z'))) {
+ if (last == next) {
+ count++;
+ } else {
+ if (count > 0) {
+ validateFormat((char) last);
+ }
+ last = next;
+ count = 1;
+ }
+ } else {
+ if (count > 0) {
+ validateFormat((char) last);
+ count = 0;
+ }
+ last = -1;
+ }
+ }
+ if (count > 0) {
+ validateFormat((char) last);
+ }
+
+ if (quote) {
+ // text.04=Unterminated quote {0}
+ throw new IllegalArgumentException(Messages.getString("text.04")); //$NON-NLS-1$
+ }
+
+ }
+
+ /**
* Constructs a new {@code SimpleDateFormat} using the specified
* non-localized pattern and {@code DateFormatSymbols} and the {@code
* Calendar} for the default locale.
- *
+ *
* @param template
* the pattern.
* @param value
* the DateFormatSymbols.
- * @exception IllegalArgumentException
- * if the pattern is invalid.
- * @since Android 1.0
+ * @throws NullPointerException
+ * if the pattern is {@code null}.
+ * @throws IllegalArgumentException
+ * if the pattern is invalid.
*/
public SimpleDateFormat(String template, DateFormatSymbols value) {
this(Locale.getDefault());
validatePattern(template);
+ // BEGIN android-removed
+ // icuFormat = new com.ibm.icu.text.SimpleDateFormat(template, Locale.getDefault());
+ // icuFormat.setTimeZone(com.ibm.icu.util.TimeZone.getTimeZone(tzId));
+ // END android-removed
pattern = template;
formatData = (DateFormatSymbols) value.clone();
}
+ // BEGIN android-removed
+ // private void copySymbols(DateFormatSymbols value, com.ibm.icu.text.DateFormatSymbols icuSymbols) {
+ // icuSymbols.setAmPmStrings(value.getAmPmStrings());
+ // icuSymbols.setEras(value.getEras());
+ // icuSymbols.setLocalPatternChars(value.getLocalPatternChars());
+ // icuSymbols.setMonths(value.getMonths());
+ // icuSymbols.setShortMonths(value.getShortMonths());
+ // icuSymbols.setShortWeekdays(value.getShortWeekdays());
+ // icuSymbols.setWeekdays(value.getWeekdays());
+ // icuSymbols.setZoneStrings(value.getZoneStrings());
+ // }
+ // END android-removed
+
/**
* Constructs a new {@code SimpleDateFormat} using the specified
* non-localized pattern and the {@code DateFormatSymbols} and {@code
@@ -401,228 +489,59 @@ public class SimpleDateFormat extends DateFormat {
* the pattern.
* @param locale
* the locale.
- * @exception IllegalArgumentException
- * if the pattern is invalid.
- * @since Android 1.0
+ * @throws NullPointerException
+ * if the pattern is {@code null}.
+ * @throws IllegalArgumentException
+ * if the pattern is invalid.
*/
public SimpleDateFormat(String template, Locale locale) {
this(locale);
validatePattern(template);
+ // BEGIN android-removed
+ // icuFormat = new com.ibm.icu.text.SimpleDateFormat(template, locale);
+ // icuFormat.setTimeZone(com.ibm.icu.util.TimeZone.getTimeZone(tzId));
+ // END android-removed
pattern = template;
+ // BEGIN android-changed
formatData = new DateFormatSymbols(locale);
+ // END android-changed
}
+ // BEGIN android-removed
+ // SimpleDateFormat(Locale locale, com.ibm.icu.text.SimpleDateFormat icuFormat){
+ // this(locale);
+ // this.icuFormat = icuFormat;
+ // this.icuFormat.setTimeZone(com.ibm.icu.util.TimeZone.getTimeZone(tzId));
+ // pattern = (String)Format.getInternalField("pattern", icuFormat); //$NON-NLS-1$
+ // formatData = new DateFormatSymbols(locale);
+ // }
+ // END android-removed
+
private SimpleDateFormat(Locale locale) {
numberFormat = NumberFormat.getInstance(locale);
numberFormat.setParseIntegerOnly(true);
numberFormat.setGroupingUsed(false);
calendar = new GregorianCalendar(locale);
calendar.add(Calendar.YEAR, -80);
+ // BEGIN android-removed
+ // tzId = calendar.getTimeZone().getID();
+ // END android-removed
creationYear = calendar.get(Calendar.YEAR);
defaultCenturyStart = calendar.getTime();
}
- private void append(StringBuffer buffer, FieldPosition position,
- Vector fields, char format, int count) {
- int field = -1;
- int index = patternChars.indexOf(format);
- if (index == -1) {
- // text.03=Unknown pattern character - '{0}'
- throw new IllegalArgumentException(Messages.getString(
- "text.03", format)); //$NON-NLS-1$
- }
-
- int beginPosition = buffer.length();
- Field dateFormatField = null;
-
- switch (index) {
- case ERA_FIELD:
- dateFormatField = Field.ERA;
- buffer.append(formatData.eras[calendar.get(Calendar.ERA)]);
- break;
- case YEAR_FIELD:
- dateFormatField = Field.YEAR;
- int year = calendar.get(Calendar.YEAR);
- if (count < 4) {
- appendNumber(buffer, 2, year %= 100);
- } else {
- appendNumber(buffer, count, year);
- }
- break;
- case MONTH_FIELD:
- dateFormatField = Field.MONTH;
- int month = calendar.get(Calendar.MONTH);
- if (count <= 2) {
- appendNumber(buffer, count, month + 1);
- } else if (count == 3) {
- buffer.append(formatData.shortMonths[month]);
- } else {
- buffer.append(formatData.months[month]);
- }
- break;
- case DATE_FIELD:
- dateFormatField = Field.DAY_OF_MONTH;
- field = Calendar.DATE;
- break;
- case HOUR_OF_DAY1_FIELD: // k
- dateFormatField = Field.HOUR_OF_DAY1;
- int hour = calendar.get(Calendar.HOUR_OF_DAY);
- appendNumber(buffer, count, hour == 0 ? 24 : hour);
- break;
- case HOUR_OF_DAY0_FIELD: // H
- dateFormatField = Field.HOUR_OF_DAY0;
- field = Calendar.HOUR_OF_DAY;
- break;
- case MINUTE_FIELD:
- dateFormatField = Field.MINUTE;
- field = Calendar.MINUTE;
- break;
- case SECOND_FIELD:
- dateFormatField = Field.SECOND;
- field = Calendar.SECOND;
- break;
- case MILLISECOND_FIELD:
- dateFormatField = Field.MILLISECOND;
- int value = calendar.get(Calendar.MILLISECOND);
- appendNumber(buffer, count, value);
- break;
- case DAY_OF_WEEK_FIELD:
- dateFormatField = Field.DAY_OF_WEEK;
- int day = calendar.get(Calendar.DAY_OF_WEEK);
- if (count < 4) {
- buffer.append(formatData.shortWeekdays[day]);
- } else {
- buffer.append(formatData.weekdays[day]);
- }
- break;
- case DAY_OF_YEAR_FIELD:
- dateFormatField = Field.DAY_OF_YEAR;
- field = Calendar.DAY_OF_YEAR;
- break;
- case DAY_OF_WEEK_IN_MONTH_FIELD:
- dateFormatField = Field.DAY_OF_WEEK_IN_MONTH;
- field = Calendar.DAY_OF_WEEK_IN_MONTH;
- break;
- case WEEK_OF_YEAR_FIELD:
- dateFormatField = Field.WEEK_OF_YEAR;
- field = Calendar.WEEK_OF_YEAR;
- break;
- case WEEK_OF_MONTH_FIELD:
- dateFormatField = Field.WEEK_OF_MONTH;
- field = Calendar.WEEK_OF_MONTH;
- break;
- case AM_PM_FIELD:
- dateFormatField = Field.AM_PM;
- buffer.append(formatData.ampms[calendar.get(Calendar.AM_PM)]);
- break;
- case HOUR1_FIELD: // h
- dateFormatField = Field.HOUR1;
- hour = calendar.get(Calendar.HOUR);
- appendNumber(buffer, count, hour == 0 ? 12 : hour);
- break;
- case HOUR0_FIELD: // K
- dateFormatField = Field.HOUR0;
- field = Calendar.HOUR;
- break;
- case TIMEZONE_FIELD: // z
- dateFormatField = Field.TIME_ZONE;
- appendTimeZone(buffer, count, true);
- break;
- case (TIMEZONE_FIELD + 1): // Z
- dateFormatField = Field.TIME_ZONE;
- appendTimeZone(buffer, count, false);
- break;
- }
- if (field != -1) {
- appendNumber(buffer, count, calendar.get(field));
- }
-
- if (fields != null) {
- position = new FieldPosition(dateFormatField);
- position.setBeginIndex(beginPosition);
- position.setEndIndex(buffer.length());
- fields.add(position);
- } else {
- // Set to the first occurrence
- if ((position.getFieldAttribute() == dateFormatField || (position
- .getFieldAttribute() == null && position.getField() == index))
- && position.getEndIndex() == 0) {
- position.setBeginIndex(beginPosition);
- position.setEndIndex(buffer.length());
- }
- }
- }
-
- private void appendTimeZone(StringBuffer buffer, int count,
- boolean generalTimezone) {
- // cannot call TimeZone.getDisplayName() because it would not use
- // the DateFormatSymbols of this SimpleDateFormat
-
- if (generalTimezone) {
- String id = calendar.getTimeZone().getID();
- // BEGIN android-changed
- String[][] zones = formatData.internalZoneStrings();
- // END android-changed
- String[] zone = null;
- for (String[] element : zones) {
- if (id.equals(element[0])) {
- zone = element;
- break;
- }
- }
- if (zone == null) {
- int offset = calendar.get(Calendar.ZONE_OFFSET)
- + calendar.get(Calendar.DST_OFFSET);
- char sign = '+';
- if (offset < 0) {
- sign = '-';
- offset = -offset;
- }
- buffer.append("GMT"); //$NON-NLS-1$
- buffer.append(sign);
- appendNumber(buffer, 2, offset / 3600000);
- buffer.append(':');
- appendNumber(buffer, 2, (offset % 3600000) / 60000);
- } else {
- int daylight = calendar.get(Calendar.DST_OFFSET) == 0 ? 0 : 2;
- if (count < 4) {
- buffer.append(zone[2 + daylight]);
- } else {
- buffer.append(zone[1 + daylight]);
- }
- }
- } else {
- int offset = calendar.get(Calendar.ZONE_OFFSET)
- + calendar.get(Calendar.DST_OFFSET);
- char sign = '+';
- if (offset < 0) {
- sign = '-';
- offset = -offset;
- }
- buffer.append(sign);
- appendNumber(buffer, 2, offset / 3600000);
- appendNumber(buffer, 2, (offset % 3600000) / 60000);
- }
- }
-
- private void appendNumber(StringBuffer buffer, int count, int value) {
- int minimumIntegerDigits = numberFormat.getMinimumIntegerDigits();
- numberFormat.setMinimumIntegerDigits(count);
- numberFormat.format(new Integer(value), buffer, new FieldPosition(0));
- numberFormat.setMinimumIntegerDigits(minimumIntegerDigits);
- }
-
/**
* Changes the pattern of this simple date format to the specified pattern
* which uses localized pattern characters.
*
* @param template
* the localized pattern.
- * @since Android 1.0
*/
public void applyLocalizedPattern(String template) {
+ // BEGIN android-changed
pattern = convertPattern(template, formatData.getLocalPatternChars(),
patternChars, true);
+ // END android-changed
}
/**
@@ -631,37 +550,81 @@ public class SimpleDateFormat extends DateFormat {
*
* @param template
* the non-localized pattern.
- * @exception IllegalArgumentException
+ * @throws NullPointerException
+ * if the pattern is {@code null}.
+ * @throws IllegalArgumentException
* if the pattern is invalid.
- * @since Android 1.0
*/
public void applyPattern(String template) {
validatePattern(template);
+ // BEGIN android-removed
+ // /*
+ // * ICU spec explicitly mentions that "ICU interprets a single 'y'
+ // * differently than Java." We need to do a trick here to follow Java
+ // * spec.
+ // */
+ // String templateForICU = patternForICU(template);
+ // icuFormat.applyPattern(templateForICU);
+ // END android-removed
pattern = template;
}
/**
+ * Converts the Java-spec pattern into an equivalent pattern used by ICU.
+ *
+ * @param p
+ * the Java-spec style pattern.
+ * @return the ICU-style pattern.
+ */
+ @SuppressWarnings("nls")
+ private String patternForICU(String p) {
+ String[] subPatterns = p.split("'");
+ boolean quote = false;
+ boolean first = true;
+ StringBuilder result = new StringBuilder();
+ for (String subPattern : subPatterns) {
+ if (!quote) {
+ // replace 'y' with 'yy' for ICU to follow Java spec
+ result.append((first ? "" : "'")
+ + subPattern.replaceAll("(? fields = new Vector();
-
- // format the date, and find fields
- formatImpl(date, buffer, null, fields);
-
- // create and AttributedString with the formatted buffer
- AttributedString as = new AttributedString(buffer.toString());
-
- // add DateFormat field attributes to the AttributedString
- for (int i = 0; i < fields.size(); i++) {
- FieldPosition pos = fields.elementAt(i);
- Format.Field attribute = pos.getFieldAttribute();
- as.addAttribute(attribute, attribute, pos.getBeginIndex(), pos
- .getEndIndex());
- }
-
- // return the CharacterIterator from AttributedString
- return as.getIterator();
- }
-
- /**
- * Formats the specified date as a string using the pattern of this date
- * format and appends the string to the specified string buffer.
- *
- * If the {@code field} member of {@code field} contains a value specifying
- * a format field, then its {@code beginIndex} and {@code endIndex} members
- * will be updated with the position of the first occurrence of this field
- * in the formatted text.
- *
- *
- * @param date
- * the date to format.
- * @param buffer
- * the target string buffer to append the formatted date/time to.
- * @param field
- * on input: an optional alignment field; on output: the offsets
- * of the alignment field in the formatted text.
- * @return the string buffer.
- * @throws IllegalArgumentException
- * if there are invalid characters in the pattern.
- * @since Android 1.0
- */
- @Override
- public StringBuffer format(Date date, StringBuffer buffer,
- FieldPosition field) {
- return formatImpl(date, buffer, field, null);
- }
-
- /**
- * Validates the format character.
- *
- * @param format
- * the format character
- *
- * @throws IllegalArgumentException
- * when the format character is invalid
- */
- private void validateFormat(char format) {
- int index = patternChars.indexOf(format);
- if (index == -1) {
- // text.03=Unknown pattern character - '{0}'
- throw new IllegalArgumentException(Messages.getString(
- "text.03", format)); //$NON-NLS-1$
- }
- }
-
- /**
- * Validates the pattern.
- *
- * @param template
- * the pattern to validate.
- *
- * @throws NullPointerException
- * if the pattern is null
- * @throws IllegalArgumentException
- * if the pattern is invalid
- */
- private void validatePattern(String template) {
- boolean quote = false;
- int next, last = -1, count = 0;
-
- final int patternLength = template.length();
- for (int i = 0; i < patternLength; i++) {
- next = (template.charAt(i));
- if (next == '\'') {
- if (count > 0) {
- validateFormat((char) last);
- count = 0;
- }
- if (last == next) {
- last = -1;
- } else {
- last = next;
- }
- quote = !quote;
- continue;
- }
- if (!quote
- && (last == next || (next >= 'a' && next <= 'z') || (next >= 'A' && next <= 'Z'))) {
- if (last == next) {
- count++;
- } else {
- if (count > 0) {
- validateFormat((char) last);
- }
- last = next;
- count = 1;
- }
- } else {
- if (count > 0) {
- validateFormat((char) last);
- count = 0;
- }
- last = -1;
- }
- }
- if (count > 0) {
- validateFormat((char) last);
+ if (object instanceof Number) {
+ return formatToCharacterIteratorImpl(new Date(((Number) object)
+ .longValue()));
}
+ throw new IllegalArgumentException();
+
+ }
+
+ private AttributedCharacterIterator formatToCharacterIteratorImpl(Date date) {
+ StringBuffer buffer = new StringBuffer();
+ Vector fields = new Vector();
- if (quote) {
- // text.04=Unterminated quote {0}
- throw new IllegalArgumentException(Messages.getString("text.04")); //$NON-NLS-1$
+ // format the date, and find fields
+ formatImpl(date, buffer, null, fields);
+
+ // create and AttributedString with the formatted buffer
+ AttributedString as = new AttributedString(buffer.toString());
+
+ // add DateFormat field attributes to the AttributedString
+ for (int i = 0; i < fields.size(); i++) {
+ FieldPosition pos = fields.elementAt(i);
+ Format.Field attribute = pos.getFieldAttribute();
+ as.addAttribute(attribute, attribute, pos.getBeginIndex(), pos
+ .getEndIndex());
}
+ // return the CharacterIterator from AttributedString
+ return as.getIterator();
}
/**
@@ -874,11 +725,9 @@ public class SimpleDateFormat extends DateFormat {
* @param fields
* Vector used to store the FieldPositions for each field in this
* date
- *
* @return the formatted Date
- *
- * @exception IllegalArgumentException
- * when the object cannot be formatted by this Format
+ * @throws IllegalArgumentException
+ * if the object cannot be formatted by this Format.
*/
private StringBuffer formatImpl(Date date, StringBuffer buffer,
FieldPosition field, Vector fields) {
@@ -932,13 +781,247 @@ public class SimpleDateFormat extends DateFormat {
}
return buffer;
}
+
+ private void append(StringBuffer buffer, FieldPosition position,
+ Vector fields, char format, int count) {
+ int field = -1;
+ int index = patternChars.indexOf(format);
+ if (index == -1) {
+ // text.03=Unknown pattern character - '{0}'
+ throw new IllegalArgumentException(Messages.getString(
+ "text.03", format)); //$NON-NLS-1$
+ }
+
+ int beginPosition = buffer.length();
+ Field dateFormatField = null;
+ switch (index) {
+ case ERA_FIELD:
+ dateFormatField = Field.ERA;
+ buffer.append(formatData.eras[calendar.get(Calendar.ERA)]);
+ break;
+ case YEAR_FIELD:
+ dateFormatField = Field.YEAR;
+ int year = calendar.get(Calendar.YEAR);
+ if (count < 4) {
+ appendNumber(buffer, 2, year %= 100);
+ } else {
+ appendNumber(buffer, count, year);
+ }
+ break;
+ case MONTH_FIELD:
+ dateFormatField = Field.MONTH;
+ int month = calendar.get(Calendar.MONTH);
+ if (count <= 2) {
+ appendNumber(buffer, count, month + 1);
+ } else if (count == 3) {
+ buffer.append(formatData.shortMonths[month]);
+ } else {
+ buffer.append(formatData.months[month]);
+ }
+ break;
+ case DATE_FIELD:
+ dateFormatField = Field.DAY_OF_MONTH;
+ field = Calendar.DATE;
+ break;
+ case HOUR_OF_DAY1_FIELD: // k
+ dateFormatField = Field.HOUR_OF_DAY1;
+ int hour = calendar.get(Calendar.HOUR_OF_DAY);
+ appendNumber(buffer, count, hour == 0 ? 24 : hour);
+ break;
+ case HOUR_OF_DAY0_FIELD: // H
+ dateFormatField = Field.HOUR_OF_DAY0;
+ field = Calendar.HOUR_OF_DAY;
+ break;
+ case MINUTE_FIELD:
+ dateFormatField = Field.MINUTE;
+ field = Calendar.MINUTE;
+ break;
+ case SECOND_FIELD:
+ dateFormatField = Field.SECOND;
+ field = Calendar.SECOND;
+ break;
+ case MILLISECOND_FIELD:
+ dateFormatField = Field.MILLISECOND;
+ int value = calendar.get(Calendar.MILLISECOND);
+ appendNumber(buffer, count, value);
+ break;
+ case DAY_OF_WEEK_FIELD:
+ dateFormatField = Field.DAY_OF_WEEK;
+ int day = calendar.get(Calendar.DAY_OF_WEEK);
+ if (count < 4) {
+ buffer.append(formatData.shortWeekdays[day]);
+ } else {
+ buffer.append(formatData.weekdays[day]);
+ }
+ break;
+ case DAY_OF_YEAR_FIELD:
+ dateFormatField = Field.DAY_OF_YEAR;
+ field = Calendar.DAY_OF_YEAR;
+ break;
+ case DAY_OF_WEEK_IN_MONTH_FIELD:
+ dateFormatField = Field.DAY_OF_WEEK_IN_MONTH;
+ field = Calendar.DAY_OF_WEEK_IN_MONTH;
+ break;
+ case WEEK_OF_YEAR_FIELD:
+ dateFormatField = Field.WEEK_OF_YEAR;
+ field = Calendar.WEEK_OF_YEAR;
+ break;
+ case WEEK_OF_MONTH_FIELD:
+ dateFormatField = Field.WEEK_OF_MONTH;
+ field = Calendar.WEEK_OF_MONTH;
+ break;
+ case AM_PM_FIELD:
+ dateFormatField = Field.AM_PM;
+ buffer.append(formatData.ampms[calendar.get(Calendar.AM_PM)]);
+ break;
+ case HOUR1_FIELD: // h
+ dateFormatField = Field.HOUR1;
+ hour = calendar.get(Calendar.HOUR);
+ appendNumber(buffer, count, hour == 0 ? 12 : hour);
+ break;
+ case HOUR0_FIELD: // K
+ dateFormatField = Field.HOUR0;
+ field = Calendar.HOUR;
+ break;
+ case TIMEZONE_FIELD: // z
+ dateFormatField = Field.TIME_ZONE;
+ appendTimeZone(buffer, count, true);
+ break;
+ // BEGIN android-changed
+ case (TIMEZONE_FIELD + 1): // Z
+ dateFormatField = Field.TIME_ZONE;
+ appendTimeZone(buffer, count, false);
+ break;
+ // END android-changed
+ }
+ if (field != -1) {
+ appendNumber(buffer, count, calendar.get(field));
+ }
+
+ if (fields != null) {
+ position = new FieldPosition(dateFormatField);
+ position.setBeginIndex(beginPosition);
+ position.setEndIndex(buffer.length());
+ fields.add(position);
+ } else {
+ // Set to the first occurrence
+ if ((position.getFieldAttribute() == dateFormatField || (position
+ .getFieldAttribute() == null && position.getField() == index))
+ && position.getEndIndex() == 0) {
+ position.setBeginIndex(beginPosition);
+ position.setEndIndex(buffer.length());
+ }
+ }
+ }
+
+ private void appendTimeZone(StringBuffer buffer, int count,
+ boolean generalTimezone) {
+ // cannot call TimeZone.getDisplayName() because it would not use
+ // the DateFormatSymbols of this SimpleDateFormat
+
+ if (generalTimezone) {
+ String id = calendar.getTimeZone().getID();
+ // BEGIN android-changed
+ String[][] zones = formatData.internalZoneStrings();
+ // END android-changed
+ String[] zone = null;
+ for (String[] element : zones) {
+ if (id.equals(element[0])) {
+ zone = element;
+ break;
+ }
+ }
+ if (zone == null) {
+ int offset = calendar.get(Calendar.ZONE_OFFSET)
+ + calendar.get(Calendar.DST_OFFSET);
+ char sign = '+';
+ if (offset < 0) {
+ sign = '-';
+ offset = -offset;
+ }
+ buffer.append("GMT"); //$NON-NLS-1$
+ buffer.append(sign);
+ appendNumber(buffer, 2, offset / 3600000);
+ buffer.append(':');
+ appendNumber(buffer, 2, (offset % 3600000) / 60000);
+ } else {
+ int daylight = calendar.get(Calendar.DST_OFFSET) == 0 ? 0 : 2;
+ if (count < 4) {
+ buffer.append(zone[2 + daylight]);
+ } else {
+ buffer.append(zone[1 + daylight]);
+ }
+ }
+ } else {
+ int offset = calendar.get(Calendar.ZONE_OFFSET)
+ + calendar.get(Calendar.DST_OFFSET);
+ char sign = '+';
+ if (offset < 0) {
+ sign = '-';
+ offset = -offset;
+ }
+ buffer.append(sign);
+ appendNumber(buffer, 2, offset / 3600000);
+ appendNumber(buffer, 2, (offset % 3600000) / 60000);
+ }
+ }
+
+ private void appendNumber(StringBuffer buffer, int count, int value) {
+ int minimumIntegerDigits = numberFormat.getMinimumIntegerDigits();
+ numberFormat.setMinimumIntegerDigits(count);
+ numberFormat.format(new Integer(value), buffer, new FieldPosition(0));
+ numberFormat.setMinimumIntegerDigits(minimumIntegerDigits);
+ }
+
+ // BEGIN android-added
+ private Date error(ParsePosition position, int offset, TimeZone zone) {
+ position.setErrorIndex(offset);
+ calendar.setTimeZone(zone);
+ return null;
+ }
+ // END android-added
+
+ /**
+ * Formats the specified date as a string using the pattern of this date
+ * format and appends the string to the specified string buffer.
+ *
+ * If the {@code field} member of {@code field} contains a value specifying
+ * a format field, then its {@code beginIndex} and {@code endIndex} members
+ * will be updated with the position of the first occurrence of this field
+ * in the formatted text.
+ *
+ * @param date
+ * the date to format.
+ * @param buffer
+ * the target string buffer to append the formatted date/time to.
+ * @param fieldPos
+ * on input: an optional alignment field; on output: the offsets
+ * of the alignment field in the formatted text.
+ * @return the string buffer.
+ * @throws IllegalArgumentException
+ * if there are invalid characters in the pattern.
+ */
+ @Override
+ public StringBuffer format(Date date, StringBuffer buffer,
+ FieldPosition fieldPos) {
+ // BEGIN android-changed
+ // Harmony delegates to ICU's SimpleDateFormat, we implement it directly
+ return formatImpl(date, buffer, fieldPos, null);
+ // END android-changed
+ }
+
+ // BEGIN android-removed
+ // private com.ibm.icu.text.DateFormat.Field toICUField(
+ // DateFormat.Field attribute) {
+ // ...
+ // }
+ // END android-removed
/**
- * Returns the date which is the start of the one hundred year period for
+ * Answers the Date which is the start of the one hundred year period for
* two digits year values.
*
- * @return a date.
- * @since Android 1.0
+ * @return a Date
*/
public Date get2DigitYearStart() {
return defaultCenturyStart;
@@ -946,9 +1029,8 @@ public class SimpleDateFormat extends DateFormat {
/**
* Returns the {@code DateFormatSymbols} used by this simple date format.
- *
+ *
* @return the {@code DateFormatSymbols} object.
- * @since Android 1.0
*/
public DateFormatSymbols getDateFormatSymbols() {
// Return a clone so the arrays in the ResourceBundle are not modified
@@ -961,6 +1043,7 @@ public class SimpleDateFormat extends DateFormat {
+ creationYear;
}
+ // BEGIN android-added
private int parse(String string, int offset, char format, int count) {
int index = patternChars.indexOf(format);
if (index == -1) {
@@ -1085,6 +1168,7 @@ public class SimpleDateFormat extends DateFormat {
}
return offset;
}
+ // END android-added
/**
* Parses a date from the specified string starting at the index specified
@@ -1092,7 +1176,7 @@ public class SimpleDateFormat extends DateFormat {
* of the {@code ParsePosition} is updated to the index following the parsed
* text. On error, the index is unchanged and the error index of {@code
* ParsePosition} is set to the index where the error occurred.
- *
+ *
* @param string
* the string to parse using the pattern of this simple date
* format.
@@ -1106,10 +1190,11 @@ public class SimpleDateFormat extends DateFormat {
* error.
* @throws IllegalArgumentException
* if there are invalid characters in the pattern.
- * @since Android 1.0
*/
@Override
public Date parse(String string, ParsePosition position) {
+ // BEGIN android-changed
+ // Harmony delegates to ICU's SimpleDateFormat, we implement it directly
boolean quote = false;
int next, last = -1, count = 0, offset = position.getIndex();
int length = string.length();
@@ -1178,8 +1263,10 @@ public class SimpleDateFormat extends DateFormat {
position.setIndex(offset);
calendar.setTimeZone(zone);
return date;
+ // END android-changed
}
+ // BEGIN android-added
private Number parseNumber(int max, String string, ParsePosition position) {
int digit, length = string.length(), result = 0;
int index = position.getIndex();
@@ -1299,6 +1386,7 @@ public class SimpleDateFormat extends DateFormat {
}
return -offset - 1;
}
+ // END android-added
/**
* Sets the date which is the start of the one hundred year period for two
@@ -1306,9 +1394,11 @@ public class SimpleDateFormat extends DateFormat {
*
* @param date
* the new date.
- * @since Android 1.0
*/
public void set2DigitYearStart(Date date) {
+ // BEGIN android-removed
+ // icuFormat.set2DigitYearStart(date);
+ // END android-removed
defaultCenturyStart = date;
Calendar cal = new GregorianCalendar();
cal.setTime(date);
@@ -1320,9 +1410,13 @@ public class SimpleDateFormat extends DateFormat {
*
* @param value
* the new {@code DateFormatSymbols} object.
- * @since Android 1.0
*/
public void setDateFormatSymbols(DateFormatSymbols value) {
+ // BEGIN android-removed
+ // com.ibm.icu.text.DateFormatSymbols icuSymbols = new com.ibm.icu.text.DateFormatSymbols();
+ // copySymbols(value, icuSymbols);
+ // icuFormat.setDateFormatSymbols(icuSymbols);
+ // END android-removed
formatData = (DateFormatSymbols) value.clone();
}
@@ -1331,11 +1425,12 @@ public class SimpleDateFormat extends DateFormat {
* characters.
*
* @return the localized pattern.
- * @since Android 1.0
*/
public String toLocalizedPattern() {
+ // BEGIN android-changed
return convertPattern(pattern, patternChars, formatData
.getLocalPatternChars(), false);
+ // END android-changed
}
/**
@@ -1343,7 +1438,6 @@ public class SimpleDateFormat extends DateFormat {
* pattern characters.
*
* @return the non-localized pattern.
- * @since Android 1.0
*/
public String toPattern() {
return pattern;
diff --git a/text/src/main/java/java/text/StringCharacterIterator.java b/text/src/main/java/java/text/StringCharacterIterator.java
index 5d02ceb..8ef0341 100644
--- a/text/src/main/java/java/text/StringCharacterIterator.java
+++ b/text/src/main/java/java/text/StringCharacterIterator.java
@@ -19,8 +19,6 @@ package java.text;
/**
* An implementation of {@link CharacterIterator} for strings.
- *
- * @since Android 1.0
*/
public final class StringCharacterIterator implements CharacterIterator {
@@ -35,7 +33,6 @@ public final class StringCharacterIterator implements CharacterIterator {
*
* @param value
* the source string to iterate over.
- * @since Android 1.0
*/
public StringCharacterIterator(String value) {
string = value;
@@ -53,10 +50,9 @@ public final class StringCharacterIterator implements CharacterIterator {
* the source string to iterate over.
* @param location
* the current index.
- * @exception IllegalArgumentException
- * if {@code location} is negative or greater than the length
- * of the source string.
- * @since Android 1.0
+ * @throws IllegalArgumentException
+ * if {@code location} is negative or greater than the length
+ * of the source string.
*/
public StringCharacterIterator(String value, int location) {
string = value;
@@ -80,11 +76,10 @@ public final class StringCharacterIterator implements CharacterIterator {
* the index one past the last character to iterate.
* @param location
* the current index.
- * @exception IllegalArgumentException
- * if {@code start < 0}, {@code start > end},
- * {@code location < start}, {@code location > end} or if
- * {@code end} is greater than the length of {@code value}.
- * @since Android 1.0
+ * @throws IllegalArgumentException
+ * if {@code start < 0}, {@code start > end}, {@code location <
+ * start}, {@code location > end} or if {@code end} is greater
+ * than the length of {@code value}.
*/
public StringCharacterIterator(String value, int start, int end,
int location) {
@@ -104,7 +99,6 @@ public final class StringCharacterIterator implements CharacterIterator {
*
* @return a shallow copy of this iterator.
* @see java.lang.Cloneable
- * @since Android 1.0
*/
@Override
public Object clone() {
@@ -120,7 +114,6 @@ public final class StringCharacterIterator implements CharacterIterator {
*
* @return the current character, or {@code DONE} if the current index is
* past the end.
- * @since Android 1.0
*/
public char current() {
if (offset == end) {
@@ -140,7 +133,6 @@ public final class StringCharacterIterator implements CharacterIterator {
* @return {@code true} if the specified object is equal to this
* {@code StringCharacterIterator}; {@code false} otherwise.
* @see #hashCode
- * @since Android 1.0
*/
@Override
public boolean equals(Object object) {
@@ -158,7 +150,6 @@ public final class StringCharacterIterator implements CharacterIterator {
*
* @return the character at the begin index or {@code DONE} if the begin
* index is equal to the end index.
- * @since Android 1.0
*/
public char first() {
if (start == end) {
@@ -172,7 +163,6 @@ public final class StringCharacterIterator implements CharacterIterator {
* Returns the begin index in the source string.
*
* @return the index of the first character of the iteration.
- * @since Android 1.0
*/
public int getBeginIndex() {
return start;
@@ -182,7 +172,6 @@ public final class StringCharacterIterator implements CharacterIterator {
* Returns the end index in the source string.
*
* @return the index one past the last character of the iteration.
- * @since Android 1.0
*/
public int getEndIndex() {
return end;
@@ -192,7 +181,6 @@ public final class StringCharacterIterator implements CharacterIterator {
* Returns the current index in the source string.
*
* @return the current index.
- * @since Android 1.0
*/
public int getIndex() {
return offset;
@@ -209,9 +197,8 @@ public final class StringCharacterIterator implements CharacterIterator {
*
* @return the character before the end index or {@code DONE} if the begin
* index is equal to the end index.
- * @since Android 1.0
*/
- public char last() {
+ public char last() {
if (start == end) {
return DONE;
}
@@ -219,14 +206,13 @@ public final class StringCharacterIterator implements CharacterIterator {
return string.charAt(offset);
}
- /**
- * Increments the current index and returns the character at the new index.
- *
- * @return the character at the next index, or {@code DONE} if the next
- * index would be past the end.
- * @since Android 1.0
- */
- public char next() {
+ /**
+ * Increments the current index and returns the character at the new index.
+ *
+ * @return the character at the next index, or {@code DONE} if the next
+ * index would be past the end.
+ */
+ public char next() {
if (offset >= (end - 1)) {
offset = end;
return DONE;
@@ -234,13 +220,12 @@ public final class StringCharacterIterator implements CharacterIterator {
return string.charAt(++offset);
}
- /**
- * Decrements the current index and returns the character at the new index.
- *
- * @return the character at the previous index, or {@code DONE} if the
- * previous index would be past the beginning.
- * @since Android 1.0
- */
+ /**
+ * Decrements the current index and returns the character at the new index.
+ *
+ * @return the character at the previous index, or {@code DONE} if the
+ * previous index would be past the beginning.
+ */
public char previous() {
if (offset == start) {
return DONE;
@@ -255,10 +240,9 @@ public final class StringCharacterIterator implements CharacterIterator {
* the index the current position is set to.
* @return the character at the new index, or {@code DONE} if
* {@code location} is set to the end index.
- * @exception IllegalArgumentException
- * if {@code location} is smaller than the begin index or
- * greater than the end index.
- * @since Android 1.0
+ * @throws IllegalArgumentException
+ * if {@code location} is smaller than the begin index or greater
+ * than the end index.
*/
public char setIndex(int location) {
if (location < start || location > end) {
@@ -277,7 +261,6 @@ public final class StringCharacterIterator implements CharacterIterator {
*
* @param value
* the new source string.
- * @since Android 1.0
*/
public void setText(String value) {
string = value;
diff --git a/text/src/main/java/org/apache/harmony/text/BidiWrapper.java b/text/src/main/java/org/apache/harmony/text/BidiWrapper.java
index 240fcdf..fac25b9 100644
--- a/text/src/main/java/org/apache/harmony/text/BidiWrapper.java
+++ b/text/src/main/java/org/apache/harmony/text/BidiWrapper.java
@@ -18,7 +18,8 @@
package org.apache.harmony.text;
/**
- * TODO: type description
+ * Dalvik Bidi wrapper. Derived from an old version of Harmony; today they use
+ * straight through to ICU4J.
*/
public final class BidiWrapper {
diff --git a/text/src/test/java/org/apache/harmony/text/tests/java/text/BidiTest.java b/text/src/test/java/org/apache/harmony/text/tests/java/text/BidiTest.java
index e3ea9dc..deef841 100644
--- a/text/src/test/java/org/apache/harmony/text/tests/java/text/BidiTest.java
+++ b/text/src/test/java/org/apache/harmony/text/tests/java/text/BidiTest.java
@@ -1757,8 +1757,13 @@ public class BidiTest extends TestCase {
// Expected
}
-// Outsourced to _AndroidFailure:
-// bidi.createLineBidi(2, 2);
+ // BEGIN android-removed
+ // Outsourced to _AndroidFailure:
+ // try {
+ // bidi.createLineBidi(2, 2);
+ // } catch (IllegalArgumentException expected) {
+ // }
+ // END android-removed
try {
bidi.createLineBidi(2, 4);
@@ -1974,19 +1979,23 @@ public class BidiTest extends TestCase {
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
- notes = "Doesn't verify any int value between 0 and getRunCount().",
+ notes = "",
method = "getRunLimit",
args = {int.class}
)
+ @KnownFailure("Doesn't verify any int value between 0 and getRunCount().")
public void testGetRunLimit() {
bd = new Bidi("text", Bidi.DIRECTION_LEFT_TO_RIGHT);
try {
assertTrue(4 == bd.getRunLimit(-1));
- } catch (Exception e) {
- fail("Unexpected exception: " + e);
+ } catch (IllegalArgumentException e) {
+ // Expected for illegal run limit
+ return;
}
+
+ fail("Expected IllegalArgumentException to be thrown for invalid run limit");
}
-
+
@TestTargetNew(
level = TestLevel.COMPLETE,
notes = "",
@@ -2052,13 +2061,17 @@ public class BidiTest extends TestCase {
method = "Bidi",
args = {java.text.AttributedCharacterIterator.class}
)
+ @KnownFailure("Doesn't verify any int value between 0 and getRunCount().")
public void testBidiConstructor_Iterator() {
AttributedString paragraph = new AttributedString("text");
bd = new Bidi(paragraph.getIterator());
try {
assertTrue(4 == bd.getRunLimit(1));
- } catch (Exception e) {
- fail("Unexpected exception: " + e);
+ } catch (IllegalArgumentException e) {
+ // Expected for illegal run limit
+ return;
}
+
+ fail("Expected IllegalArgumentException to be thrown for invalid run limit");
}
}
diff --git a/text/src/test/java/org/apache/harmony/text/tests/java/text/DataFormatFieldTest.java b/text/src/test/java/org/apache/harmony/text/tests/java/text/DataFormatFieldTest.java
index ff05e64..ff6dd8e 100644
--- a/text/src/test/java/org/apache/harmony/text/tests/java/text/DataFormatFieldTest.java
+++ b/text/src/test/java/org/apache/harmony/text/tests/java/text/DataFormatFieldTest.java
@@ -207,7 +207,6 @@ public class DataFormatFieldTest extends TestCase {
method = "readResolve",
args = {}
)
- @KnownFailure("readResolve does not work properly")
public void test_readResolve() {
// test for method java.lang.Object readResolve()
diff --git a/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatSymbolsTest.java b/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatSymbolsTest.java
index 4151dc8..8b97ee7 100644
--- a/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatSymbolsTest.java
+++ b/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatSymbolsTest.java
@@ -16,11 +16,14 @@
*/
package org.apache.harmony.text.tests.java.text;
-import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTargetNew;
import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
import java.text.DateFormatSymbols;
import java.util.Arrays;
import java.util.Locale;
@@ -42,11 +45,7 @@ public class DateFormatSymbolsTest extends junit.framework.TestCase {
public void test_Constructor() {
// Test for method java.text.DateFormatSymbols()
// Used in tests
- try {
- new DateFormatSymbols();
- } catch (Exception e) {
- fail("Constructor failed.");
- }
+ new DateFormatSymbols();
}
/**
@@ -60,11 +59,7 @@ public class DateFormatSymbolsTest extends junit.framework.TestCase {
)
public void test_ConstructorLjava_util_Locale() {
// Test for method java.text.DateFormatSymbols(java.util.Locale)
- try {
- new DateFormatSymbols(new Locale("en", "us"));
- } catch (Exception e) {
- fail("Constructor failed.");
- }
+ new DateFormatSymbols(new Locale("en", "us"));
}
/**
@@ -156,8 +151,10 @@ public class DateFormatSymbolsTest extends junit.framework.TestCase {
String retVal = dfs.getLocalPatternChars();
String val = "GyMdkHmsSEDFwWahKzZ";
+ // Harmony uses a different set of pattern chars
+ // String val = "GyMdkHmsSEDFwWahKzYeugAZvcLQqV";
- assertTrue("Returned incorrect pattern string", retVal.equals(val));
+ assertEquals("Returned incorrect pattern string", val, retVal);
}
/**
@@ -175,9 +172,9 @@ public class DateFormatSymbolsTest extends junit.framework.TestCase {
String[] retVal = dfs.getMonths();
String[] val = { "January", "February", "March", "April", "May",
"June", "July", "August", "September", "October", "November",
- "December", "" };
- if (retVal.length != val.length)
- fail("Returned wrong array: " + retVal.length);
+ "December", ""};
+ // Note: Harmony doesn't include "" at the end of the array
+ assertEquals("Returned wrong array: ", val.length, retVal.length);
for (int i = 0; i < val.length; i++)
assertTrue("Array values do not match", retVal[i].equals(val[i]));
}
@@ -196,9 +193,9 @@ public class DateFormatSymbolsTest extends junit.framework.TestCase {
// java.text.DateFormatSymbols.getShortMonths()
String[] retVal = dfs.getShortMonths();
String[] val = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
- "Aug", "Sep", "Oct", "Nov", "Dec", "" };
- if (retVal.length != val.length)
- fail("Returned wrong array");
+ "Aug", "Sep", "Oct", "Nov", "Dec", ""};
+ // Note: Harmony doesn't include "" at the end of the array
+ assertEquals("Returned wrong array: ", val.length, retVal.length);
for (int i = 0; i < val.length; i++)
assertTrue("Array values do not match", retVal[i].equals(val[i]));
}
@@ -482,4 +479,32 @@ public class DateFormatSymbolsTest extends junit.framework.TestCase {
*/
protected void tearDown() {
}
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Checks serialization mechanism.",
+ method = "!SerializationSelf",
+ args = {}
+ )
+[] public void test_serialization() throws Exception {
+ DateFormatSymbols symbols = new DateFormatSymbols(Locale.FRANCE);
+ String[][] zoneStrings = symbols.getZoneStrings();
+ assertNotNull(zoneStrings);
+
+ // serialize
+ ByteArrayOutputStream byteOStream = new ByteArrayOutputStream();
+ ObjectOutputStream objectOStream = new ObjectOutputStream(byteOStream);
+ objectOStream.writeObject(symbols);
+
+ // and deserialize
+ ObjectInputStream objectIStream = new ObjectInputStream(
+ new ByteArrayInputStream(byteOStream.toByteArray()));
+ DateFormatSymbols symbolsD = (DateFormatSymbols) objectIStream
+ .readObject();
+
+ // The associated currency will not persist
+ String[][] zoneStringsD = symbolsD.getZoneStrings();
+ assertNotNull(zoneStringsD);
+ assertEquals(symbols, symbolsD);
+ }
}
diff --git a/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatTest.java b/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatTest.java
index e70aaf2..e7609a8 100644
--- a/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatTest.java
+++ b/text/src/test/java/org/apache/harmony/text/tests/java/text/DateFormatTest.java
@@ -1079,4 +1079,43 @@ public class DateFormatTest extends junit.framework.TestCase {
fail("Unexpected exception " + e.toString());
}
}
+
+ /**
+ * @tests java.text.DateFormat#parse(String)
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "parse",
+ args = {java.lang.String.class}
+ )
+ public void test_parse_LString() {
+ DateFormat format = DateFormat.getInstance();
+ try {
+ format.parse("not a Date");
+ fail("should throw ParseException first");
+ } catch (ParseException e) {
+ assertNotNull(e.getMessage());
+ }
+ }
+
+ /**
+ * @tests java.text.DateFormat#setLenient(boolean)
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "setLenient",
+ args = {boolean.class}
+ )
+ public void test_setLenient() {
+ Date d = null;
+ DateFormat output = new SimpleDateFormat("MM/dd/yy");
+ output.setLenient(false);
+ try {
+ d = output.parse("01/01/-1");
+ fail("Should throw ParseException here.");
+ } catch (ParseException e) {}
+ }
+
}
diff --git a/text/src/test/java/org/apache/harmony/text/tests/java/text/DecimalFormatSymbolsTest.java b/text/src/test/java/org/apache/harmony/text/tests/java/text/DecimalFormatSymbolsTest.java
index ce2e6d5..47107cd 100644
--- a/text/src/test/java/org/apache/harmony/text/tests/java/text/DecimalFormatSymbolsTest.java
+++ b/text/src/test/java/org/apache/harmony/text/tests/java/text/DecimalFormatSymbolsTest.java
@@ -149,8 +149,8 @@ public class DecimalFormatSymbolsTest extends TestCase {
@KnownFailure("some locales were removed last minute in cupcake")
public void test_getCurrency() {
Currency currency = Currency.getInstance("USD");
- assertTrue("Returned incorrect currency",
- dfsUS.getCurrency() == currency);
+ assertEquals("Returned incorrect currency",
+ dfsUS.getCurrency(), currency);
// use cs_CZ instead
//Currency currK = Currency.getInstance("KRW");
@@ -446,8 +446,8 @@ public class DecimalFormatSymbolsTest extends TestCase {
dfs.setCurrency(currency);
assertTrue("Returned incorrect currency", currency == dfs.getCurrency());
- assertTrue("Returned incorrect currency symbol", currency.getSymbol(
- locale).equals(dfs.getCurrencySymbol()));
+ assertEquals("Returned incorrect currency symbol", currency.getSymbol(
+ locale), dfs.getCurrencySymbol());
assertTrue("Returned incorrect international currency symbol", currency
.getCurrencyCode().equals(dfs.getInternationalCurrencySymbol()));
}
@@ -551,8 +551,8 @@ public class DecimalFormatSymbolsTest extends TestCase {
assertTrue("Test1: Returned incorrect currency", currency == dfs
.getCurrency());
- assertTrue("Test1: Returned incorrect currency symbol", currency
- .getSymbol(locale).equals(dfs.getCurrencySymbol()));
+ assertEquals("Test1: Returned incorrect currency symbol", currency
+ .getSymbol(locale), dfs.getCurrencySymbol());
assertTrue("Test1: Returned incorrect international currency symbol",
currency.getCurrencyCode().equals(
dfs.getInternationalCurrencySymbol()));
@@ -754,8 +754,43 @@ public class DecimalFormatSymbolsTest extends TestCase {
i.close();
}
} catch (Exception e) {
- // ignore
}
}
+ assertDecimalFormatSymbolsRIFrance(dfs);
+ }
+
+ static void assertDecimalFormatSymbolsRIFrance(DecimalFormatSymbols dfs) {
+ // Values based on Java 1.5 RI DecimalFormatSymbols for Locale.FRANCE
+ /*
+ * currency = [EUR]
+ * currencySymbol = [€][U+20ac]
+ * decimalSeparator = [,][U+002c]
+ * digit = [#][U+0023]
+ * groupingSeparator = [ ][U+00a0]
+ * infinity = [∞][U+221e]
+ * internationalCurrencySymbol = [EUR]
+ * minusSign = [-][U+002d]
+ * monetaryDecimalSeparator = [,][U+002c]
+ * naN = [�][U+fffd]
+ * patternSeparator = [;][U+003b]
+ * perMill = [‰][U+2030]
+ * percent = [%][U+0025]
+ * zeroDigit = [0][U+0030]
+ */
+ assertEquals("EUR", dfs.getCurrency().getCurrencyCode());
+ assertEquals("\u20AC", dfs.getCurrencySymbol());
+ assertEquals(',', dfs.getDecimalSeparator());
+ assertEquals('#', dfs.getDigit());
+ assertEquals('\u00a0', dfs.getGroupingSeparator());
+ assertEquals("\u221e", dfs.getInfinity());
+ assertEquals("EUR", dfs.getInternationalCurrencySymbol());
+ assertEquals('-', dfs.getMinusSign());
+ assertEquals(',', dfs.getMonetaryDecimalSeparator());
+ // RI's default NaN is U+FFFD, Harmony's is based on ICU
+ assertEquals("\uFFFD", dfs.getNaN());
+ assertEquals('\u003b', dfs.getPatternSeparator());
+ assertEquals('\u2030', dfs.getPerMill());
+ assertEquals('%', dfs.getPercent());
+ assertEquals('0', dfs.getZeroDigit());
}
}
diff --git a/text/src/test/java/org/apache/harmony/text/tests/java/text/DecimalFormatTest.java b/text/src/test/java/org/apache/harmony/text/tests/java/text/DecimalFormatTest.java
index a802ad8..aa36abc 100644
--- a/text/src/test/java/org/apache/harmony/text/tests/java/text/DecimalFormatTest.java
+++ b/text/src/test/java/org/apache/harmony/text/tests/java/text/DecimalFormatTest.java
@@ -31,6 +31,7 @@ import tests.support.Support_BitSet;
import tests.support.Support_DecimalFormat;
import java.io.ObjectInputStream;
+import java.io.IOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.text.AttributedCharacterIterator;
@@ -40,6 +41,7 @@ import java.text.FieldPosition;
import java.text.NumberFormat;
import java.text.ParseException;
import java.text.ParsePosition;
+import java.util.BitSet;
import java.util.Currency;
import java.util.Locale;
@@ -1495,7 +1497,7 @@ public class DecimalFormatTest extends TestCase {
.t_format_with_FieldPosition();
int failCount = 0;
- Support_BitSet failures = new Support_BitSet();
+ BitSet failures = new BitSet();
final DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US);
@@ -1729,7 +1731,7 @@ public class DecimalFormatTest extends TestCase {
@KnownFailure("Something seems wrong with Android implementation, here!")
public void test_formatJLjava_lang_StringBufferLjava_text_FieldPosition() {
int failCount = 0;
- Support_BitSet failures = new Support_BitSet();
+ BitSet failures = new BitSet();
final DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US);
@@ -2437,7 +2439,7 @@ public class DecimalFormatTest extends TestCase {
args = {}
)
@KnownFailure("a regression. This didn't fail before")
- public void test_serializationHarmonyRICompatible() {
+ public void test_serializationHarmonyRICompatible() throws Exception {
NumberFormat nf = NumberFormat.getInstance(Locale.FRANCE);
DecimalFormat df = null;
@@ -2455,8 +2457,6 @@ public class DecimalFormatTest extends TestCase {
oinput = new ObjectInputStream(this.getClass().getResource(
"/serialization/java/text/DecimalFormat.ser").openStream());
deserializedDF = (DecimalFormat) oinput.readObject();
- } catch (Exception e) {
- fail("Error occurs during deserialization");
} finally {
try {
if (null != oinput) {
@@ -2473,8 +2473,7 @@ public class DecimalFormatTest extends TestCase {
assertEquals(df.getPositiveSuffix(), deserializedDF.getPositiveSuffix());
assertEquals(df.getCurrency(), deserializedDF.getCurrency());
- assertEquals(df.getDecimalFormatSymbols(), deserializedDF
- .getDecimalFormatSymbols());
+ DecimalFormatSymbolsTest.assertDecimalFormatSymbolsRIFrance(deserializedDF.getDecimalFormatSymbols());
assertEquals(df.getGroupingSize(), df.getGroupingSize());
assertEquals(df.getMaximumFractionDigits(), deserializedDF
@@ -2545,11 +2544,7 @@ public class DecimalFormatTest extends TestCase {
)
public void testSetDecimalFormatSymbolsAsNull() {
// Regression for HARMONY-1070
- try {
- DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance();
- format.setDecimalFormatSymbols(null);
- } catch (Exception e) {
- fail("Unexpected exception caught: " + e);
- }
+ DecimalFormat format = (DecimalFormat) DecimalFormat.getInstance();
+ format.setDecimalFormatSymbols(null);
}
}
diff --git a/text/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatTest.java b/text/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatTest.java
index 0265a51..57a1206 100644
--- a/text/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatTest.java
+++ b/text/src/test/java/org/apache/harmony/text/tests/java/text/MessageFormatTest.java
@@ -145,22 +145,15 @@ public class MessageFormatTest extends TestCase {
assertEquals("Simple string", "Test message", new MessageFormat(
"Test message").format(new Object[0]));
- try {
- result = new MessageFormat("Don't").format(new Object[0]);
- assertTrue("Should not throw IllegalArgumentException: " + result,
+ result = new MessageFormat("Don't").format(new Object[0]);
+ assertTrue("Should not throw IllegalArgumentException: " + result,
"Dont".equals(result));
- } catch (Exception e) {
- fail("Unexpected exception: " + e);
- }
try {
new MessageFormat("Invalid {1,foobar} format descriptor!");
fail("Expected test_ConstructorLjava_lang_String to throw IAE.");
} catch (IllegalArgumentException ex) {
// expected
- } catch (Throwable ex) {
- fail("Expected test_ConstructorLjava_lang_String to throw IAE, not a "
- + ex.getClass().getName());
}
try {
@@ -168,9 +161,6 @@ public class MessageFormatTest extends TestCase {
"Invalid {1,date,invalid-spec} format descriptor!");
} catch (IllegalArgumentException ex) {
// expected
- } catch (Throwable ex) {
- fail("Expected test_ConstructorLjava_lang_String to throw IAE, not a "
- + ex.getClass().getName());
}
checkSerialization(new MessageFormat(""));
@@ -1177,10 +1167,10 @@ public class MessageFormatTest extends TestCase {
* java.text.MessageFormat#parse(java.lang.String).
*/
@TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "parse",
- args = {java.lang.String.class}
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "parse",
+ args = {java.lang.String.class}
)
public void test_parseLjava_lang_String() throws ParseException {
String pattern = "A {3, number, currency} B {2, time} C {0, number, percent} D {4} E {1,choice,0#off|1#on} F {0, date}";
@@ -1242,10 +1232,10 @@ public class MessageFormatTest extends TestCase {
* argument ParsePosition as null.
*/
@TestTargetNew(
- level = TestLevel.COMPLETE,
- notes = "",
- method = "parseObject",
- args = {java.lang.String.class, java.text.ParsePosition.class}
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "parseObject",
+ args = {java.lang.String.class, java.text.ParsePosition.class}
)
public void test_parseObjectLjava_lang_StringLjavajava_text_ParsePosition() {
MessageFormat mf = new MessageFormat("{0,number,#.##}, {0,number,#.#}");
@@ -1288,10 +1278,10 @@ public class MessageFormatTest extends TestCase {
}
}
@TestTargetNew(
- level = TestLevel.PARTIAL,
- notes = "Regression test. Doesn't verifies exception.",
- method = "format",
- args = {java.lang.Object.class}
+ level = TestLevel.PARTIAL,
+ notes = "Regression test. Doesn't verifies exception.",
+ method = "format",
+ args = {java.lang.Object.class}
)
public void test_format_Object() {
// Regression for HARMONY-1875
@@ -1304,4 +1294,35 @@ public class MessageFormatTest extends TestCase {
assertEquals(etalon, obj.format(new Object[] { new Date() }));
}
+ /**
+ * @tests java.text.MessageFormat#parse(java.lang.String)
+ */
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "parse",
+ args = {java.lang.String.class}
+ )
+ public void test_parse() throws ParseException {
+ // Regression for HARMONY-63
+ MessageFormat mf = new MessageFormat("{0,number,#,####}", Locale.US);
+ Object[] res = mf.parse("1,00,00");
+ assertEquals("Assert 0: incorrect size of parsed data ", 1, res.length);
+ assertEquals("Assert 1: parsed value incorrectly", new Long(10000), (Long)res[0]);
+ }
+
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "",
+ method = "format",
+ args = {java.lang.String.class, java.lang.Object[].class}
+ )
+ public void testHARMONY5323() {
+ Object []messageArgs = new Object[11];
+ for (int i = 0; i < messageArgs.length; i++)
+ messageArgs[i] = "dumb"+i;
+
+ String res = MessageFormat.format("bgcolor=\"{10}\"", messageArgs);
+ assertEquals(res, "bgcolor=\"dumb10\"");
+ }
}
diff --git a/text/src/test/java/org/apache/harmony/text/tests/java/text/NumberFormatTest.java b/text/src/test/java/org/apache/harmony/text/tests/java/text/NumberFormatTest.java
index 93e58db..0480704 100644
--- a/text/src/test/java/org/apache/harmony/text/tests/java/text/NumberFormatTest.java
+++ b/text/src/test/java/org/apache/harmony/text/tests/java/text/NumberFormatTest.java
@@ -206,7 +206,7 @@ public class NumberFormatTest extends TestCase {
"#,##0;#,##0-", format.toPattern());
assertEquals(
"Test8: NumberFormat.getIntegerInstance(new Locale(\"ar\", \"AE\")).format(-35.76) returned wrong value",
- "36-", format.format(-35.76));
+ "\u0666-", format.format(-6));
assertEquals(
"Test9: NumberFormat.getIntegerInstance(new Locale(\"ar\", \"AE\")).parse(\"-36-\") returned wrong number",
new Long(-36), format.parse("36-"));
diff --git a/text/src/test/java/org/apache/harmony/text/tests/java/text/ParsePositionTest.java b/text/src/test/java/org/apache/harmony/text/tests/java/text/ParsePositionTest.java
index 9c1fb21..89cb7e4 100644
--- a/text/src/test/java/org/apache/harmony/text/tests/java/text/ParsePositionTest.java
+++ b/text/src/test/java/org/apache/harmony/text/tests/java/text/ParsePositionTest.java
@@ -39,15 +39,10 @@ public class ParsePositionTest extends junit.framework.TestCase {
)
public void test_ConstructorI() {
// Test for method java.text.ParsePosition(int)
- try {
- ParsePosition pp1 = new ParsePosition(Integer.MIN_VALUE);
- assertTrue("Initialization failed.",
- pp1.getIndex() == Integer.MIN_VALUE);
- assertEquals("Initialization failed.", -1, pp1.getErrorIndex());
- } catch (Exception e) {
- fail("Constructor failed.");
- }
-
+ ParsePosition pp1 = new ParsePosition(Integer.MIN_VALUE);
+ assertTrue("Initialization failed.",
+ pp1.getIndex() == Integer.MIN_VALUE);
+ assertEquals("Initialization failed.", -1, pp1.getErrorIndex());
}
/**
diff --git a/text/src/test/java/org/apache/harmony/text/tests/java/text/Support_DecimalFormat.java b/text/src/test/java/org/apache/harmony/text/tests/java/text/Support_DecimalFormat.java
new file mode 100644
index 0000000..2fe1107
--- /dev/null
+++ b/text/src/test/java/org/apache/harmony/text/tests/java/text/Support_DecimalFormat.java
@@ -0,0 +1,287 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.text.tests.java.text;
+
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
+import java.util.Locale;
+import java.util.Vector;
+
+
+public class Support_DecimalFormat extends Support_Format {
+
+ public Support_DecimalFormat(String p1) {
+ super(p1);
+ }
+
+ @Override
+ public void runTest() {
+ t_formatToCharacterIterator();
+ t_format_with_FieldPosition();
+ }
+
+ public static void main(String[] args) {
+ new Support_DecimalFormat("").runTest();
+ }
+
+ public void t_format_with_FieldPosition() {
+ DecimalFormat format = (DecimalFormat) NumberFormat
+ .getCurrencyInstance(Locale.US);
+ Number number = new Double(10000000.76);
+ String text = "$10,000,000.76";
+
+ t_FormatWithField(0, format, number, text, NumberFormat.Field.CURRENCY,
+ 0, 1);
+ t_FormatWithField(1, format, number, text, NumberFormat.Field.INTEGER,
+ 1, 11);
+ t_FormatWithField(2, format, number, text,
+ NumberFormat.Field.GROUPING_SEPARATOR, 3, 4);
+ t_FormatWithField(3, format, number, text,
+ NumberFormat.Field.DECIMAL_SEPARATOR, 11, 12);
+ t_FormatWithField(4, format, number, text, NumberFormat.Field.FRACTION,
+ 12, 14);
+
+ // test fields that are not included in the formatted text
+ t_FormatWithField(5, format, number, text, NumberFormat.Field.SIGN, 0,
+ 0);
+ t_FormatWithField(6, format, number, text, NumberFormat.Field.EXPONENT,
+ 0, 0);
+ t_FormatWithField(7, format, number, text,
+ NumberFormat.Field.EXPONENT_SIGN, 0, 0);
+ t_FormatWithField(8, format, number, text,
+ NumberFormat.Field.EXPONENT_SYMBOL, 0, 0);
+ t_FormatWithField(9, format, number, text, NumberFormat.Field.PERCENT,
+ 0, 0);
+ t_FormatWithField(10, format, number, text,
+ NumberFormat.Field.PERMILLE, 0, 0);
+
+ // test Exponential
+ format = new DecimalFormat("000000000.0#E0");
+ text = "100000007.6E-1";
+ t_FormatWithField(11, format, number, text, NumberFormat.Field.INTEGER,
+ 0, 9);
+ t_FormatWithField(12, format, number, text,
+ NumberFormat.Field.DECIMAL_SEPARATOR, 9, 10);
+ t_FormatWithField(13, format, number, text,
+ NumberFormat.Field.FRACTION, 10, 11);
+ t_FormatWithField(14, format, number, text,
+ NumberFormat.Field.EXPONENT_SYMBOL, 11, 12);
+ t_FormatWithField(15, format, number, text,
+ NumberFormat.Field.EXPONENT_SIGN, 12, 13);
+ t_FormatWithField(16, format, number, text,
+ NumberFormat.Field.EXPONENT, 13, 14);
+
+ // test fields that are not included in the formatted text
+ t_FormatWithField(17, format, number, text,
+ NumberFormat.Field.GROUPING_SEPARATOR, 0, 0);
+ t_FormatWithField(18, format, number, text, NumberFormat.Field.SIGN, 0,
+ 0);
+ t_FormatWithField(19, format, number, text,
+ NumberFormat.Field.CURRENCY, 0, 0);
+ t_FormatWithField(20, format, number, text, NumberFormat.Field.PERCENT,
+ 0, 0);
+ t_FormatWithField(21, format, number, text,
+ NumberFormat.Field.PERMILLE, 0, 0);
+
+ // test currency instance with TR Locale
+ number = new Double(350.76);
+ format = (DecimalFormat) NumberFormat.getCurrencyInstance(new Locale(
+ "tr", "TR"));
+ text = "351 TL";
+ t_FormatWithField(22, format, number, text, NumberFormat.Field.INTEGER,
+ 0, 3);
+ t_FormatWithField(23, format, number, text,
+ NumberFormat.Field.CURRENCY, 4, 6);
+
+ // test fields that are not included in the formatted text
+ t_FormatWithField(25, format, number, text,
+ NumberFormat.Field.GROUPING_SEPARATOR, 0, 0);
+ t_FormatWithField(26, format, number, text,
+ NumberFormat.Field.DECIMAL_SEPARATOR, 0, 0);
+ t_FormatWithField(27, format, number, text, NumberFormat.Field.SIGN, 0,
+ 0);
+ t_FormatWithField(28, format, number, text,
+ NumberFormat.Field.EXPONENT, 0, 0);
+ t_FormatWithField(29, format, number, text,
+ NumberFormat.Field.EXPONENT_SIGN, 0, 0);
+ t_FormatWithField(30, format, number, text,
+ NumberFormat.Field.EXPONENT_SYMBOL, 0, 0);
+ t_FormatWithField(31, format, number, text, NumberFormat.Field.PERCENT,
+ 0, 0);
+ t_FormatWithField(32, format, number, text,
+ NumberFormat.Field.PERMILLE, 0, 0);
+
+ }
+
+ public void t_formatToCharacterIterator() {
+
+ Number number = new Double(350.76);
+ Number negativeNumber = new Double(-350.76);
+
+ Locale us = Locale.US;
+ Locale tr = new Locale("tr", "TR");
+
+ // test number instance
+ t_Format(1, number, NumberFormat.getNumberInstance(us),
+ getNumberVectorUS());
+
+ // test integer instance
+ // testFormat(2, number, NumberFormat.getIntegerInstance(us),
+ // getPercentVectorUS());
+
+ // test percent instance
+ t_Format(3, number, NumberFormat.getPercentInstance(us),
+ getPercentVectorUS());
+
+ // test permille pattern
+ DecimalFormat format = new DecimalFormat("###0.##\u2030");
+ t_Format(4, number, format, getPermilleVector());
+
+ // test exponential pattern with positive exponent
+ format = new DecimalFormat("00.0#E0");
+ t_Format(5, number, format, getPositiveExponentVector());
+
+ // test exponential pattern with negative exponent
+ format = new DecimalFormat("0000.0#E0");
+ t_Format(6, number, format, getNegativeExponentVector());
+
+ // test currency instance with US Locale
+ t_Format(7, number, NumberFormat.getCurrencyInstance(us),
+ getPositiveCurrencyVectorUS());
+
+ // test negative currency instance with US Locale
+ t_Format(8, negativeNumber, NumberFormat.getCurrencyInstance(us),
+ getNegativeCurrencyVectorUS());
+
+ // test currency instance with TR Locale
+ t_Format(9, number, NumberFormat.getCurrencyInstance(tr),
+ getPositiveCurrencyVectorTR());
+
+ // test negative currency instance with TR Locale
+ t_Format(10, negativeNumber, NumberFormat.getCurrencyInstance(tr),
+ getNegativeCurrencyVectorTR());
+
+ // test multiple grouping seperators
+ number = new Long(100300400);
+ t_Format(11, number, NumberFormat.getNumberInstance(us),
+ getNumberVector2US());
+
+ // test 0
+ number = new Long(0);
+ t_Format(12, number, NumberFormat.getNumberInstance(us),
+ getZeroVector());
+ }
+
+ private static Vector getNumberVectorUS() {
+ Vector v = new Vector();
+ v.add(new FieldContainer(0, 3, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(3, 4, NumberFormat.Field.DECIMAL_SEPARATOR));
+ v.add(new FieldContainer(4, 6, NumberFormat.Field.FRACTION));
+ return v;
+ }
+
+ private static Vector getPositiveCurrencyVectorTR() {
+ Vector v = new Vector();
+ v.add(new FieldContainer(0, 3, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(4, 6, NumberFormat.Field.CURRENCY));
+ return v;
+ }
+
+ private static Vector getNegativeCurrencyVectorTR() {
+ Vector v = new Vector();
+ v.add(new FieldContainer(0, 1, NumberFormat.Field.SIGN));
+ v.add(new FieldContainer(1, 4, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(5, 7, NumberFormat.Field.CURRENCY));
+ return v;
+ }
+
+ private static Vector getPositiveCurrencyVectorUS() {
+ Vector v = new Vector();
+ v.add(new FieldContainer(0, 1, NumberFormat.Field.CURRENCY));
+ v.add(new FieldContainer(1, 4, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(4, 5, NumberFormat.Field.DECIMAL_SEPARATOR));
+ v.add(new FieldContainer(5, 7, NumberFormat.Field.FRACTION));
+ return v;
+ }
+
+ private static Vector getNegativeCurrencyVectorUS() {
+ Vector v = new Vector();
+ v.add(new FieldContainer(1, 2, NumberFormat.Field.CURRENCY));
+ v.add(new FieldContainer(2, 5, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(5, 6, NumberFormat.Field.DECIMAL_SEPARATOR));
+ v.add(new FieldContainer(6, 8, NumberFormat.Field.FRACTION));
+ return v;
+ }
+
+ private static Vector getPercentVectorUS() {
+ Vector v = new Vector();
+ v.add(new FieldContainer(0, 2, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(2, 3, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(2, 3, NumberFormat.Field.GROUPING_SEPARATOR));
+ v.add(new FieldContainer(3, 6, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(6, 7, NumberFormat.Field.PERCENT));
+ return v;
+ }
+
+ private static Vector getPermilleVector() {
+ Vector v = new Vector();
+ v.add(new FieldContainer(0, 6, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(6, 7, NumberFormat.Field.PERMILLE));
+ return v;
+ }
+
+ private static Vector getNegativeExponentVector() {
+ Vector v = new Vector();
+ v.add(new FieldContainer(0, 4, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(4, 5, NumberFormat.Field.DECIMAL_SEPARATOR));
+ v.add(new FieldContainer(5, 6, NumberFormat.Field.FRACTION));
+ v.add(new FieldContainer(6, 7, NumberFormat.Field.EXPONENT_SYMBOL));
+ v.add(new FieldContainer(7, 8, NumberFormat.Field.EXPONENT_SIGN));
+ v.add(new FieldContainer(8, 9, NumberFormat.Field.EXPONENT));
+ return v;
+ }
+
+ private static Vector getPositiveExponentVector() {
+ Vector v = new Vector();
+ v.add(new FieldContainer(0, 2, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(2, 3, NumberFormat.Field.DECIMAL_SEPARATOR));
+ v.add(new FieldContainer(3, 5, NumberFormat.Field.FRACTION));
+ v.add(new FieldContainer(5, 6, NumberFormat.Field.EXPONENT_SYMBOL));
+ v.add(new FieldContainer(6, 7, NumberFormat.Field.EXPONENT));
+ return v;
+ }
+
+ private static Vector getNumberVector2US() {
+ Vector v = new Vector();
+ v.add(new FieldContainer(0, 3, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(3, 4, NumberFormat.Field.GROUPING_SEPARATOR));
+ v.add(new FieldContainer(3, 4, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(4, 7, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(7, 8, NumberFormat.Field.GROUPING_SEPARATOR));
+ v.add(new FieldContainer(7, 8, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(8, 11, NumberFormat.Field.INTEGER));
+ return v;
+ }
+
+ private static Vector getZeroVector() {
+ Vector v = new Vector();
+ v.add(new FieldContainer(0, 1, NumberFormat.Field.INTEGER));
+ return v;
+ }
+
+}
diff --git a/text/src/test/java/org/apache/harmony/text/tests/java/text/Support_Format.java b/text/src/test/java/org/apache/harmony/text/tests/java/text/Support_Format.java
new file mode 100644
index 0000000..ffcdf1c
--- /dev/null
+++ b/text/src/test/java/org/apache/harmony/text/tests/java/text/Support_Format.java
@@ -0,0 +1,143 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.text.tests.java.text;
+
+import java.text.AttributedCharacterIterator;
+import java.text.FieldPosition;
+import java.text.Format;
+import java.text.AttributedCharacterIterator.Attribute;
+import java.util.Iterator;
+import java.util.Vector;
+import junit.framework.TestCase;
+
+public class Support_Format extends TestCase {
+
+ protected String text;
+
+ public Support_Format(String p1) {
+ super(p1);
+ }
+
+ protected void t_FormatWithField(int count, Format format, Object object,
+ String text, Format.Field field, int begin, int end) {
+ StringBuffer buffer = new StringBuffer();
+ FieldPosition pos = new FieldPosition(field);
+ format.format(object, buffer, pos);
+
+ // System.out.println(buffer);
+ // System.out.println(pos);
+
+ if (text == null) {
+ assertEquals("Test " + count + ": incorrect formatted text",
+ this.text, buffer.toString());
+ } else {
+ assertEquals("Test " + count + ": incorrect formatted text", text,
+ buffer.toString());
+ }
+
+ assertEquals("Test " + count + ": incorrect begin index for field "
+ + field, begin, pos.getBeginIndex());
+ assertEquals("Test " + count + ": incorrect end index for field"
+ + field, end, pos.getEndIndex());
+ }
+
+ protected void t_Format(int count, Object object, Format format,
+ Vector expectedResults) {
+ // System.out.println(format.format(object));
+ Vector results = findFields(format.formatToCharacterIterator(object));
+ assertTrue("Test " + count
+ + ": Format returned incorrect CharacterIterator for "
+ + format.format(object), compare(results, expectedResults));
+ }
+
+ /**
+ * compares two vectors regardless of the order of their elements
+ */
+ protected static boolean compare(Vector vector1, Vector vector2) {
+ return vector1.size() == vector2.size() && vector1.containsAll(vector2);
+ }
+
+ /**
+ * finds attributes with regards to char index in this
+ * AttributedCharacterIterator, and puts them in a vector
+ *
+ * @param iterator
+ * @return a vector, each entry in this vector are of type FieldContainer ,
+ * which stores start and end indexes and an attribute this range
+ * has
+ */
+ protected static Vector findFields(AttributedCharacterIterator iterator) {
+ Vector result = new Vector();
+ while (iterator.getIndex() != iterator.getEndIndex()) {
+ int start = iterator.getRunStart();
+ int end = iterator.getRunLimit();
+
+ Iterator it = iterator.getAttributes().keySet().iterator();
+ while (it.hasNext()) {
+ AttributedCharacterIterator.Attribute attribute = it.next();
+ Object value = iterator.getAttribute(attribute);
+ result.add(new FieldContainer(start, end, attribute, value));
+ // System.out.println(start + " " + end + ": " + attribute + ",
+ // " + value );
+ // System.out.println("v.add(new FieldContainer(" + start +"," +
+ // end +"," + attribute+ "," + value+ "));");
+ }
+ iterator.setIndex(end);
+ }
+ return result;
+ }
+
+ protected static class FieldContainer {
+ int start, end;
+
+ AttributedCharacterIterator.Attribute attribute;
+
+ Object value;
+
+ // called from support_decimalformat and support_simpledateformat tests
+ public FieldContainer(int start, int end,
+ AttributedCharacterIterator.Attribute attribute) {
+ this(start, end, attribute, attribute);
+ }
+
+ // called from support_messageformat tests
+ public FieldContainer(int start, int end, Attribute attribute, int value) {
+ this(start, end, attribute, new Integer(value));
+ }
+
+ // called from support_messageformat tests
+ public FieldContainer(int start, int end, Attribute attribute,
+ Object value) {
+ this.start = start;
+ this.end = end;
+ this.attribute = attribute;
+ this.value = value;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof FieldContainer)) {
+ return false;
+ }
+
+ FieldContainer fc = (FieldContainer) obj;
+ return (start == fc.start && end == fc.end
+ && attribute == fc.attribute && value.equals(fc.value));
+ }
+ }
+}
diff --git a/text/src/test/java/org/apache/harmony/text/tests/java/text/Support_MessageFormat.java b/text/src/test/java/org/apache/harmony/text/tests/java/text/Support_MessageFormat.java
new file mode 100644
index 0000000..454caeb
--- /dev/null
+++ b/text/src/test/java/org/apache/harmony/text/tests/java/text/Support_MessageFormat.java
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.text.tests.java.text;
+
+import java.text.DateFormat;
+import java.text.MessageFormat;
+import java.text.NumberFormat;
+import java.text.MessageFormat.Field;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.Locale;
+import java.util.Vector;
+
+
+public class Support_MessageFormat extends Support_Format {
+
+ public Support_MessageFormat(String p1) {
+ super(p1);
+ }
+
+ @Override
+ public void runTest() {
+ t_formatToCharacterIterator();
+ t_format_with_FieldPosition();
+ }
+
+ public static void main(String[] args) {
+ new Support_MessageFormat("").runTest();
+ }
+
+ public void t_format_with_FieldPosition() {
+
+ String pattern = "On {4,date} at {3,time}, he ate {2,number, integer} hamburger{2,choice,1#|1 getMessageVector1() {
+ Vector v = new Vector();
+ v.add(new FieldContainer(3, 6, Field.ARGUMENT, 4));
+ v.add(new FieldContainer(3, 6, DateFormat.Field.MONTH));
+ v.add(new FieldContainer(6, 7, Field.ARGUMENT, 4));
+ v.add(new FieldContainer(7, 9, Field.ARGUMENT, 4));
+ v.add(new FieldContainer(7, 9, DateFormat.Field.DAY_OF_MONTH));
+ v.add(new FieldContainer(9, 11, Field.ARGUMENT, 4));
+ v.add(new FieldContainer(11, 15, Field.ARGUMENT, 4));
+ v.add(new FieldContainer(11, 15, DateFormat.Field.YEAR));
+ v.add(new FieldContainer(19, 20, Field.ARGUMENT, 3));
+ v.add(new FieldContainer(19, 20, DateFormat.Field.HOUR1));
+ v.add(new FieldContainer(20, 21, Field.ARGUMENT, 3));
+ v.add(new FieldContainer(21, 23, Field.ARGUMENT, 3));
+ v.add(new FieldContainer(21, 23, DateFormat.Field.MINUTE));
+ v.add(new FieldContainer(23, 24, Field.ARGUMENT, 3));
+ v.add(new FieldContainer(24, 26, Field.ARGUMENT, 3));
+ v.add(new FieldContainer(24, 26, DateFormat.Field.SECOND));
+ v.add(new FieldContainer(26, 27, Field.ARGUMENT, 3));
+ v.add(new FieldContainer(27, 29, Field.ARGUMENT, 3));
+ v.add(new FieldContainer(27, 29, DateFormat.Field.AM_PM));
+ v.add(new FieldContainer(38, 39, Field.ARGUMENT, 2));
+ v.add(new FieldContainer(38, 39, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(49, 50, Field.ARGUMENT, 2));
+ v.add(new FieldContainer(61, 62, Field.ARGUMENT, 1));
+ v.add(new FieldContainer(61, 62, NumberFormat.Field.INTEGER));
+ v.add(new FieldContainer(62, 63, Field.ARGUMENT, 1));
+ v.add(new FieldContainer(62, 63, NumberFormat.Field.DECIMAL_SEPARATOR));
+ v.add(new FieldContainer(63, 64, Field.ARGUMENT, 1));
+ v.add(new FieldContainer(63, 64, NumberFormat.Field.FRACTION));
+ v.add(new FieldContainer(90, 106, Field.ARGUMENT, 0));
+ return v;
+ }
+
+}
diff --git a/text/src/test/java/org/apache/harmony/text/tests/java/text/Support_SimpleDateFormat.java b/text/src/test/java/org/apache/harmony/text/tests/java/text/Support_SimpleDateFormat.java
new file mode 100644
index 0000000..24a436b
--- /dev/null
+++ b/text/src/test/java/org/apache/harmony/text/tests/java/text/Support_SimpleDateFormat.java
@@ -0,0 +1,266 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.harmony.text.tests.java.text;
+
+import java.text.DateFormat;
+import java.text.NumberFormat;
+import java.text.SimpleDateFormat;
+import java.text.DateFormat.Field;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.Locale;
+import java.util.TimeZone;
+import java.util.Vector;
+
+import org.apache.harmony.text.tests.java.text.Support_Format.FieldContainer;
+
+
+public class Support_SimpleDateFormat extends Support_Format {
+
+ public Support_SimpleDateFormat(String p1) {
+ super(p1);
+ }
+
+ @Override
+ public void runTest() {
+ t_formatToCharacterIterator();
+ t_format_with_FieldPosition();
+ }
+
+ public static void main(String[] args) {
+ new Support_SimpleDateFormat("").runTest();
+ }
+
+ public void t_format_with_FieldPosition() {
+ TimeZone tz = TimeZone.getTimeZone("EST");
+ Calendar cal = new GregorianCalendar(tz);
+ cal.set(1999, Calendar.SEPTEMBER, 13, 17, 19, 01);
+ cal.set(Calendar.MILLISECOND, 0);
+ Date date = cal.getTime();
+ SimpleDateFormat format = (SimpleDateFormat) DateFormat
+ .getDateInstance(DateFormat.DEFAULT, Locale.US);
+ format.setTimeZone(tz);
+
+ // test with all pattern chars, and multiple occurances
+ format
+ .applyPattern("G GGGG y yy yyyy M MM MMM MMMM d dd ddd k kk kkk H HH HHH h hh hhh m mmm s ss sss S SS SSS EE EEEE D DD DDD F FF w www W WWW a aaa K KKK z zzzz Z ZZZZ");
+
+ StringBuffer textbuffer = new StringBuffer(
+ "AD Anno Domini 99 99 1999 9 09 Sep September 13 13 013 17 17 017 17 17 017 5 05");
+ textbuffer
+ .append(" 005 19 019 1 01 001 0 00 000 Mon Monday 256 256 256 2 02 38 038 3 003 PM");
+ textbuffer.append(" PM 5 005 GMT-05:00 GMT-05:00 -0500 GMT-05:00");
+
+ // to avoid passing the huge Stringbuffer each time.
+ super.text = textbuffer.toString();
+
+ // test if field positions are set correctly for these fields occuring
+ // multiple times.
+ t_FormatWithField(0, format, date, null, Field.ERA, 0, 2);
+ t_FormatWithField(1, format, date, null, Field.YEAR, 15, 17);
+ t_FormatWithField(2, format, date, null, Field.MONTH, 26, 27);
+ t_FormatWithField(3, format, date, null, Field.DAY_OF_MONTH, 45, 47);
+ t_FormatWithField(4, format, date, null, Field.HOUR_OF_DAY1, 55, 57);
+ t_FormatWithField(5, format, date, null, Field.HOUR_OF_DAY0, 65, 67);
+ t_FormatWithField(6, format, date, null, Field.HOUR1, 75, 76);
+ t_FormatWithField(7, format, date, null, Field.MINUTE, 84, 86);
+ t_FormatWithField(8, format, date, null, Field.SECOND, 91, 92);
+ t_FormatWithField(9, format, date, null, Field.MILLISECOND, 100, 101);
+ t_FormatWithField(10, format, date, null, Field.DAY_OF_WEEK, 109, 112);
+ t_FormatWithField(11, format, date, null, Field.DAY_OF_YEAR, 120, 123);
+ t_FormatWithField(12, format, date, null, Field.DAY_OF_WEEK_IN_MONTH,
+ 132, 133);
+ t_FormatWithField(13, format, date, null, Field.WEEK_OF_YEAR, 137, 139);
+ t_FormatWithField(14, format, date, null, Field.WEEK_OF_MONTH, 144, 145);
+ t_FormatWithField(15, format, date, null, Field.AM_PM, 150, 152);
+ t_FormatWithField(16, format, date, null, Field.HOUR0, 158, 159);
+ t_FormatWithField(17, format, date, null, Field.TIME_ZONE, 164, 173);
+
+ // test fields that are not included in the formatted text
+ t_FormatWithField(18, format, date, null,
+ NumberFormat.Field.EXPONENT_SIGN, 0, 0);
+
+ // test with simple example
+ format.applyPattern("h:m z");
+
+ super.text = "5:19 GMT-05:00";
+ t_FormatWithField(21, format, date, null, Field.HOUR1, 0, 1);
+ t_FormatWithField(22, format, date, null, Field.MINUTE, 2, 4);
+ t_FormatWithField(23, format, date, null, Field.TIME_ZONE, 5, 14);
+
+ // test fields that are not included in the formatted text
+
+ t_FormatWithField(24, format, date, null, Field.ERA, 0, 0);
+ t_FormatWithField(25, format, date, null, Field.YEAR, 0, 0);
+ t_FormatWithField(26, format, date, null, Field.MONTH, 0, 0);
+ t_FormatWithField(27, format, date, null, Field.DAY_OF_MONTH, 0, 0);
+ t_FormatWithField(28, format, date, null, Field.HOUR_OF_DAY1, 0, 0);
+ t_FormatWithField(29, format, date, null, Field.HOUR_OF_DAY0, 0, 0);
+ t_FormatWithField(30, format, date, null, Field.SECOND, 0, 0);
+ t_FormatWithField(31, format, date, null, Field.MILLISECOND, 0, 0);
+ t_FormatWithField(32, format, date, null, Field.DAY_OF_WEEK, 0, 0);
+ t_FormatWithField(33, format, date, null, Field.DAY_OF_YEAR, 0, 0);
+ t_FormatWithField(34, format, date, null, Field.DAY_OF_WEEK_IN_MONTH,
+ 0, 0);
+ t_FormatWithField(35, format, date, null, Field.WEEK_OF_YEAR, 0, 0);
+ t_FormatWithField(36, format, date, null, Field.WEEK_OF_MONTH, 0, 0);
+ t_FormatWithField(37, format, date, null, Field.AM_PM, 0, 0);
+ t_FormatWithField(38, format, date, null, Field.HOUR0, 0, 0);
+
+ t_FormatWithField(39, format, date, null, NumberFormat.Field.EXPONENT,
+ 0, 0);
+
+ // test with simple example with pattern char Z
+ format.applyPattern("h:m Z z");
+ super.text = "5:19 -0500 GMT-05:00";
+ t_FormatWithField(40, format, date, null, Field.HOUR1, 0, 1);
+ t_FormatWithField(41, format, date, null, Field.MINUTE, 2, 4);
+ t_FormatWithField(42, format, date, null, Field.TIME_ZONE, 5, 10);
+ }
+
+ public void t_formatToCharacterIterator() {
+ TimeZone tz = TimeZone.getTimeZone("EST");
+ Calendar cal = new GregorianCalendar(tz);
+ cal.set(1999, Calendar.SEPTEMBER, 13, 17, 19, 01);
+ cal.set(Calendar.MILLISECOND, 0);
+ Date date = cal.getTime();
+ SimpleDateFormat format = (SimpleDateFormat) DateFormat
+ .getDateInstance(DateFormat.DEFAULT, Locale.US);
+ format.setTimeZone(tz);
+
+ format.applyPattern("yyyyMMddHHmmss");
+ t_Format(1, date, format, getDateVector1());
+
+ format.applyPattern("w W dd MMMM yyyy EEEE");
+ t_Format(2, date, format, getDateVector2());
+
+ format.applyPattern("h:m z");
+ t_Format(3, date, format, getDateVector3());
+
+ format.applyPattern("h:m Z");
+ t_Format(5, date, format, getDateVector5());
+
+ // with all pattern chars, and multiple occurances
+ format
+ .applyPattern("G GGGG y yy yyyy M MM MMM MMMM d dd ddd k kk kkk H HH HHH h hh hhh m mmm s ss sss S SS SSS EE EEEE D DD DDD F FF w www W WWW a aaa K KKK z zzzz Z ZZZZ");
+ t_Format(4, date, format, getDateVector4());
+ }
+
+ private Vector getDateVector1() {
+ // "19990913171901"
+ Vector v = new Vector();
+ v.add(new FieldContainer(0, 4, Field.YEAR));
+ v.add(new FieldContainer(4, 6, Field.MONTH));
+ v.add(new FieldContainer(6, 8, Field.DAY_OF_MONTH));
+ v.add(new FieldContainer(8, 10, Field.HOUR_OF_DAY0));
+ v.add(new FieldContainer(10, 12, Field.MINUTE));
+ v.add(new FieldContainer(12, 14, Field.SECOND));
+ return v;
+ }
+
+ private Vector getDateVector2() {
+ // "12 3 5 March 2002 Monday"
+ Vector v = new Vector();
+ v.add(new FieldContainer(0, 2, Field.WEEK_OF_YEAR));
+ v.add(new FieldContainer(3, 4, Field.WEEK_OF_MONTH));
+ v.add(new FieldContainer(5, 7, Field.DAY_OF_MONTH));
+ v.add(new FieldContainer(8, 17, Field.MONTH));
+ v.add(new FieldContainer(18, 22, Field.YEAR));
+ v.add(new FieldContainer(23, 29, Field.DAY_OF_WEEK));
+ return v;
+ }
+
+ private Vector getDateVector3() {
+ // "5:19 EDT"
+ Vector v = new Vector();
+ v.add(new FieldContainer(0, 1, Field.HOUR1));
+ v.add(new FieldContainer(2, 4, Field.MINUTE));
+ v.add(new FieldContainer(5, 14, Field.TIME_ZONE));
+ return v;
+ }
+
+ private Vector getDateVector5() {
+ // "5:19 -0400"
+ Vector v = new Vector();
+ v.add(new FieldContainer(0, 1, Field.HOUR1));
+ v.add(new FieldContainer(2, 4, Field.MINUTE));
+ v.add(new FieldContainer(5, 10, Field.TIME_ZONE));
+ return v;
+ }
+
+ private Vector getDateVector4() {
+ Vector v = new Vector();
+
+ // "AD AD 99 99 1999 9 09 Sep September 13 13 013 17 17 017 17 17 017 5
+ // 05
+ // 005 19 019 1 01 001 0 00 000 Mon Monday 256 256 256 2 02 38 038 3 003
+ // PM
+ // PM 5 005 EDT Eastern Daylight Time -0400 -0400"
+ v.add(new FieldContainer(0, 2, Field.ERA));
+ v.add(new FieldContainer(3, 5, Field.ERA));
+ v.add(new FieldContainer(6, 8, Field.YEAR));
+ v.add(new FieldContainer(9, 11, Field.YEAR));
+ v.add(new FieldContainer(12, 16, Field.YEAR));
+ v.add(new FieldContainer(17, 18, Field.MONTH));
+ v.add(new FieldContainer(19, 21, Field.MONTH));
+ v.add(new FieldContainer(22, 25, Field.MONTH));
+ v.add(new FieldContainer(26, 35, Field.MONTH));
+ v.add(new FieldContainer(36, 38, Field.DAY_OF_MONTH));
+ v.add(new FieldContainer(39, 41, Field.DAY_OF_MONTH));
+ v.add(new FieldContainer(42, 45, Field.DAY_OF_MONTH));
+ v.add(new FieldContainer(46, 48, Field.HOUR_OF_DAY1));
+ v.add(new FieldContainer(49, 51, Field.HOUR_OF_DAY1));
+ v.add(new FieldContainer(52, 55, Field.HOUR_OF_DAY1));
+ v.add(new FieldContainer(56, 58, Field.HOUR_OF_DAY0));
+ v.add(new FieldContainer(59, 61, Field.HOUR_OF_DAY0));
+ v.add(new FieldContainer(62, 65, Field.HOUR_OF_DAY0));
+ v.add(new FieldContainer(66, 67, Field.HOUR1));
+ v.add(new FieldContainer(68, 70, Field.HOUR1));
+ v.add(new FieldContainer(71, 74, Field.HOUR1));
+ v.add(new FieldContainer(75, 77, Field.MINUTE));
+ v.add(new FieldContainer(78, 81, Field.MINUTE));
+ v.add(new FieldContainer(82, 83, Field.SECOND));
+ v.add(new FieldContainer(84, 86, Field.SECOND));
+ v.add(new FieldContainer(87, 90, Field.SECOND));
+ v.add(new FieldContainer(91, 92, Field.MILLISECOND));
+ v.add(new FieldContainer(93, 95, Field.MILLISECOND));
+ v.add(new FieldContainer(96, 99, Field.MILLISECOND));
+ v.add(new FieldContainer(100, 103, Field.DAY_OF_WEEK));
+ v.add(new FieldContainer(104, 110, Field.DAY_OF_WEEK));
+ v.add(new FieldContainer(111, 114, Field.DAY_OF_YEAR));
+ v.add(new FieldContainer(115, 118, Field.DAY_OF_YEAR));
+ v.add(new FieldContainer(119, 122, Field.DAY_OF_YEAR));
+ v.add(new FieldContainer(123, 124, Field.DAY_OF_WEEK_IN_MONTH));
+ v.add(new FieldContainer(125, 127, Field.DAY_OF_WEEK_IN_MONTH));
+ v.add(new FieldContainer(128, 130, Field.WEEK_OF_YEAR));
+ v.add(new FieldContainer(131, 134, Field.WEEK_OF_YEAR));
+ v.add(new FieldContainer(135, 136, Field.WEEK_OF_MONTH));
+ v.add(new FieldContainer(137, 140, Field.WEEK_OF_MONTH));
+ v.add(new FieldContainer(141, 143, Field.AM_PM));
+ v.add(new FieldContainer(145, 147, Field.AM_PM));
+ v.add(new FieldContainer(149, 150, Field.HOUR0));
+ v.add(new FieldContainer(151, 154, Field.HOUR0));
+ v.add(new FieldContainer(155, 164, Field.TIME_ZONE));
+ v.add(new FieldContainer(165, 174, Field.TIME_ZONE));
+ v.add(new FieldContainer(175, 180, Field.TIME_ZONE));
+ v.add(new FieldContainer(181, 186, Field.TIME_ZONE));
+ return v;
+ }
+
+}
--
cgit v1.1