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:
Tania Bento 2007-04-05 00:15:16 +00:00 committed by Tom Tromey
parent dabf62003e
commit 618bf37b05
10 changed files with 162 additions and 21 deletions

View File

@ -1,3 +1,21 @@
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".
2007-04-04 Kyle Galloway <kgallowa@redhat.com> 2007-04-04 Kyle Galloway <kgallowa@redhat.com>
* classpath/gnu/classpath/jdwp/util/VariableTable.java: Change longs * classpath/gnu/classpath/jdwp/util/VariableTable.java: Change longs

View File

@ -46,8 +46,8 @@ public:
::java::lang::Object * getOption(jint); ::java::lang::Object * getOption(jint);
void shutdownInput(); void shutdownInput();
void shutdownOutput(); void shutdownOutput();
public: // actually protected
void create(jboolean); void create(jboolean);
public: // actually protected
void connect(::java::lang::String *, jint); void connect(::java::lang::String *, jint);
void connect(::java::net::InetAddress *, jint); void connect(::java::net::InetAddress *, jint);
void connect(::java::net::SocketAddress *, jint); void connect(::java::net::SocketAddress *, jint);

View File

@ -50,7 +50,6 @@ private:
static void writeVersionInfo(::java::util::jar::Attributes *, ::java::io::OutputStream *); static void writeVersionInfo(::java::util::jar::Attributes *, ::java::io::OutputStream *);
static void writeAttributeEntry(::java::util::Map$Entry *, ::java::io::OutputStream *); static void writeAttributeEntry(::java::util::Map$Entry *, ::java::io::OutputStream *);
static void writeHeader(::java::lang::String *, ::java::lang::String *, ::java::io::OutputStream *); static void writeHeader(::java::lang::String *, ::java::lang::String *, ::java::io::OutputStream *);
static ::java::util::logging::Logger * log;
public: public:
static ::java::lang::String * META_INF; static ::java::lang::String * META_INF;
static ::java::lang::String * DSA_SUFFIX; static ::java::lang::String * DSA_SUFFIX;

View File

@ -41,7 +41,6 @@ public:
private: private:
VMCompiler(); VMCompiler();
static ::java::lang::Class * loadSharedLibrary(::java::lang::ClassLoader *, ::java::lang::String *, ::java::security::ProtectionDomain *, ::java::lang::String *); static ::java::lang::Class * loadSharedLibrary(::java::lang::ClassLoader *, ::java::lang::String *, ::java::security::ProtectionDomain *, ::java::lang::String *);
static ::java::lang::String * bytesToString(JArray< jbyte > *);
public: public:
static ::java::lang::Class * compileClass(::java::lang::ClassLoader *, ::java::lang::String *, JArray< jbyte > *, jint, jint, ::java::security::ProtectionDomain *); static ::java::lang::Class * compileClass(::java::lang::ClassLoader *, ::java::lang::String *, JArray< jbyte > *, jint, jint, ::java::security::ProtectionDomain *);
static jboolean compileClass(::java::lang::Class *); static jboolean compileClass(::java::lang::Class *);

View File

@ -83,6 +83,7 @@ private:
jint serialVersionOnStream; jint serialVersionOnStream;
jchar zeroDigit; jchar zeroDigit;
::java::util::Locale * locale; ::java::util::Locale * locale;
::java::util::Currency * currency;
static const jlong serialVersionUID = 5772796243397350300LL; static const jlong serialVersionUID = 5772796243397350300LL;
public: public:
static ::java::lang::Class class$; static ::java::lang::Class class$;

View File

@ -1,5 +1,5 @@
/* DecimalFormatSymbols.java -- Format symbols used by DecimalFormat /* 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. 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 * This method initializes a new instance of
* <code>DecimalFormatSymbols</code> for the specified locale. * <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. * @param loc The local to load symbols for.
* @throws NullPointerException if the locale is null.
* @see #getInstance(java.util.Locale)
*/ */
public DecimalFormatSymbols (Locale loc) public DecimalFormatSymbols (Locale loc)
{ {
@ -136,14 +147,26 @@ public final class DecimalFormatSymbols implements Cloneable, Serializable
{ {
res = null; 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", '.'); decimalSeparator = safeGetChar (res, "decimalSeparator", '.');
digit = safeGetChar (res, "digit", '#'); digit = safeGetChar (res, "digit", '#');
exponential = safeGetChar (res, "exponential", 'E'); exponential = safeGetChar (res, "exponential", 'E');
groupingSeparator = safeGetChar (res, "groupingSeparator", ','); groupingSeparator = safeGetChar (res, "groupingSeparator", ',');
infinity = safeGetString (res, "infinity", "\u221e"); infinity = safeGetString (res, "infinity", "\u221e");
// FIXME: default?
intlCurrencySymbol = safeGetString (res, "intlCurrencySymbol", "$");
try try
{ {
monetarySeparator = safeGetChar (res, "monetarySeparator", '.'); monetarySeparator = safeGetChar (res, "monetarySeparator", '.');
@ -200,12 +223,13 @@ public final class DecimalFormatSymbols implements Cloneable, Serializable
* Returns the currency corresponding to the currency symbol stored * Returns the currency corresponding to the currency symbol stored
* in the instance of <code>DecimalFormatSymbols</code>. * in the instance of <code>DecimalFormatSymbols</code>.
* *
* @return A new instance of <code>Currency</code> if * @return An instance of <code>Currency</code> which matches
* the currency code matches a known one. * the currency used, or null if there is no corresponding
* instance.
*/ */
public Currency getCurrency () 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) public void setCurrency (Currency currency)
{ {
setCurrencySymbol (currency.getSymbol()); 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 * This method sets the international currency symbol to the
* specified value. * 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));
}
} }
/** /**
@ -594,6 +638,16 @@ public final class DecimalFormatSymbols implements Cloneable, Serializable
*/ */
private Locale locale; 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 static final long serialVersionUID = 5772796243397350300L;
private void readObject(ObjectInputStream stream) private void readObject(ObjectInputStream stream)

View File

@ -13,6 +13,7 @@ class java::util::Currency : public ::java::lang::Object
Currency(); Currency();
Currency(::java::util::Locale *); Currency(::java::util::Locale *);
Currency(::java::lang::String *);
public: public:
::java::lang::String * getCurrencyCode(); ::java::lang::String * getCurrencyCode();
jint getDefaultFractionDigits(); jint getDefaultFractionDigits();
@ -28,7 +29,9 @@ public: // actually package-private
private: private:
::java::util::Locale * __attribute__((aligned(__alignof__( ::java::lang::Object)))) locale; ::java::util::Locale * __attribute__((aligned(__alignof__( ::java::lang::Object)))) locale;
::java::util::ResourceBundle * res; ::java::util::ResourceBundle * res;
static ::java::util::Properties * properties;
::java::lang::String * currencyCode; ::java::lang::String * currencyCode;
jint fractionDigits;
static ::java::util::Map * cache; static ::java::util::Map * cache;
public: public:
static ::java::lang::Class class$; static ::java::lang::Class class$;

View File

@ -37,6 +37,7 @@ exception statement from your version. */
package java.util; package java.util;
import java.io.IOException;
import java.io.ObjectStreamException; import java.io.ObjectStreamException;
import java.io.Serializable; import java.io.Serializable;
import java.text.NumberFormat; import java.text.NumberFormat;
@ -82,6 +83,16 @@ public final class Currency
*/ */
private transient ResourceBundle res; private transient ResourceBundle res;
/**
* The set of properties which map a currency to
* the currency information such as the ISO 4217
* currency code and the number of decimal points.
*
* @see #getCurrencyCode()
* @serial ignored.
*/
private static transient Properties properties;
/** /**
* The ISO 4217 currency code associated with this * The ISO 4217 currency code associated with this
* particular instance. * particular instance.
@ -91,6 +102,15 @@ public final class Currency
*/ */
private String currencyCode; private String currencyCode;
/**
* The number of fraction digits associated with this
* particular instance.
*
* @see #getDefaultFractionDigits()
* @serial the number of fraction digits
*/
private transient int fractionDigits;
/** /**
* A cache of <code>Currency</code> instances to * A cache of <code>Currency</code> instances to
* ensure the singleton nature of this class. The key * ensure the singleton nature of this class. The key
@ -108,6 +128,17 @@ public final class Currency
static static
{ {
cache = new HashMap(); cache = new HashMap();
/* Create the properties object */
properties = new Properties();
/* Try and load the properties from our iso4217.properties resource */
try
{
properties.load(Currency.class.getResourceAsStream("iso4217.properties"));
}
catch (IOException exception)
{
System.out.println("Failed to load currency resource: " + exception);
}
} }
/** /**
@ -130,9 +161,24 @@ public final class Currency
*/ */
private Currency (Locale loc) private Currency (Locale loc)
{ {
String countryCode;
String fractionDigitsKey;
/* Retrieve the country code from the locale */
countryCode = loc.getCountry();
/* If there is no country code, return */
if (countryCode.equals(""))
{
throw new
IllegalArgumentException("Invalid (empty) country code for locale:"
+ loc);
}
this.locale = loc; this.locale = loc;
this.res = ResourceBundle.getBundle ("gnu.java.locale.LocaleInformation", this.res = ResourceBundle.getBundle ("gnu.java.locale.LocaleInformation",
locale, ClassLoader.getSystemClassLoader()); locale, ClassLoader.getSystemClassLoader());
/* Retrieve the ISO4217 currency code */ /* Retrieve the ISO4217 currency code */
try try
{ {
@ -142,6 +188,25 @@ public final class Currency
{ {
currencyCode = null; currencyCode = null;
} }
/* Construct the key for the fraction digits */
fractionDigitsKey = countryCode + ".fractionDigits";
/* Retrieve the fraction digits */
fractionDigits = Integer.parseInt(properties.getProperty(fractionDigitsKey));
}
/**
* Constructor for the "XXX" special case. This allows
* a Currency to be constructed from an assumed good
* currency code.
*
* @param code the code to use.
*/
private Currency(String code)
{
currencyCode = code;
fractionDigits = -1; /* Pseudo currency */
} }
/** /**
@ -168,9 +233,7 @@ public final class Currency
*/ */
public int getDefaultFractionDigits () public int getDefaultFractionDigits ()
{ {
NumberFormat currency = NumberFormat.getCurrencyInstance (locale); return fractionDigits;
return currency.getMaximumFractionDigits();
} }
/** /**
@ -226,6 +289,10 @@ public final class Currency
{ {
Locale[] allLocales = Locale.getAvailableLocales (); Locale[] allLocales = Locale.getAvailableLocales ();
/* Nasty special case to allow an erroneous currency... blame Sun */
if (currencyCode.equals("XXX"))
return new Currency("XXX");
for (int i = 0;i < allLocales.length; i++) for (int i = 0;i < allLocales.length; i++)
{ {
Currency testCurrency = getInstance (allLocales[i]); Currency testCurrency = getInstance (allLocales[i]);