FileDocCategorySizeDatePackage
DecimalFormatSymbols.javaAPI DocAndroid 1.5 API19502Wed May 06 22:41:06 BST 2009java.text

DecimalFormatSymbols

public final class DecimalFormatSymbols extends Object implements Serializable, Cloneable
Encapsulates the set of symbols (such as the decimal separator, the grouping separator, and so on) needed by {@code DecimalFormat} to format numbers. {@code DecimalFormat} internally creates an instance of {@code DecimalFormatSymbols} from its locale data. If you need to change any of these symbols, you can get the {@code DecimalFormatSymbols} object from your {@code DecimalFormat} and modify it.
see
java.util.Locale
see
DecimalFormat
since
Android 1.0

Fields Summary
private static final long
serialVersionUID
private final int
ZeroDigit
private final int
Digit
private final int
DecimalSeparator
private final int
GroupingSeparator
private final int
PatternSeparator
private final int
Percent
private final int
PerMill
private final int
Exponent
private final int
MonetaryDecimalSeparator
private final int
MinusSign
transient char[]
patternChars
private transient Currency
currency
private transient Locale
locale
private String
infinity
private String
NaN
private String
currencySymbol
private String
intlCurrencySymbol
private static final ObjectStreamField[]
serialPersistentFields
Constructors Summary
public DecimalFormatSymbols()
Constructs a new {@code DecimalFormatSymbols} containing the symbols for the default locale. Best practice is to create a {@code DecimalFormat} and then to get the {@code DecimalFormatSymbols} from that object by calling {@link DecimalFormat#getDecimalFormatSymbols()}.

since
Android 1.0


                                               
      
        this(Locale.getDefault());
    
public DecimalFormatSymbols(Locale locale)
Constructs a new DecimalFormatSymbols containing the symbols for the specified Locale. Best practice is to create a {@code DecimalFormat} and then to get the {@code DecimalFormatSymbols} from that object by calling {@link DecimalFormat#getDecimalFormatSymbols()}.

param
locale the locale.
since
Android 1.0

        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$
        }
    
Methods Summary
public java.lang.Objectclone()
Returns a new {@code DecimalFormatSymbols} with the same symbols as this {@code DecimalFormatSymbols}.

return
a shallow copy of this {@code DecimalFormatSymbols}.
see
java.lang.Cloneable
since
Android 1.0

        try {
            DecimalFormatSymbols symbols = (DecimalFormatSymbols) super.clone();
            symbols.patternChars = patternChars.clone();
            return symbols;
        } catch (CloneNotSupportedException e) {
            return null;
        }
    
public booleanequals(java.lang.Object object)
Compares the specified object to this {@code DecimalFormatSymbols} and indicates if they are equal. In order to be equal, {@code object} must be an instance of {@code DecimalFormatSymbols} and contain the same symbols.

param
object the object to compare with this object.
return
{@code true} if the specified object is equal to this {@code DecimalFormatSymbols}; {@code false} otherwise.
see
#hashCode
since
Android 1.0

        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);
    
public java.util.CurrencygetCurrency()
Returns the currency.

{@code null} is returned if {@code setInternationalCurrencySymbol()} has been previously called with a value that is not a valid ISO 4217 currency code.

return
the currency that was set in the constructor or by calling {@code setCurrency()} or {@code setInternationalCurrencySymbol()}, or {@code null} if an invalid currency was set.
see
#setCurrency(Currency)
see
#setInternationalCurrencySymbol(String)
since
Android 1.0

        return currency;
    
public java.lang.StringgetCurrencySymbol()
Returns the currency symbol.

return
the currency symbol as string.
since
Android 1.0

        return currencySymbol;
    
public chargetDecimalSeparator()
Returns the character which represents the decimal point in a number.

return
the decimal separator character.
since
Android 1.0

        return patternChars[DecimalSeparator];
    
public chargetDigit()
Returns the character which represents a single digit in a format pattern.

return
the digit pattern character.
since
Android 1.0

        return patternChars[Digit];
    
chargetExponential()

        return patternChars[Exponent];
    
public chargetGroupingSeparator()
Returns the character used as the thousands separator in a number.

return
the thousands separator character.
since
Android 1.0

        return patternChars[GroupingSeparator];
    
public java.lang.StringgetInfinity()
Returns the string which represents infinity.

return
the infinity symbol as a string.
since
Android 1.0

        return infinity;
    
public java.lang.StringgetInternationalCurrencySymbol()
Returns the international currency symbol.

return
the international currency symbol as string.
since
Android 1.0

        return intlCurrencySymbol;
    
public chargetMinusSign()
Returns the minus sign character.

return
the minus sign as a character.
since
Android 1.0

        return patternChars[MinusSign];
    
public chargetMonetaryDecimalSeparator()
Returns the character which represents the decimal point in a monetary value.

return
the monetary decimal point as a character.
since
Android 1.0

        return patternChars[MonetaryDecimalSeparator];
    
public java.lang.StringgetNaN()
Returns the string which represents NaN.

return
the symbol NaN as a string.
since
Android 1.0

        return NaN;
    
public chargetPatternSeparator()
Returns the character which separates the positive and negative patterns in a format pattern.

return
the pattern separator character.
since
Android 1.0

        return patternChars[PatternSeparator];
    
public chargetPerMill()
Returns the per mill sign character.

return
the per mill sign character.
since
Android 1.0

        return patternChars[PerMill];
    
public chargetPercent()
Returns the percent character.

return
the percent character.
since
Android 1.0

        return patternChars[Percent];
    
public chargetZeroDigit()
Returns the character which represents zero.

return
the zero character.
since
Android 1.0

        return patternChars[ZeroDigit];
    
public inthashCode()

        return new String(patternChars).hashCode() + infinity.hashCode()
                + NaN.hashCode() + currencySymbol.hashCode()
                + intlCurrencySymbol.hashCode();
    
private voidreadObject(java.io.ObjectInputStream stream)

        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;
        }
    
public voidsetCurrency(java.util.Currency currency)
Sets the currency.

The international currency symbol and the currency symbol are updated, but the min and max number of fraction digits stays the same.

param
currency the new currency.
throws
NullPointerException if {@code currency} is {@code null}.
since
Android 1.0

        if (currency == null) {
            throw new NullPointerException();
        }
        if (currency == this.currency) {
            return;
        }
        this.currency = currency;
        intlCurrencySymbol = currency.getCurrencyCode();
        currencySymbol = currency.getSymbol(locale);
    
public voidsetCurrencySymbol(java.lang.String value)
Sets the currency symbol.

param
value the currency symbol.
since
Android 1.0

        currencySymbol = value;
    
public voidsetDecimalSeparator(char value)
Sets the character which represents the decimal point in a number.

param
value the decimal separator character.
since
Android 1.0

        patternChars[DecimalSeparator] = value;
    
public voidsetDigit(char value)
Sets the character which represents a single digit in a format pattern.

param
value the digit character.
since
Android 1.0

        patternChars[Digit] = value;
    
voidsetExponential(char value)

        patternChars[Exponent] = value;
    
public voidsetGroupingSeparator(char value)
Sets the character used as the thousands separator in a number.

param
value the grouping separator character.
since
Android 1.0

        patternChars[GroupingSeparator] = value;
    
public voidsetInfinity(java.lang.String value)
Sets the string which represents infinity.

param
value the string representing infinity.
since
Android 1.0

        infinity = value;
    
public voidsetInternationalCurrencySymbol(java.lang.String value)
Sets the international currency symbol.

The currency and currency symbol are also updated if {@code value} is a valid ISO4217 currency code.

The min and max number of fraction digits stay the same.

param
value the currency code.
since
Android 1.0

        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;
    
public voidsetMinusSign(char value)
Sets the minus sign character.

param
value the minus sign character.
since
Android 1.0

        patternChars[MinusSign] = value;
    
public voidsetMonetaryDecimalSeparator(char value)
Sets the character which represents the decimal point in a monetary value.

param
value the monetary decimal separator character.
since
Android 1.0

        patternChars[MonetaryDecimalSeparator] = value;
    
public voidsetNaN(java.lang.String value)
Sets the string which represents NaN.

param
value the string representing NaN.
since
Android 1.0

        NaN = value;
    
public voidsetPatternSeparator(char value)
Sets the character which separates the positive and negative patterns in a format pattern.

param
value the pattern separator character.
since
Android 1.0

        patternChars[PatternSeparator] = value;
    
public voidsetPerMill(char value)
Sets the per mill sign character.

param
value the per mill character.
since
Android 1.0

        patternChars[PerMill] = value;
    
public voidsetPercent(char value)
Sets the percent character.

param
value the percent character.
since
Android 1.0

        patternChars[Percent] = value;
    
public voidsetZeroDigit(char value)
Sets the character which represents zero.

param
value the zero digit character.
since
Android 1.0

        patternChars[ZeroDigit] = value;
    
private voidwriteObject(java.io.ObjectOutputStream stream)

 //$NON-NLS-1$

          
        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();