harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r462605 [4/8] - in /incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java: java/text/ org/apache/harmony/text/ org/apache/harmony/text/internal/nls/
Date Tue, 10 Oct 2006 22:18:37 GMT
Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/DecimalFormatSymbols.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/DecimalFormatSymbols.java?view=diff&rev=462605&r1=462604&r2=462605
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/DecimalFormatSymbols.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/DecimalFormatSymbols.java Tue Oct 10 15:18:35 2006
@@ -17,7 +17,6 @@
 
 package java.text;
 
-
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
@@ -34,503 +33,511 @@
  */
 public final class DecimalFormatSymbols implements Cloneable, Serializable {
 
-	private static final long serialVersionUID = 5772796243397350300L;
+    private static final long serialVersionUID = 5772796243397350300L;
 
-	private final int ZeroDigit = 0, Digit = 1, DecimalSeparator = 2,
-			GroupingSeparator = 3, PatternSeparator = 4, Percent = 5,
-			PerMill = 6, Exponent = 7, MonetaryDecimalSeparator = 8,
-			MinusSign = 9;
-
-	transient char[] patternChars;
-
-	private transient Currency currency;
-
-	private transient Locale locale;
-
-	private String infinity, NaN, currencySymbol, intlCurrencySymbol;
-
-	/**
-	 * Constructs a new DecimalFormatSymbols containing the symbols for the
-	 * default Locale.
-	 */
-	public DecimalFormatSymbols() {
-		this(Locale.getDefault());
-	}
-
-	/**
-	 * Constructs a new DecimalFormatSymbols containing the symbols for the
-	 * specified Locale.
-	 * 
-	 * @param locale
-	 *            the Locale
-	 */
-	public DecimalFormatSymbols(Locale locale) {
-		ResourceBundle bundle = Format.getBundle(locale);
-		patternChars = bundle.getString("DecimalPatternChars").toCharArray(); //$NON-NLS-1$
-		infinity = bundle.getString("Infinity"); //$NON-NLS-1$
-		NaN = bundle.getString("NaN"); //$NON-NLS-1$
-		this.locale = locale;
-		try {
-			currency = Currency.getInstance(locale);
-			currencySymbol = currency.getSymbol(locale);
-			intlCurrencySymbol = currency.getCurrencyCode();
-		} catch (IllegalArgumentException e) {
-			currency = Currency.getInstance("XXX"); //$NON-NLS-1$
-			currencySymbol = bundle.getString("CurrencySymbol"); //$NON-NLS-1$
-			intlCurrencySymbol = bundle.getString("IntCurrencySymbol"); //$NON-NLS-1$
-		}
-	}
-
-	/**
-	 * Answers a new DecimalFormatSymbols with the same symbols as this
-	 * DecimalFormatSymbols.
-	 * 
-	 * @return a shallow copy of this DecimalFormatSymbols
-	 * 
-	 * @see java.lang.Cloneable
-	 */
-	public Object clone() {
-		try {
-			DecimalFormatSymbols symbols = (DecimalFormatSymbols) super.clone();
-			symbols.patternChars = (char[]) patternChars.clone();
-			return symbols;
-		} catch (CloneNotSupportedException e) {
-			return null;
-		}
-	}
-
-	/**
-	 * Compares the specified object to this DecimalFormatSymbols and answer if
-	 * they are equal. The object must be an instance of DecimalFormatSymbols
-	 * with the same symbols.
-	 * 
-	 * @param object
-	 *            the object to compare with this object
-	 * @return true if the specified object is equal to this
-	 *         DecimalFormatSymbols, false otherwise
-	 * 
-	 * @see #hashCode
-	 */
-	public boolean equals(Object object) {
-		if (this == object)
-			return true;
-		if (!(object instanceof DecimalFormatSymbols))
-			return false;
-		DecimalFormatSymbols obj = (DecimalFormatSymbols) object;
-		return Arrays.equals(patternChars, obj.patternChars)
-				&& infinity.equals(obj.infinity) && NaN.equals(obj.NaN)
-				&& currencySymbol.equals(obj.currencySymbol)
-				&& intlCurrencySymbol.equals(obj.intlCurrencySymbol);
-	}
-
-	/**
-	 * Answers the currency.
-	 * <p>
-	 * <code>null<code> is returned
-	 * if <code>setInternationalCurrencySymbol()</code> has been previously called
-	 * with a value that is not a valid ISO 4217 currency code.
-	 * <p>
-	 *
-	 * @return		the currency that was set in the constructor, <code>setCurrency()</code>,
-	 * 				or <code>setInternationalCurrencySymbol()</code>, or </code>null</code>
-	 * 
-	 * @see #setCurrency(Currency)
-	 * @see #setInternationalCurrencySymbol(String)
-	 */
-	public Currency getCurrency() {
-		return currency;
-	}
-
-	/**
-	 * Answers the international currency symbol.
-	 * 
-	 * @return a String
-	 */
-	public String getInternationalCurrencySymbol() {
-		return intlCurrencySymbol;
-	}
-
-	/**
-	 * Answers the currency symbol.
-	 * 
-	 * @return a String
-	 */
-	public String getCurrencySymbol() {
-		return currencySymbol;
-	}
-
-	/**
-	 * Answers the character which represents the decimal point in a number.
-	 * 
-	 * @return a char
-	 */
-	public char getDecimalSeparator() {
-		return patternChars[DecimalSeparator];
-	}
-
-	/**
-	 * Answers the character which represents a single digit in a format
-	 * pattern.
-	 * 
-	 * @return a char
-	 */
-	public char getDigit() {
-		return patternChars[Digit];
-	}
-
-	/**
-	 * Answers the character used as the thousands separator in a number.
-	 * 
-	 * @return a char
-	 */
-	public char getGroupingSeparator() {
-		return patternChars[GroupingSeparator];
-	}
-
-	/**
-	 * Answers the String which represents infinity.
-	 * 
-	 * @return a String
-	 */
-	public String getInfinity() {
-		return infinity;
-	}
-
-	String getLocalPatternChars() {
-		// Don't include the MonetaryDecimalSeparator or the MinusSign
-		return new String(patternChars, 0, patternChars.length - 2);
-	}
-
-	/**
-	 * Answers the minus sign character.
-	 * 
-	 * @return a char
-	 */
-	public char getMinusSign() {
-		return patternChars[MinusSign];
-	}
-
-	/**
-	 * Answers the character which represents the decimal point in a monetary
-	 * value.
-	 * 
-	 * @return a char
-	 */
-	public char getMonetaryDecimalSeparator() {
-		return patternChars[MonetaryDecimalSeparator];
-	}
-
-	/**
-	 * Answers the String which represents NaN.
-	 * 
-	 * @return a String
-	 */
-	public String getNaN() {
-		return NaN;
-	}
-
-	/**
-	 * Answers the character which separates the positive and negative patterns
-	 * in a format pattern.
-	 * 
-	 * @return a char
-	 */
-	public char getPatternSeparator() {
-		return patternChars[PatternSeparator];
-	}
-
-	/**
-	 * Answers the percent character.
-	 * 
-	 * @return a char
-	 */
-	public char getPercent() {
-		return patternChars[Percent];
-	}
-
-	/**
-	 * Answers the mille percent sign character.
-	 * 
-	 * @return a char
-	 */
-	public char getPerMill() {
-		return patternChars[PerMill];
-	}
-
-	/**
-	 * Answers the character which represents zero.
-	 * 
-	 * @return a char
-	 */
-	public char getZeroDigit() {
-		return patternChars[ZeroDigit];
-	}
-
-	char getExponential() {
-		return patternChars[Exponent];
-	}
-
-	/**
-	 * Answers an integer hash code for the receiver. Objects which are equal
-	 * answer the same value for this method.
-	 * 
-	 * @return the receiver's hash
-	 * 
-	 * @see #equals
-	 */
-	public int hashCode() {
-		return new String(patternChars).hashCode() + infinity.hashCode()
-				+ NaN.hashCode() + currencySymbol.hashCode()
-				+ intlCurrencySymbol.hashCode();
-	}
-
-	/**
-	 * Sets the currency.
-	 * <p>
-	 * The international currency symbol and currency symbol are updated, but
-	 * the min and max number of fraction digits stay the same.
-	 * <p>
-	 * 
-	 * @param currency
-	 *            the new currency
-	 * 
-	 * @throws java.lang.NullPointerException
-	 *             if currency is null
-	 */
-	public void setCurrency(Currency currency) {
-		if (currency == null)
-			throw new NullPointerException();
-		if (currency == this.currency)
-			return;
-		this.currency = currency;
-		intlCurrencySymbol = currency.getCurrencyCode();
-		currencySymbol = currency.getSymbol(locale);
-	}
-
-	/**
-	 * Sets the international currency symbol.
-	 * <p>
-	 * currency and currency symbol also are updated, if <code>value</code> is
-	 * a valid ISO4217 currency code.
-	 * <p>
-	 * The min and max number of fraction digits stay the same.
-	 * 
-	 * @param value
-	 *            currency code
-	 */
-	public void setInternationalCurrencySymbol(String value) {
-		if (value == null) {
-			currency = null;
-			intlCurrencySymbol = null;
-			return;
-		}
-
-		if (value.equals(intlCurrencySymbol))
-			return;
-
-		try {
-			currency = Currency.getInstance(value);
-			currencySymbol = currency.getSymbol(locale);
-		} catch (IllegalArgumentException e) {
-			currency = null;
-		}
-		intlCurrencySymbol = value;
-	}
-
-	/**
-	 * Sets the currency symbol.
-	 * 
-	 * @param value
-	 *            a String
-	 */
-	public void setCurrencySymbol(String value) {
-		currencySymbol = value;
-	}
-
-	/**
-	 * Sets the character which represents the decimal point in a number.
-	 * 
-	 * @param value
-	 *            the decimal separator character
-	 */
-	public void setDecimalSeparator(char value) {
-		patternChars[DecimalSeparator] = value;
-	}
-
-	/**
-	 * Sets the character which represents a single digit in a format pattern.
-	 * 
-	 * @param value
-	 *            the digit character
-	 */
-	public void setDigit(char value) {
-		patternChars[Digit] = value;
-	}
-
-	/**
-	 * Sets the character used as the thousands separator in a number.
-	 * 
-	 * @param value
-	 *            the grouping separator character
-	 */
-	public void setGroupingSeparator(char value) {
-		patternChars[GroupingSeparator] = value;
-	}
-
-	/**
-	 * Sets the String which represents infinity.
-	 * 
-	 * @param value
-	 *            the String
-	 */
-	public void setInfinity(String value) {
-		infinity = value;
-	}
-
-	/**
-	 * Sets the minus sign character.
-	 * 
-	 * @param value
-	 *            the minus sign character
-	 */
-	public void setMinusSign(char value) {
-		patternChars[MinusSign] = value;
-	}
-
-	/**
-	 * Sets the character which represents the decimal point in a monetary
-	 * value.
-	 * 
-	 * @param value
-	 *            the monetary decimal separator character
-	 */
-	public void setMonetaryDecimalSeparator(char value) {
-		patternChars[MonetaryDecimalSeparator] = value;
-	}
-
-	/**
-	 * Sets the String which represents NaN.
-	 * 
-	 * @param value
-	 *            the String
-	 */
-	public void setNaN(String value) {
-		NaN = value;
-	}
-
-	/**
-	 * Sets the character which separates the positive and negative patterns in
-	 * a format pattern.
-	 * 
-	 * @param value
-	 *            the pattern separator character
-	 */
-	public void setPatternSeparator(char value) {
-		patternChars[PatternSeparator] = value;
-	}
-
-	/**
-	 * Sets the percent character.
-	 * 
-	 * @param value
-	 *            the percent character
-	 */
-	public void setPercent(char value) {
-		patternChars[Percent] = value;
-	}
-
-	/**
-	 * Sets the mille percent sign character.
-	 * 
-	 * @param value
-	 *            the mille percent character
-	 */
-	public void setPerMill(char value) {
-		patternChars[PerMill] = value;
-	}
-
-	/**
-	 * Sets the character which represents zero.
-	 * 
-	 * @param value
-	 *            the zero digit character
-	 */
-	public void setZeroDigit(char value) {
-		patternChars[ZeroDigit] = value;
-	}
-
-	void setExponential(char value) {
-		patternChars[Exponent] = value;
-	}
-
-	private static final ObjectStreamField[] serialPersistentFields = {
-			new ObjectStreamField("currencySymbol", String.class), //$NON-NLS-1$
-			new ObjectStreamField("decimalSeparator", Character.TYPE), //$NON-NLS-1$
-			new ObjectStreamField("digit", Character.TYPE), //$NON-NLS-1$
-			new ObjectStreamField("exponential", Character.TYPE), //$NON-NLS-1$
-			new ObjectStreamField("groupingSeparator", Character.TYPE), //$NON-NLS-1$
-			new ObjectStreamField("infinity", String.class), //$NON-NLS-1$
-			new ObjectStreamField("intlCurrencySymbol", String.class), //$NON-NLS-1$
-			new ObjectStreamField("minusSign", Character.TYPE), //$NON-NLS-1$
-			new ObjectStreamField("monetarySeparator", Character.TYPE), //$NON-NLS-1$
-			new ObjectStreamField("NaN", String.class), //$NON-NLS-1$
-			new ObjectStreamField("patternSeparator", Character.TYPE), //$NON-NLS-1$
-			new ObjectStreamField("percent", Character.TYPE), //$NON-NLS-1$
-			new ObjectStreamField("perMill", Character.TYPE), //$NON-NLS-1$
-			new ObjectStreamField("serialVersionOnStream", Integer.TYPE), //$NON-NLS-1$
-			new ObjectStreamField("zeroDigit", Character.TYPE), //$NON-NLS-1$
-			new ObjectStreamField("locale", Locale.class),}; //$NON-NLS-1$
-
-	private void writeObject(ObjectOutputStream stream) throws IOException {
-		ObjectOutputStream.PutField fields = stream.putFields();
-		fields.put("currencySymbol", currencySymbol); //$NON-NLS-1$
-		fields.put("decimalSeparator", getDecimalSeparator()); //$NON-NLS-1$
-		fields.put("digit", getDigit()); //$NON-NLS-1$
-		fields.put("exponential", getExponential()); //$NON-NLS-1$
-		fields.put("groupingSeparator", getGroupingSeparator()); //$NON-NLS-1$
-		fields.put("infinity", infinity); //$NON-NLS-1$
-		fields.put("intlCurrencySymbol", intlCurrencySymbol); //$NON-NLS-1$
-		fields.put("minusSign", getMinusSign()); //$NON-NLS-1$
-		fields.put("monetarySeparator", getMonetaryDecimalSeparator()); //$NON-NLS-1$
-		fields.put("NaN", NaN); //$NON-NLS-1$
-		fields.put("patternSeparator", getPatternSeparator()); //$NON-NLS-1$
-		fields.put("percent", getPercent()); //$NON-NLS-1$
-		fields.put("perMill", getPerMill()); //$NON-NLS-1$
-		fields.put("serialVersionOnStream", 1); //$NON-NLS-1$
-		fields.put("zeroDigit", getZeroDigit()); //$NON-NLS-1$
-		fields.put("locale", locale); //$NON-NLS-1$
-		stream.writeFields();
-	}
-
-	private void readObject(ObjectInputStream stream) throws IOException,
-			ClassNotFoundException {
-		ObjectInputStream.GetField fields = stream.readFields();
-		patternChars = new char[10];
-		currencySymbol = (String) fields.get("currencySymbol", ""); //$NON-NLS-1$ //$NON-NLS-2$
-		setDecimalSeparator(fields.get("decimalSeparator", '.')); //$NON-NLS-1$
-		setDigit(fields.get("digit", '#')); //$NON-NLS-1$
-		setGroupingSeparator(fields.get("groupingSeparator", ',')); //$NON-NLS-1$
-		infinity = (String) fields.get("infinity", ""); //$NON-NLS-1$ //$NON-NLS-2$
-		intlCurrencySymbol = (String) fields.get("intlCurrencySymbol", ""); //$NON-NLS-1$ //$NON-NLS-2$
-		setMinusSign(fields.get("minusSign", '-')); //$NON-NLS-1$
-		NaN = (String) fields.get("NaN", ""); //$NON-NLS-1$ //$NON-NLS-2$
-		setPatternSeparator(fields.get("patternSeparator", ';')); //$NON-NLS-1$
-		setPercent(fields.get("percent", '%')); //$NON-NLS-1$
-		setPerMill(fields.get("perMill", '\u2030')); //$NON-NLS-1$
-		setZeroDigit(fields.get("zeroDigit", '0')); //$NON-NLS-1$
-		locale = (Locale)fields.get("locale", null); //$NON-NLS-1$
-		if (fields.get("serialVersionOnStream", 0) == 0) { //$NON-NLS-1$
-			setMonetaryDecimalSeparator(getDecimalSeparator());
-			setExponential('E');
-		} else {
-			setMonetaryDecimalSeparator(fields.get("monetarySeparator", '.')); //$NON-NLS-1$
-			setExponential(fields.get("exponential", 'E')); //$NON-NLS-1$
-			
-		}
-		try {
-			currency = Currency.getInstance(intlCurrencySymbol);
-		} catch (IllegalArgumentException e) {
-			currency = null;
-		}
-	}
+    private final int ZeroDigit = 0, Digit = 1, DecimalSeparator = 2,
+            GroupingSeparator = 3, PatternSeparator = 4, Percent = 5,
+            PerMill = 6, Exponent = 7, MonetaryDecimalSeparator = 8,
+            MinusSign = 9;
+
+    transient char[] patternChars;
+
+    private transient Currency currency;
+
+    private transient Locale locale;
+
+    private String infinity, NaN, currencySymbol, intlCurrencySymbol;
+
+    /**
+     * Constructs a new DecimalFormatSymbols containing the symbols for the
+     * default Locale.
+     */
+    public DecimalFormatSymbols() {
+        this(Locale.getDefault());
+    }
+
+    /**
+     * Constructs a new DecimalFormatSymbols containing the symbols for the
+     * specified Locale.
+     * 
+     * @param locale
+     *            the Locale
+     */
+    public DecimalFormatSymbols(Locale locale) {
+        ResourceBundle bundle = Format.getBundle(locale);
+        patternChars = bundle.getString("DecimalPatternChars").toCharArray(); //$NON-NLS-1$
+        infinity = bundle.getString("Infinity"); //$NON-NLS-1$
+        NaN = bundle.getString("NaN"); //$NON-NLS-1$
+        this.locale = locale;
+        try {
+            currency = Currency.getInstance(locale);
+            currencySymbol = currency.getSymbol(locale);
+            intlCurrencySymbol = currency.getCurrencyCode();
+        } catch (IllegalArgumentException e) {
+            currency = Currency.getInstance("XXX"); //$NON-NLS-1$
+            currencySymbol = bundle.getString("CurrencySymbol"); //$NON-NLS-1$
+            intlCurrencySymbol = bundle.getString("IntCurrencySymbol"); //$NON-NLS-1$
+        }
+    }
+
+    /**
+     * Answers a new DecimalFormatSymbols with the same symbols as this
+     * DecimalFormatSymbols.
+     * 
+     * @return a shallow copy of this DecimalFormatSymbols
+     * 
+     * @see java.lang.Cloneable
+     */
+    @Override
+    public Object clone() {
+        try {
+            DecimalFormatSymbols symbols = (DecimalFormatSymbols) super.clone();
+            symbols.patternChars = patternChars.clone();
+            return symbols;
+        } catch (CloneNotSupportedException e) {
+            return null;
+        }
+    }
+
+    /**
+     * Compares the specified object to this DecimalFormatSymbols and answer if
+     * they are equal. The object must be an instance of DecimalFormatSymbols
+     * with the same symbols.
+     * 
+     * @param object
+     *            the object to compare with this object
+     * @return true if the specified object is equal to this
+     *         DecimalFormatSymbols, false otherwise
+     * 
+     * @see #hashCode
+     */
+    @Override
+    public boolean equals(Object object) {
+        if (this == object) {
+            return true;
+        }
+        if (!(object instanceof DecimalFormatSymbols)) {
+            return false;
+        }
+        DecimalFormatSymbols obj = (DecimalFormatSymbols) object;
+        return Arrays.equals(patternChars, obj.patternChars)
+                && infinity.equals(obj.infinity) && NaN.equals(obj.NaN)
+                && currencySymbol.equals(obj.currencySymbol)
+                && intlCurrencySymbol.equals(obj.intlCurrencySymbol);
+    }
+
+    /**
+     * Answers the currency.
+     * <p>
+     * <code>null<code> is returned
+     * if <code>setInternationalCurrencySymbol()</code> has been previously called
+     * with a value that is not a valid ISO 4217 currency code.
+     * <p>
+     *
+     * @return		the currency that was set in the constructor, <code>setCurrency()</code>,
+     * 				or <code>setInternationalCurrencySymbol()</code>, or </code>null</code>
+     * 
+     * @see #setCurrency(Currency)
+     * @see #setInternationalCurrencySymbol(String)
+     */
+    public Currency getCurrency() {
+        return currency;
+    }
+
+    /**
+     * Answers the international currency symbol.
+     * 
+     * @return a String
+     */
+    public String getInternationalCurrencySymbol() {
+        return intlCurrencySymbol;
+    }
+
+    /**
+     * Answers the currency symbol.
+     * 
+     * @return a String
+     */
+    public String getCurrencySymbol() {
+        return currencySymbol;
+    }
+
+    /**
+     * Answers the character which represents the decimal point in a number.
+     * 
+     * @return a char
+     */
+    public char getDecimalSeparator() {
+        return patternChars[DecimalSeparator];
+    }
+
+    /**
+     * Answers the character which represents a single digit in a format
+     * pattern.
+     * 
+     * @return a char
+     */
+    public char getDigit() {
+        return patternChars[Digit];
+    }
+
+    /**
+     * Answers the character used as the thousands separator in a number.
+     * 
+     * @return a char
+     */
+    public char getGroupingSeparator() {
+        return patternChars[GroupingSeparator];
+    }
+
+    /**
+     * Answers the String which represents infinity.
+     * 
+     * @return a String
+     */
+    public String getInfinity() {
+        return infinity;
+    }
+
+    String getLocalPatternChars() {
+        // Don't include the MonetaryDecimalSeparator or the MinusSign
+        return new String(patternChars, 0, patternChars.length - 2);
+    }
+
+    /**
+     * Answers the minus sign character.
+     * 
+     * @return a char
+     */
+    public char getMinusSign() {
+        return patternChars[MinusSign];
+    }
+
+    /**
+     * Answers the character which represents the decimal point in a monetary
+     * value.
+     * 
+     * @return a char
+     */
+    public char getMonetaryDecimalSeparator() {
+        return patternChars[MonetaryDecimalSeparator];
+    }
+
+    /**
+     * Answers the String which represents NaN.
+     * 
+     * @return a String
+     */
+    public String getNaN() {
+        return NaN;
+    }
+
+    /**
+     * Answers the character which separates the positive and negative patterns
+     * in a format pattern.
+     * 
+     * @return a char
+     */
+    public char getPatternSeparator() {
+        return patternChars[PatternSeparator];
+    }
+
+    /**
+     * Answers the percent character.
+     * 
+     * @return a char
+     */
+    public char getPercent() {
+        return patternChars[Percent];
+    }
+
+    /**
+     * Answers the mille percent sign character.
+     * 
+     * @return a char
+     */
+    public char getPerMill() {
+        return patternChars[PerMill];
+    }
+
+    /**
+     * Answers the character which represents zero.
+     * 
+     * @return a char
+     */
+    public char getZeroDigit() {
+        return patternChars[ZeroDigit];
+    }
+
+    char getExponential() {
+        return patternChars[Exponent];
+    }
+
+    /**
+     * Answers an integer hash code for the receiver. Objects which are equal
+     * answer the same value for this method.
+     * 
+     * @return the receiver's hash
+     * 
+     * @see #equals
+     */
+    @Override
+    public int hashCode() {
+        return new String(patternChars).hashCode() + infinity.hashCode()
+                + NaN.hashCode() + currencySymbol.hashCode()
+                + intlCurrencySymbol.hashCode();
+    }
+
+    /**
+     * Sets the currency.
+     * <p>
+     * The international currency symbol and currency symbol are updated, but
+     * the min and max number of fraction digits stay the same.
+     * <p>
+     * 
+     * @param currency
+     *            the new currency
+     * 
+     * @throws java.lang.NullPointerException
+     *             if currency is null
+     */
+    public void setCurrency(Currency currency) {
+        if (currency == null) {
+            throw new NullPointerException();
+        }
+        if (currency == this.currency) {
+            return;
+        }
+        this.currency = currency;
+        intlCurrencySymbol = currency.getCurrencyCode();
+        currencySymbol = currency.getSymbol(locale);
+    }
+
+    /**
+     * Sets the international currency symbol.
+     * <p>
+     * currency and currency symbol also are updated, if <code>value</code> is
+     * a valid ISO4217 currency code.
+     * <p>
+     * The min and max number of fraction digits stay the same.
+     * 
+     * @param value
+     *            currency code
+     */
+    public void setInternationalCurrencySymbol(String value) {
+        if (value == null) {
+            currency = null;
+            intlCurrencySymbol = null;
+            return;
+        }
+
+        if (value.equals(intlCurrencySymbol)) {
+            return;
+        }
+
+        try {
+            currency = Currency.getInstance(value);
+            currencySymbol = currency.getSymbol(locale);
+        } catch (IllegalArgumentException e) {
+            currency = null;
+        }
+        intlCurrencySymbol = value;
+    }
+
+    /**
+     * Sets the currency symbol.
+     * 
+     * @param value
+     *            a String
+     */
+    public void setCurrencySymbol(String value) {
+        currencySymbol = value;
+    }
+
+    /**
+     * Sets the character which represents the decimal point in a number.
+     * 
+     * @param value
+     *            the decimal separator character
+     */
+    public void setDecimalSeparator(char value) {
+        patternChars[DecimalSeparator] = value;
+    }
+
+    /**
+     * Sets the character which represents a single digit in a format pattern.
+     * 
+     * @param value
+     *            the digit character
+     */
+    public void setDigit(char value) {
+        patternChars[Digit] = value;
+    }
+
+    /**
+     * Sets the character used as the thousands separator in a number.
+     * 
+     * @param value
+     *            the grouping separator character
+     */
+    public void setGroupingSeparator(char value) {
+        patternChars[GroupingSeparator] = value;
+    }
+
+    /**
+     * Sets the String which represents infinity.
+     * 
+     * @param value
+     *            the String
+     */
+    public void setInfinity(String value) {
+        infinity = value;
+    }
+
+    /**
+     * Sets the minus sign character.
+     * 
+     * @param value
+     *            the minus sign character
+     */
+    public void setMinusSign(char value) {
+        patternChars[MinusSign] = value;
+    }
+
+    /**
+     * Sets the character which represents the decimal point in a monetary
+     * value.
+     * 
+     * @param value
+     *            the monetary decimal separator character
+     */
+    public void setMonetaryDecimalSeparator(char value) {
+        patternChars[MonetaryDecimalSeparator] = value;
+    }
+
+    /**
+     * Sets the String which represents NaN.
+     * 
+     * @param value
+     *            the String
+     */
+    public void setNaN(String value) {
+        NaN = value;
+    }
+
+    /**
+     * Sets the character which separates the positive and negative patterns in
+     * a format pattern.
+     * 
+     * @param value
+     *            the pattern separator character
+     */
+    public void setPatternSeparator(char value) {
+        patternChars[PatternSeparator] = value;
+    }
+
+    /**
+     * Sets the percent character.
+     * 
+     * @param value
+     *            the percent character
+     */
+    public void setPercent(char value) {
+        patternChars[Percent] = value;
+    }
+
+    /**
+     * Sets the mille percent sign character.
+     * 
+     * @param value
+     *            the mille percent character
+     */
+    public void setPerMill(char value) {
+        patternChars[PerMill] = value;
+    }
+
+    /**
+     * Sets the character which represents zero.
+     * 
+     * @param value
+     *            the zero digit character
+     */
+    public void setZeroDigit(char value) {
+        patternChars[ZeroDigit] = value;
+    }
+
+    void setExponential(char value) {
+        patternChars[Exponent] = value;
+    }
+
+    private static final ObjectStreamField[] serialPersistentFields = {
+            new ObjectStreamField("currencySymbol", String.class), //$NON-NLS-1$
+            new ObjectStreamField("decimalSeparator", Character.TYPE), //$NON-NLS-1$
+            new ObjectStreamField("digit", Character.TYPE), //$NON-NLS-1$
+            new ObjectStreamField("exponential", Character.TYPE), //$NON-NLS-1$
+            new ObjectStreamField("groupingSeparator", Character.TYPE), //$NON-NLS-1$
+            new ObjectStreamField("infinity", String.class), //$NON-NLS-1$
+            new ObjectStreamField("intlCurrencySymbol", String.class), //$NON-NLS-1$
+            new ObjectStreamField("minusSign", Character.TYPE), //$NON-NLS-1$
+            new ObjectStreamField("monetarySeparator", Character.TYPE), //$NON-NLS-1$
+            new ObjectStreamField("NaN", String.class), //$NON-NLS-1$
+            new ObjectStreamField("patternSeparator", Character.TYPE), //$NON-NLS-1$
+            new ObjectStreamField("percent", Character.TYPE), //$NON-NLS-1$
+            new ObjectStreamField("perMill", Character.TYPE), //$NON-NLS-1$
+            new ObjectStreamField("serialVersionOnStream", Integer.TYPE), //$NON-NLS-1$
+            new ObjectStreamField("zeroDigit", Character.TYPE), //$NON-NLS-1$
+            new ObjectStreamField("locale", Locale.class), }; //$NON-NLS-1$
+
+    private void writeObject(ObjectOutputStream stream) throws IOException {
+        ObjectOutputStream.PutField fields = stream.putFields();
+        fields.put("currencySymbol", currencySymbol); //$NON-NLS-1$
+        fields.put("decimalSeparator", getDecimalSeparator()); //$NON-NLS-1$
+        fields.put("digit", getDigit()); //$NON-NLS-1$
+        fields.put("exponential", getExponential()); //$NON-NLS-1$
+        fields.put("groupingSeparator", getGroupingSeparator()); //$NON-NLS-1$
+        fields.put("infinity", infinity); //$NON-NLS-1$
+        fields.put("intlCurrencySymbol", intlCurrencySymbol); //$NON-NLS-1$
+        fields.put("minusSign", getMinusSign()); //$NON-NLS-1$
+        fields.put("monetarySeparator", getMonetaryDecimalSeparator()); //$NON-NLS-1$
+        fields.put("NaN", NaN); //$NON-NLS-1$
+        fields.put("patternSeparator", getPatternSeparator()); //$NON-NLS-1$
+        fields.put("percent", getPercent()); //$NON-NLS-1$
+        fields.put("perMill", getPerMill()); //$NON-NLS-1$
+        fields.put("serialVersionOnStream", 1); //$NON-NLS-1$
+        fields.put("zeroDigit", getZeroDigit()); //$NON-NLS-1$
+        fields.put("locale", locale); //$NON-NLS-1$
+        stream.writeFields();
+    }
+
+    private void readObject(ObjectInputStream stream) throws IOException,
+            ClassNotFoundException {
+        ObjectInputStream.GetField fields = stream.readFields();
+        patternChars = new char[10];
+        currencySymbol = (String) fields.get("currencySymbol", ""); //$NON-NLS-1$ //$NON-NLS-2$
+        setDecimalSeparator(fields.get("decimalSeparator", '.')); //$NON-NLS-1$
+        setDigit(fields.get("digit", '#')); //$NON-NLS-1$
+        setGroupingSeparator(fields.get("groupingSeparator", ',')); //$NON-NLS-1$
+        infinity = (String) fields.get("infinity", ""); //$NON-NLS-1$ //$NON-NLS-2$
+        intlCurrencySymbol = (String) fields.get("intlCurrencySymbol", ""); //$NON-NLS-1$ //$NON-NLS-2$
+        setMinusSign(fields.get("minusSign", '-')); //$NON-NLS-1$
+        NaN = (String) fields.get("NaN", ""); //$NON-NLS-1$ //$NON-NLS-2$
+        setPatternSeparator(fields.get("patternSeparator", ';')); //$NON-NLS-1$
+        setPercent(fields.get("percent", '%')); //$NON-NLS-1$
+        setPerMill(fields.get("perMill", '\u2030')); //$NON-NLS-1$
+        setZeroDigit(fields.get("zeroDigit", '0')); //$NON-NLS-1$
+        locale = (Locale) fields.get("locale", null); //$NON-NLS-1$
+        if (fields.get("serialVersionOnStream", 0) == 0) { //$NON-NLS-1$
+            setMonetaryDecimalSeparator(getDecimalSeparator());
+            setExponential('E');
+        } else {
+            setMonetaryDecimalSeparator(fields.get("monetarySeparator", '.')); //$NON-NLS-1$
+            setExponential(fields.get("exponential", 'E')); //$NON-NLS-1$
+
+        }
+        try {
+            currency = Currency.getInstance(intlCurrencySymbol);
+        } catch (IllegalArgumentException e) {
+            currency = null;
+        }
+    }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/FieldPosition.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/FieldPosition.java?view=diff&rev=462605&r1=462604&r2=462605
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/FieldPosition.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/FieldPosition.java Tue Oct 10 15:18:35 2006
@@ -17,152 +17,155 @@
 
 package java.text;
 
-
 /**
  * FieldPosition is used to identify fields in formatted Strings.
  */
 public class FieldPosition {
 
-	private int myField, beginIndex, endIndex;
+    private int myField, beginIndex, endIndex;
 
-	private Format.Field myAttribute;
+    private Format.Field myAttribute;
 
-	/**
-	 * Constructs a new FieldPosition on the specified field.
-	 * 
-	 * @param field
-	 *            the field to identify
-	 */
-	public FieldPosition(int field) {
-		myField = field;
-	}
-
-	/**
-	 * Constructs a new FieldPosition on the specified Field attribute.
-	 * 
-	 * @param attribute
-	 *            the field attribute to identify
-	 */
-	public FieldPosition(Format.Field attribute) {
-		myAttribute = attribute;
-		myField = -1;
-	}
-
-	/**
-	 * Constructs a new FieldPosition on the specified Field attribute and field
-	 * id.
-	 * 
-	 * @param attribute
-	 *            the field attribute to identify
-	 * @param field
-	 *            the field to identify
-	 */
-	public FieldPosition(Format.Field attribute, int field) {
-		myAttribute = attribute;
-		myField = field;
-	}
-
-	void clear() {
-		beginIndex = endIndex = 0;
-	}
-
-	/**
-	 * Compares the specified object to this FieldPosition and answer if they
-	 * are equal. The object must be an instance of FieldPosition with the same
-	 * field, begin index and end index.
-	 * 
-	 * @param object
-	 *            the object to compare with this object
-	 * @return true if the specified object is equal to this fieldPosition,
-	 *         false otherwise
-	 * 
-	 * @see #hashCode
-	 */
-	public boolean equals(Object object) {
-		if (!(object instanceof FieldPosition))
-			return false;
-		FieldPosition pos = (FieldPosition) object;
-		return myField == pos.myField && myAttribute == pos.myAttribute
-				&& beginIndex == pos.beginIndex && endIndex == pos.endIndex;
-	}
-
-	/**
-	 * Answers the index of the beginning of the field.
-	 * 
-	 * @return the first index of the field
-	 */
-	public int getBeginIndex() {
-		return beginIndex;
-	}
-
-	/**
-	 * Answers the index one past the end of the field.
-	 * 
-	 * @return one past the index of the last character in the field
-	 */
-	public int getEndIndex() {
-		return endIndex;
-	}
-
-	/**
-	 * Answers the field which is being identified.
-	 * 
-	 * @return the field
-	 */
-	public int getField() {
-		return myField;
-	}
-
-	/**
-	 * Answers the attribute which is being identified.
-	 * 
-	 * @return the field
-	 */
-	public Format.Field getFieldAttribute() {
-		return myAttribute;
-	}
-
-	/**
-	 * Answers an integer hash code for the receiver. Objects which are equal
-	 * answer the same value for this method.
-	 * 
-	 * @return the receiver's hash
-	 * 
-	 * @see #equals
-	 */
-	public int hashCode() {
-		int attributeHash = (myAttribute == null) ? 0 : myAttribute.hashCode();
-		return attributeHash + myField * 10 + beginIndex * 100 + endIndex;
-	}
-
-	/**
-	 * Sets the index of the beginning of the field.
-	 * 
-	 * @param index
-	 *            the index of the first character in the field
-	 */
-	public void setBeginIndex(int index) {
-		beginIndex = index;
-	}
-
-	/**
-	 * Sets the index of the end of the field.
-	 * 
-	 * @param index
-	 *            one past the index of the last character in the field
-	 */
-	public void setEndIndex(int index) {
-		endIndex = index;
-	}
-
-	/**
-	 * Answers the string representation of this FieldPosition.
-	 * 
-	 * @return the string representation of this FieldPosition
-	 */
-	public String toString() {
-		return getClass().getName() + "[attribute=" + myAttribute + ", field=" //$NON-NLS-1$ //$NON-NLS-2$
-				+ myField + ", beginIndex=" + beginIndex + ", endIndex=" //$NON-NLS-1$ //$NON-NLS-2$
-				+ endIndex + "]"; //$NON-NLS-1$
-	}
+    /**
+     * Constructs a new FieldPosition on the specified field.
+     * 
+     * @param field
+     *            the field to identify
+     */
+    public FieldPosition(int field) {
+        myField = field;
+    }
+
+    /**
+     * Constructs a new FieldPosition on the specified Field attribute.
+     * 
+     * @param attribute
+     *            the field attribute to identify
+     */
+    public FieldPosition(Format.Field attribute) {
+        myAttribute = attribute;
+        myField = -1;
+    }
+
+    /**
+     * Constructs a new FieldPosition on the specified Field attribute and field
+     * id.
+     * 
+     * @param attribute
+     *            the field attribute to identify
+     * @param field
+     *            the field to identify
+     */
+    public FieldPosition(Format.Field attribute, int field) {
+        myAttribute = attribute;
+        myField = field;
+    }
+
+    void clear() {
+        beginIndex = endIndex = 0;
+    }
+
+    /**
+     * Compares the specified object to this FieldPosition and answer if they
+     * are equal. The object must be an instance of FieldPosition with the same
+     * field, begin index and end index.
+     * 
+     * @param object
+     *            the object to compare with this object
+     * @return true if the specified object is equal to this fieldPosition,
+     *         false otherwise
+     * 
+     * @see #hashCode
+     */
+    @Override
+    public boolean equals(Object object) {
+        if (!(object instanceof FieldPosition)) {
+            return false;
+        }
+        FieldPosition pos = (FieldPosition) object;
+        return myField == pos.myField && myAttribute == pos.myAttribute
+                && beginIndex == pos.beginIndex && endIndex == pos.endIndex;
+    }
+
+    /**
+     * Answers the index of the beginning of the field.
+     * 
+     * @return the first index of the field
+     */
+    public int getBeginIndex() {
+        return beginIndex;
+    }
+
+    /**
+     * Answers the index one past the end of the field.
+     * 
+     * @return one past the index of the last character in the field
+     */
+    public int getEndIndex() {
+        return endIndex;
+    }
+
+    /**
+     * Answers the field which is being identified.
+     * 
+     * @return the field
+     */
+    public int getField() {
+        return myField;
+    }
+
+    /**
+     * Answers the attribute which is being identified.
+     * 
+     * @return the field
+     */
+    public Format.Field getFieldAttribute() {
+        return myAttribute;
+    }
+
+    /**
+     * Answers an integer hash code for the receiver. Objects which are equal
+     * answer the same value for this method.
+     * 
+     * @return the receiver's hash
+     * 
+     * @see #equals
+     */
+    @Override
+    public int hashCode() {
+        int attributeHash = (myAttribute == null) ? 0 : myAttribute.hashCode();
+        return attributeHash + myField * 10 + beginIndex * 100 + endIndex;
+    }
+
+    /**
+     * Sets the index of the beginning of the field.
+     * 
+     * @param index
+     *            the index of the first character in the field
+     */
+    public void setBeginIndex(int index) {
+        beginIndex = index;
+    }
+
+    /**
+     * Sets the index of the end of the field.
+     * 
+     * @param index
+     *            one past the index of the last character in the field
+     */
+    public void setEndIndex(int index) {
+        endIndex = index;
+    }
+
+    /**
+     * Answers the string representation of this FieldPosition.
+     * 
+     * @return the string representation of this FieldPosition
+     */
+    @Override
+    public String toString() {
+        return getClass().getName() + "[attribute=" + myAttribute + ", field=" //$NON-NLS-1$ //$NON-NLS-2$
+                + myField + ", beginIndex=" + beginIndex + ", endIndex=" //$NON-NLS-1$ //$NON-NLS-2$
+                + endIndex + "]"; //$NON-NLS-1$
+    }
 }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Format.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Format.java?view=diff&rev=462605&r1=462604&r2=462605
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Format.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/text/src/main/java/java/text/Format.java Tue Oct 10 15:18:35 2006
@@ -17,7 +17,6 @@
 
 package java.text;
 
-
 import java.io.Serializable;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
@@ -32,218 +31,230 @@
  */
 public abstract class Format implements Serializable, Cloneable {
 
-	private static final long serialVersionUID = -299282585814624189L;
+    private static final long serialVersionUID = -299282585814624189L;
 
-	/**
-	 * Constructs a new instance of Format.
-	 * 
-	 */
-	public Format() {
-	}
-
-	/**
-	 * Answers a copy of this Format.
-	 * 
-	 * @return a shallow copy of this Format
-	 * 
-	 * @see java.lang.Cloneable
-	 */
-	public Object clone() {
-		try {
-			return super.clone();
-		} catch (CloneNotSupportedException e) {
-			return null;
-		}
-	}
-
-	static ResourceBundle getBundle(final Locale locale) {
-        return AccessController.doPrivileged(new PrivilegedAction<ResourceBundle>() {
-            public ResourceBundle run() {
-                return ResourceBundle.getBundle(
-                        "org.apache.harmony.luni.internal.locale.Locale", locale); //$NON-NLS-1$
-            }
-        });
+    /**
+     * Constructs a new instance of Format.
+     * 
+     */
+    public Format() {
+    }
+
+    /**
+     * Answers a copy of this Format.
+     * 
+     * @return a shallow copy of this Format
+     * 
+     * @see java.lang.Cloneable
+     */
+    @Override
+    public Object clone() {
+        try {
+            return super.clone();
+        } catch (CloneNotSupportedException e) {
+            return null;
+        }
     }
 
-	String convertPattern(String template, String fromChars, String toChars,
-			boolean check) {
-		if (!check && fromChars.equals(toChars))
-			return template;
-		boolean quote = false;
-		StringBuilder output = new StringBuilder();
-		int length = template.length();
-		for (int i = 0; i < length; i++) {
-			int index;
-			char next = template.charAt(i);
-			if (next == '\'')
-				quote = !quote;
-			if (!quote && (index = fromChars.indexOf(next)) != -1)
-				output.append(toChars.charAt(index));
-			else if (check
-					&& !quote
-					&& ((next >= 'a' && next <= 'z') || (next >= 'A' && next <= 'Z')))
+    static ResourceBundle getBundle(final Locale locale) {
+        return AccessController
+                .doPrivileged(new PrivilegedAction<ResourceBundle>() {
+                    public ResourceBundle run() {
+                        return ResourceBundle
+                                .getBundle(
+                                        "org.apache.harmony.luni.internal.locale.Locale", locale); //$NON-NLS-1$
+                    }
+                });
+    }
+
+    String convertPattern(String template, String fromChars, String toChars,
+            boolean check) {
+        if (!check && fromChars.equals(toChars)) {
+            return template;
+        }
+        boolean quote = false;
+        StringBuilder output = new StringBuilder();
+        int length = template.length();
+        for (int i = 0; i < length; i++) {
+            int index;
+            char next = template.charAt(i);
+            if (next == '\'') {
+                quote = !quote;
+            }
+            if (!quote && (index = fromChars.indexOf(next)) != -1) {
+                output.append(toChars.charAt(index));
+            } else if (check
+                    && !quote
+                    && ((next >= 'a' && next <= 'z') || (next >= 'A' && next <= 'Z'))) {
                 // text.05=Invalid pattern char {0} in {1}
                 throw new IllegalArgumentException(Messages.getString(
                         "text.05", String.valueOf(next), template)); //$NON-NLS-1$
-			else
-				output.append(next);
-		}
-		if (quote)
+            } else {
+                output.append(next);
+            }
+        }
+        if (quote) {
             // text.04=Unterminated quote
-			throw new IllegalArgumentException(Messages.getString("text.04")); //$NON-NLS-1$
-		return output.toString();
-	}
-
-	/**
-	 * Formats the specified object using the rules of this Format.
-	 * 
-	 * 
-	 * @param object
-	 *            the object to format
-	 * @return the formatted String
-	 * 
-	 * @exception IllegalArgumentException
-	 *                when the object cannot be formatted by this Format
-	 */
-	public final String format(Object object) {
-		return format(object, new StringBuffer(), new FieldPosition(0))
-				.toString();
-	}
-
-	/**
-	 * Formats the specified object into the specified StringBuffer using the
-	 * rules of this Format. If the field specified by the FieldPosition is
-	 * formatted, set the begin and end index of the formatted field in the
-	 * FieldPosition.
-	 * 
-	 * @param object
-	 *            the object to format
-	 * @param buffer
-	 *            the StringBuffer
-	 * @param field
-	 *            the FieldPosition
-	 * @return the StringBuffer parameter <code>buffer</code>
-	 * 
-	 * @exception IllegalArgumentException
-	 *                when the object cannot be formatted by this Format
-	 */
-	public abstract StringBuffer format(Object object, StringBuffer buffer,
-			FieldPosition field);
-
-	/**
-	 * Formats the specified object using the rules of this format and returns
-	 * an AttributedCharacterIterator with the formatted String and no
-	 * attributes.
-	 * <p>
-	 * Subclasses should return an AttributedCharacterIterator with the
-	 * appropriate attributes.
-	 * 
-	 * @param object
-	 *            the object to format
-	 * @return an AttributedCharacterIterator with the formatted object and
-	 *         attributes
-	 * 
-	 * @exception IllegalArgumentException
-	 *                when the object cannot be formatted by this Format
-	 */
-	public AttributedCharacterIterator formatToCharacterIterator(Object object) {
-		return new AttributedString(format(object)).getIterator();
-	}
-
-	/**
-	 * Parse the specified String using the rules of this Format.
-	 * 
-	 * @param string
-	 *            the String to parse
-	 * @return the object resulting from the parse
-	 * 
-	 * @exception ParseException
-	 *                when an error occurs during parsing
-	 */
-	public Object parseObject(String string) throws ParseException {
-		ParsePosition position = new ParsePosition(0);
-		Object result = parseObject(string, position);
-		if (position.getErrorIndex() != -1 || position.getIndex() == 0)
-			throw new ParseException(null, position.getErrorIndex());
-		return result;
-	}
-
-	/**
-	 * Parse the specified String starting at the index specified by the
-	 * ParsePosition. If the string is successfully parsed, the index of the
-	 * ParsePosition is updated to the index following the parsed text.
-	 * 
-	 * @param string
-	 *            the String to parse
-	 * @param position
-	 *            the ParsePosition, updated on return with the index following
-	 *            the parsed text, or on error the index is unchanged and the
-	 *            error index is set to the index where the error occurred
-	 * @return the object resulting from the parse, or null if there is an error
-	 */
-	public abstract Object parseObject(String string, ParsePosition position);
-
-	static boolean upTo(String string, ParsePosition position,
-			StringBuffer buffer, char stop) {
-		int index = position.getIndex(), length = string.length();
-		boolean lastQuote = false, quote = false;
-		while (index < length) {
-			char ch = string.charAt(index++);
-			if (ch == '\'') {
-				if (lastQuote)
-					buffer.append('\'');
-				quote = !quote;
-				lastQuote = true;
-			} else if (ch == stop && !quote) {
-				position.setIndex(index);
-				return true;
-			} else {
-				lastQuote = false;
-				buffer.append(ch);
-			}
-		}
-		position.setIndex(index);
-		return false;
-	}
-
-	static boolean upToWithQuotes(String string, ParsePosition position,
-			StringBuffer buffer, char stop, char start) {
-		int index = position.getIndex(), length = string.length(), count = 1;
-		boolean quote = false;
-		while (index < length) {
-			char ch = string.charAt(index++);
-			if (ch == '\'')
-				quote = !quote;
-			if (!quote) {
-				if (ch == stop)
-					count--;
-				if (count == 0) {
-					position.setIndex(index);
-					return true;
-				}
-				if (ch == start)
-					count++;
-			}
-			buffer.append(ch);
-		}
-		// text.07=Unmatched braces in the pattern
-		throw new IllegalArgumentException(Messages.getString("text.07")); //$NON-NLS-1$
-	}
-
-	/**
-	 * This inner class is used to represent Format attributes in the
-	 * AttributedCharacterIterator that formatToCharacterIterator() method
-	 * returns in the Format subclasses.
-	 */
-	public static class Field extends AttributedCharacterIterator.Attribute {
+            throw new IllegalArgumentException(Messages.getString("text.04")); //$NON-NLS-1$
+        }
+        return output.toString();
+    }
+
+    /**
+     * Formats the specified object using the rules of this Format.
+     * 
+     * 
+     * @param object
+     *            the object to format
+     * @return the formatted String
+     * 
+     * @exception IllegalArgumentException
+     *                when the object cannot be formatted by this Format
+     */
+    public final String format(Object object) {
+        return format(object, new StringBuffer(), new FieldPosition(0))
+                .toString();
+    }
+
+    /**
+     * Formats the specified object into the specified StringBuffer using the
+     * rules of this Format. If the field specified by the FieldPosition is
+     * formatted, set the begin and end index of the formatted field in the
+     * FieldPosition.
+     * 
+     * @param object
+     *            the object to format
+     * @param buffer
+     *            the StringBuffer
+     * @param field
+     *            the FieldPosition
+     * @return the StringBuffer parameter <code>buffer</code>
+     * 
+     * @exception IllegalArgumentException
+     *                when the object cannot be formatted by this Format
+     */
+    public abstract StringBuffer format(Object object, StringBuffer buffer,
+            FieldPosition field);
+
+    /**
+     * Formats the specified object using the rules of this format and returns
+     * an AttributedCharacterIterator with the formatted String and no
+     * attributes.
+     * <p>
+     * Subclasses should return an AttributedCharacterIterator with the
+     * appropriate attributes.
+     * 
+     * @param object
+     *            the object to format
+     * @return an AttributedCharacterIterator with the formatted object and
+     *         attributes
+     * 
+     * @exception IllegalArgumentException
+     *                when the object cannot be formatted by this Format
+     */
+    public AttributedCharacterIterator formatToCharacterIterator(Object object) {
+        return new AttributedString(format(object)).getIterator();
+    }
+
+    /**
+     * Parse the specified String using the rules of this Format.
+     * 
+     * @param string
+     *            the String to parse
+     * @return the object resulting from the parse
+     * 
+     * @exception ParseException
+     *                when an error occurs during parsing
+     */
+    public Object parseObject(String string) throws ParseException {
+        ParsePosition position = new ParsePosition(0);
+        Object result = parseObject(string, position);
+        if (position.getErrorIndex() != -1 || position.getIndex() == 0) {
+            throw new ParseException(null, position.getErrorIndex());
+        }
+        return result;
+    }
+
+    /**
+     * Parse the specified String starting at the index specified by the
+     * ParsePosition. If the string is successfully parsed, the index of the
+     * ParsePosition is updated to the index following the parsed text.
+     * 
+     * @param string
+     *            the String to parse
+     * @param position
+     *            the ParsePosition, updated on return with the index following
+     *            the parsed text, or on error the index is unchanged and the
+     *            error index is set to the index where the error occurred
+     * @return the object resulting from the parse, or null if there is an error
+     */
+    public abstract Object parseObject(String string, ParsePosition position);
+
+    static boolean upTo(String string, ParsePosition position,
+            StringBuffer buffer, char stop) {
+        int index = position.getIndex(), length = string.length();
+        boolean lastQuote = false, quote = false;
+        while (index < length) {
+            char ch = string.charAt(index++);
+            if (ch == '\'') {
+                if (lastQuote) {
+                    buffer.append('\'');
+                }
+                quote = !quote;
+                lastQuote = true;
+            } else if (ch == stop && !quote) {
+                position.setIndex(index);
+                return true;
+            } else {
+                lastQuote = false;
+                buffer.append(ch);
+            }
+        }
+        position.setIndex(index);
+        return false;
+    }
+
+    static boolean upToWithQuotes(String string, ParsePosition position,
+            StringBuffer buffer, char stop, char start) {
+        int index = position.getIndex(), length = string.length(), count = 1;
+        boolean quote = false;
+        while (index < length) {
+            char ch = string.charAt(index++);
+            if (ch == '\'') {
+                quote = !quote;
+            }
+            if (!quote) {
+                if (ch == stop) {
+                    count--;
+                }
+                if (count == 0) {
+                    position.setIndex(index);
+                    return true;
+                }
+                if (ch == start) {
+                    count++;
+                }
+            }
+            buffer.append(ch);
+        }
+        // text.07=Unmatched braces in the pattern
+        throw new IllegalArgumentException(Messages.getString("text.07")); //$NON-NLS-1$
+    }
+
+    /**
+     * This inner class is used to represent Format attributes in the
+     * AttributedCharacterIterator that formatToCharacterIterator() method
+     * returns in the Format subclasses.
+     */
+    public static class Field extends AttributedCharacterIterator.Attribute {
 
         private static final long serialVersionUID = 276966692217360283L;
-        
-		/**
-		 * Constructs a new instance of Field with the given fieldName.
-		 */
-		protected Field(String fieldName) {
-			super(fieldName);
-		}
-	}
+
+        /**
+         * Constructs a new instance of Field with the given fieldName.
+         */
+        protected Field(String fieldName) {
+            super(fieldName);
+        }
+    }
 }



Mime
View raw message