Fields Summary |
---|
private char | zeroDigitCharacter used for zero. |
private char | groupingSeparatorCharacter used for thousands separator. |
private char | decimalSeparatorCharacter used for decimal sign. |
private char | perMillCharacter used for per mille sign. |
private char | percentCharacter used for percent sign. |
private char | digitCharacter used for a digit in a pattern. |
private char | patternSeparatorCharacter used to separate positive and negative subpatterns
in a pattern. |
private String | infinityString used to represent infinity. |
private String | NaNString used to represent "not a number". |
private char | minusSignCharacter used to represent minus sign. |
private String | currencySymbolString denoting the local currency, e.g. "$". |
private String | intlCurrencySymbolISO 4217 currency code denoting the local currency, e.g. "USD". |
private char | monetarySeparatorThe decimal separator used when formatting currency values. |
private char | exponentialThe character used to distinguish the exponent in a number formatted
in exponential notation, e.g. 'E' for a number such as "1.23E45".
Note that the public API provides no way to set this field,
even though it is supported by the implementation and the stream format.
The intent is that this will be added to the API in the future. |
private Locale | localeThe locale of these currency format symbols. |
private transient Currency | currency |
static final long | serialVersionUID |
private static final int | currentSerialVersion |
private int | serialVersionOnStreamDescribes the version of DecimalFormatSymbols present on the stream.
Possible values are:
- 0 (or uninitialized): versions prior to JDK 1.1.6.
- 1: Versions written by JDK 1.1.6 or later, which include
two new fields:
monetarySeparator and exponential .
- 2: Versions written by J2SE 1.4 or later, which include a
new
locale field.
When streaming out a DecimalFormatSymbols , the most recent format
(corresponding to the highest allowable serialVersionOnStream )
is always written. |
private static final Hashtable | cachedLocaleDatacache to hold the NumberElements and the Currency
of a Locale. |
Methods Summary |
---|
public java.lang.Object | clone()Standard override.
try {
return (DecimalFormatSymbols)super.clone();
// other fields are bit-copied
} catch (CloneNotSupportedException e) {
throw new InternalError();
}
|
public boolean | equals(java.lang.Object obj)Override equals.
if (obj == null) return false;
if (this == obj) return true;
if (getClass() != obj.getClass()) return false;
DecimalFormatSymbols other = (DecimalFormatSymbols) obj;
return (zeroDigit == other.zeroDigit &&
groupingSeparator == other.groupingSeparator &&
decimalSeparator == other.decimalSeparator &&
percent == other.percent &&
perMill == other.perMill &&
digit == other.digit &&
minusSign == other.minusSign &&
patternSeparator == other.patternSeparator &&
infinity.equals(other.infinity) &&
NaN.equals(other.NaN) &&
currencySymbol.equals(other.currencySymbol) &&
intlCurrencySymbol.equals(other.intlCurrencySymbol) &&
currency == other.currency &&
monetarySeparator == other.monetarySeparator &&
locale.equals(other.locale));
|
public java.util.Currency | getCurrency()Gets the currency of these DecimalFormatSymbols. May be null if the
currency symbol attribute was previously set to a value that's not
a valid ISO 4217 currency code.
return currency;
|
public java.lang.String | getCurrencySymbol()Returns the currency symbol for the currency of these
DecimalFormatSymbols in their locale.
return currencySymbol;
|
public char | getDecimalSeparator()Gets the character used for decimal sign. Different for French, etc.
return decimalSeparator;
|
public char | getDigit()Gets the character used for a digit in a pattern.
return digit;
|
char | getExponentialSymbol()Returns the character used to separate the mantissa from the exponent.
return exponential;
|
public char | getGroupingSeparator()Gets the character used for thousands separator. Different for French, etc.
return groupingSeparator;
|
public java.lang.String | getInfinity()Gets the string used to represent infinity. Almost always left
unchanged.
return infinity;
|
public java.lang.String | getInternationalCurrencySymbol()Returns the ISO 4217 currency code of the currency of these
DecimalFormatSymbols.
return intlCurrencySymbol;
|
public char | getMinusSign()Gets the character used to represent minus sign. If no explicit
negative format is specified, one is formed by prefixing
minusSign to the positive format.
return minusSign;
|
public char | getMonetaryDecimalSeparator()Returns the monetary decimal separator.
return monetarySeparator;
|
public java.lang.String | getNaN()Gets the string used to represent "not a number". Almost always left
unchanged.
return NaN;
|
public char | getPatternSeparator()Gets the character used to separate positive and negative subpatterns
in a pattern.
return patternSeparator;
|
public char | getPerMill()Gets the character used for per mille sign. Different for Arabic, etc.
return perMill;
|
public char | getPercent()Gets the character used for percent sign. Different for Arabic, etc.
return percent;
|
public char | getZeroDigit()Gets the character used for zero. Different for Arabic, etc.
return zeroDigit;
|
public int | hashCode()Override hashCode.
int result = zeroDigit;
result = result * 37 + groupingSeparator;
result = result * 37 + decimalSeparator;
return result;
|
private void | initialize(java.util.Locale locale)Initializes the symbols from the LocaleElements resource bundle.
this.locale = locale;
// get resource bundle data - try the cache first
boolean needCacheUpdate = false;
Object[] data = (Object[]) cachedLocaleData.get(locale);
if (data == null) { /* cache miss */
data = new Object[3];
ResourceBundle rb = LocaleData.getLocaleElements(locale);
data[0] = rb.getStringArray("NumberElements");
needCacheUpdate = true;
}
String[] numberElements = (String[]) data[0];;
decimalSeparator = numberElements[0].charAt(0);
groupingSeparator = numberElements[1].charAt(0);
patternSeparator = numberElements[2].charAt(0);
percent = numberElements[3].charAt(0);
zeroDigit = numberElements[4].charAt(0); //different for Arabic,etc.
digit = numberElements[5].charAt(0);
minusSign = numberElements[6].charAt(0);
exponential = numberElements[7].charAt(0);
perMill = numberElements[8].charAt(0);
infinity = numberElements[9];
NaN = numberElements[10];
// Try to obtain the currency used in the locale's country.
// Check for empty country string separately because it's a valid
// country ID for Locale (and used for the C locale), but not a valid
// ISO 3166 country code, and exceptions are expensive.
if (!"".equals(locale.getCountry())) {
try {
currency = Currency.getInstance(locale);
} catch (IllegalArgumentException e) {
// use default values below for compatibility
}
}
if (currency != null) {
intlCurrencySymbol = currency.getCurrencyCode();
if (data[1] != null && data[1] == intlCurrencySymbol) {
currencySymbol = (String) data[2];
} else {
currencySymbol = currency.getSymbol(locale);
data[1] = intlCurrencySymbol;
data[2] = currencySymbol;
needCacheUpdate = true;
}
} else {
// default values
intlCurrencySymbol = "XXX";
try {
currency = Currency.getInstance(intlCurrencySymbol);
} catch (IllegalArgumentException e) {
}
currencySymbol = "\u00A4";
}
// Currently the monetary decimal separator is the same as the
// standard decimal separator for all locales that we support.
// If that changes, add a new entry to NumberElements.
monetarySeparator = decimalSeparator;
if (needCacheUpdate) {
cachedLocaleData.put(locale, data);
}
|
private void | readObject(java.io.ObjectInputStream stream)Reads the default serializable fields, provides default values for objects
in older serial versions, and initializes non-serializable fields.
If serialVersionOnStream
is less than 1, initializes monetarySeparator to be
the same as decimalSeparator and exponential
to be 'E'.
If serialVersionOnStream is less then 2,
initializes locale to the root locale.
Sets serialVersionOnStream back to the maximum allowed value so that
default serialization will work properly if this object is streamed out again.
Initializes the currency from the intlCurrencySymbol field.
stream.defaultReadObject();
if (serialVersionOnStream < 1) {
// Didn't have monetarySeparator or exponential field;
// use defaults.
monetarySeparator = decimalSeparator;
exponential = 'E";
}
if (serialVersionOnStream < 2) {
// didn't have locale; use root locale
locale = new Locale("");
}
serialVersionOnStream = currentSerialVersion;
if (intlCurrencySymbol != null) {
try {
currency = Currency.getInstance(intlCurrencySymbol);
} catch (IllegalArgumentException e) {
}
}
|
public void | setCurrency(java.util.Currency currency)Sets the currency of these DecimalFormatSymbols.
This also sets the currency symbol attribute to the currency's symbol
in the DecimalFormatSymbols' locale, and the international currency
symbol attribute to the currency's ISO 4217 currency code.
if (currency == null) {
throw new NullPointerException();
}
this.currency = currency;
intlCurrencySymbol = currency.getCurrencyCode();
currencySymbol = currency.getSymbol(locale);
|
public void | setCurrencySymbol(java.lang.String currency)Sets the currency symbol for the currency of these
DecimalFormatSymbols in their locale.
currencySymbol = currency;
|
public void | setDecimalSeparator(char decimalSeparator)Sets the character used for decimal sign. Different for French, etc.
this.decimalSeparator = decimalSeparator;
|
public void | setDigit(char digit)Sets the character used for a digit in a pattern.
this.digit = digit;
|
void | setExponentialSymbol(char exp)Sets the character used to separate the mantissa from the exponent.
exponential = exp;
|
public void | setGroupingSeparator(char groupingSeparator)Sets the character used for thousands separator. Different for French, etc.
this.groupingSeparator = groupingSeparator;
|
public void | setInfinity(java.lang.String infinity)Sets the string used to represent infinity. Almost always left
unchanged.
this.infinity = infinity;
|
public void | setInternationalCurrencySymbol(java.lang.String currencyCode)Sets the ISO 4217 currency code of the currency of these
DecimalFormatSymbols.
If the currency code is valid (as defined by
{@link java.util.Currency#getInstance(java.lang.String) Currency.getInstance}),
this also sets the currency attribute to the corresponding Currency
instance and the currency symbol attribute to the currency's symbol
in the DecimalFormatSymbols' locale. If the currency code is not valid,
then the currency attribute is set to null and the currency symbol
attribute is not modified.
intlCurrencySymbol = currencyCode;
currency = null;
if (currencyCode != null) {
try {
currency = Currency.getInstance(currencyCode);
currencySymbol = currency.getSymbol();
} catch (IllegalArgumentException e) {
}
}
|
public void | setMinusSign(char minusSign)Sets the character used to represent minus sign. If no explicit
negative format is specified, one is formed by prefixing
minusSign to the positive format.
this.minusSign = minusSign;
|
public void | setMonetaryDecimalSeparator(char sep)Sets the monetary decimal separator.
monetarySeparator = sep;
|
public void | setNaN(java.lang.String NaN)Sets the string used to represent "not a number". Almost always left
unchanged.
this.NaN = NaN;
|
public void | setPatternSeparator(char patternSeparator)Sets the character used to separate positive and negative subpatterns
in a pattern.
this.patternSeparator = patternSeparator;
|
public void | setPerMill(char perMill)Sets the character used for per mille sign. Different for Arabic, etc.
this.perMill = perMill;
|
public void | setPercent(char percent)Sets the character used for percent sign. Different for Arabic, etc.
this.percent = percent;
|
public void | setZeroDigit(char zeroDigit)Sets the character used for zero. Different for Arabic, etc.
this.zeroDigit = zeroDigit;
|