DecimalFormatSymbols.java: Added the year 2007 to Copyright information and introduced new variable, currency.
2007-04-04 Tania Bento <tbento@redhat.com> * java/text/DecimalFormatSymbols.java: Added the year 2007 to Copyright information and introduced new variable, currency. (DecimalFormatSymbols(Locale)): Define currency and intlCurrencySymbol to "XXX", currencySymbol to "?" and localCurrency appropriately. (getCurrency): Fixed documentation and return the value of currency. (setCurrency): Fixed documentation and update the value of currency. (setInternationalCurrencySymbol): Fixed documentation and update the value of currency. * java/util/Currency.java: Introduced two new variables, properties and fractionDigits. In the static block, a properties object is created and the currency resource is loaded. (Currency(Locale)): fractionDigits is defined. (Currency(String)): New method. (getDefaultFractionDigits): Return the value of fractionDigits. (getInstance(String)): Check if String is equal to "XXX". From-SVN: r123512
This commit is contained in:
parent
dabf62003e
commit
618bf37b05
10 changed files with 162 additions and 21 deletions
|
@ -1,5 +1,5 @@
|
|||
/* DecimalFormatSymbols.java -- Format symbols used by DecimalFormat
|
||||
Copyright (C) 1999, 2000, 2001, 2004 Free Software Foundation, Inc.
|
||||
Copyright (C) 1999, 2000, 2001, 2004, 2007 Free Software Foundation, Inc.
|
||||
|
||||
This file is part of GNU Classpath.
|
||||
|
||||
|
@ -121,8 +121,19 @@ public final class DecimalFormatSymbols implements Cloneable, Serializable
|
|||
/**
|
||||
* This method initializes a new instance of
|
||||
* <code>DecimalFormatSymbols</code> for the specified locale.
|
||||
* <strong>Note</strong>: if the locale does not have an associated
|
||||
* <code>Currency</code> instance, the currency symbol and
|
||||
* international currency symbol will be set to the strings "?"
|
||||
* and "XXX" respectively. This generally happens with language
|
||||
* locales (those with no specified country), such as
|
||||
* <code>Locale.ENGLISH</code>. This constructor only obtains
|
||||
* instances using the runtime's resources; to also include
|
||||
* {@link java.text.spi.DecimalFormatSymbolsProvider} instances,
|
||||
* call {@link #getInstance(java.util.Locale)} instead.
|
||||
*
|
||||
* @param loc The local to load symbols for.
|
||||
* @throws NullPointerException if the locale is null.
|
||||
* @see #getInstance(java.util.Locale)
|
||||
*/
|
||||
public DecimalFormatSymbols (Locale loc)
|
||||
{
|
||||
|
@ -136,14 +147,26 @@ public final class DecimalFormatSymbols implements Cloneable, Serializable
|
|||
{
|
||||
res = null;
|
||||
}
|
||||
currencySymbol = safeGetString (res, "currencySymbol", "$");
|
||||
currency = Currency.getInstance("XXX");
|
||||
currencySymbol = "?";
|
||||
intlCurrencySymbol = "XXX";
|
||||
try
|
||||
{
|
||||
Currency localeCurrency = Currency.getInstance(loc);
|
||||
if (localeCurrency != null)
|
||||
{
|
||||
setCurrency(localeCurrency);
|
||||
}
|
||||
}
|
||||
catch(IllegalArgumentException exception)
|
||||
{
|
||||
/* Locale has an invalid currency */
|
||||
}
|
||||
decimalSeparator = safeGetChar (res, "decimalSeparator", '.');
|
||||
digit = safeGetChar (res, "digit", '#');
|
||||
exponential = safeGetChar (res, "exponential", 'E');
|
||||
groupingSeparator = safeGetChar (res, "groupingSeparator", ',');
|
||||
infinity = safeGetString (res, "infinity", "\u221e");
|
||||
// FIXME: default?
|
||||
intlCurrencySymbol = safeGetString (res, "intlCurrencySymbol", "$");
|
||||
try
|
||||
{
|
||||
monetarySeparator = safeGetChar (res, "monetarySeparator", '.');
|
||||
|
@ -200,12 +223,13 @@ public final class DecimalFormatSymbols implements Cloneable, Serializable
|
|||
* Returns the currency corresponding to the currency symbol stored
|
||||
* in the instance of <code>DecimalFormatSymbols</code>.
|
||||
*
|
||||
* @return A new instance of <code>Currency</code> if
|
||||
* the currency code matches a known one.
|
||||
* @return An instance of <code>Currency</code> which matches
|
||||
* the currency used, or null if there is no corresponding
|
||||
* instance.
|
||||
*/
|
||||
public Currency getCurrency ()
|
||||
{
|
||||
return Currency.getInstance (currencySymbol);
|
||||
return currency;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -368,13 +392,16 @@ public final class DecimalFormatSymbols implements Cloneable, Serializable
|
|||
}
|
||||
|
||||
/**
|
||||
* This method sets the currency to the specified value.
|
||||
* This method sets the currency symbol and ISO 4217 currency
|
||||
* code to the values obtained from the supplied currency.
|
||||
*
|
||||
* @param currency The new currency
|
||||
* @param currency the currency from which to obtain the values.
|
||||
* @throws NullPointerException if the currency is null.
|
||||
*/
|
||||
public void setCurrency (Currency currency)
|
||||
{
|
||||
setCurrencySymbol (currency.getSymbol());
|
||||
this.currency = currency;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -435,14 +462,31 @@ public final class DecimalFormatSymbols implements Cloneable, Serializable
|
|||
}
|
||||
|
||||
/**
|
||||
* This method sets the international currency symbols to the
|
||||
* specified value.
|
||||
* This method sets the international currency symbol to the
|
||||
* specified value. If a valid <code>Currency</code> instance
|
||||
* exists for the international currency code, then this is
|
||||
* used for the currency attribute, and the currency symbol
|
||||
* is set to the corresponding value from this instance.
|
||||
* Otherwise, the currency attribute is set to null and the
|
||||
* symbol is left unmodified.
|
||||
*
|
||||
* @param intlCurrencySymbol The new international currency symbol.
|
||||
* @param currencyCode The new international currency symbol.
|
||||
*/
|
||||
public void setInternationalCurrencySymbol (String currency)
|
||||
public void setInternationalCurrencySymbol (String currencyCode)
|
||||
{
|
||||
intlCurrencySymbol = currency;
|
||||
intlCurrencySymbol = currencyCode;
|
||||
try
|
||||
{
|
||||
currency = Currency.getInstance(currencyCode);
|
||||
}
|
||||
catch (IllegalArgumentException exception)
|
||||
{
|
||||
currency = null;
|
||||
}
|
||||
if (currency != null)
|
||||
{
|
||||
setCurrencySymbol(currency.getSymbol(locale));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -593,7 +637,17 @@ public final class DecimalFormatSymbols implements Cloneable, Serializable
|
|||
* @serial The locale of these currency symbols.
|
||||
*/
|
||||
private Locale locale;
|
||||
|
||||
|
||||
/**
|
||||
* The currency used for the symbols in this instance.
|
||||
* This is stored temporarily for efficiency reasons,
|
||||
* as well as to ensure that the correct instance
|
||||
* is restored from the currency code.
|
||||
*
|
||||
* @serial Ignored.
|
||||
*/
|
||||
private transient Currency currency;
|
||||
|
||||
private static final long serialVersionUID = 5772796243397350300L;
|
||||
|
||||
private void readObject(ObjectInputStream stream)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue