From b27009bc3eaaeb79bd7270d4d38b1f6938202262 Mon Sep 17 00:00:00 2001 From: tromey Date: Thu, 5 Apr 2007 00:15:16 +0000 Subject: 2007-04-04 Tania Bento * 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". git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@123512 138bc75d-0d04-0410-961f-82ee72b054a4 --- libjava/java/util/Currency.h | 3 ++ libjava/java/util/Currency.java | 73 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 73 insertions(+), 3 deletions(-) (limited to 'libjava/java/util') diff --git a/libjava/java/util/Currency.h b/libjava/java/util/Currency.h index c868cef9ca3..ac8878c7e2b 100644 --- a/libjava/java/util/Currency.h +++ b/libjava/java/util/Currency.h @@ -13,6 +13,7 @@ class java::util::Currency : public ::java::lang::Object Currency(); Currency(::java::util::Locale *); + Currency(::java::lang::String *); public: ::java::lang::String * getCurrencyCode(); jint getDefaultFractionDigits(); @@ -28,7 +29,9 @@ public: // actually package-private private: ::java::util::Locale * __attribute__((aligned(__alignof__( ::java::lang::Object)))) locale; ::java::util::ResourceBundle * res; + static ::java::util::Properties * properties; ::java::lang::String * currencyCode; + jint fractionDigits; static ::java::util::Map * cache; public: static ::java::lang::Class class$; diff --git a/libjava/java/util/Currency.java b/libjava/java/util/Currency.java index e1a28e0b8c6..66888fa666b 100644 --- a/libjava/java/util/Currency.java +++ b/libjava/java/util/Currency.java @@ -37,6 +37,7 @@ exception statement from your version. */ package java.util; +import java.io.IOException; import java.io.ObjectStreamException; import java.io.Serializable; import java.text.NumberFormat; @@ -82,6 +83,16 @@ public final class Currency */ 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 * particular instance. @@ -91,6 +102,15 @@ public final class Currency */ 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 Currency instances to * ensure the singleton nature of this class. The key @@ -108,6 +128,17 @@ public final class Currency static { 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) { + 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.res = ResourceBundle.getBundle ("gnu.java.locale.LocaleInformation", locale, ClassLoader.getSystemClassLoader()); + /* Retrieve the ISO4217 currency code */ try { @@ -142,6 +188,25 @@ public final class Currency { 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 () { - NumberFormat currency = NumberFormat.getCurrencyInstance (locale); - - return currency.getMaximumFractionDigits(); + return fractionDigits; } /** @@ -226,6 +289,10 @@ public final class Currency { 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++) { Currency testCurrency = getInstance (allLocales[i]); -- cgit v1.2.3