aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/util
diff options
context:
space:
mode:
authorTania Bento <tbento@redhat.com>2007-04-05 00:15:16 +0000
committerTom Tromey <tromey@gcc.gnu.org>2007-04-05 00:15:16 +0000
commit618bf37b0547c0e994af34ea1e128af320410736 (patch)
treeb659460d69becef2f5b04af277ac9f35a6b13f7f /libjava/java/util
parentdabf62003ec4a2d31f5b276650b1554db840601a (diff)
downloadgcc-618bf37b0547c0e994af34ea1e128af320410736.zip
gcc-618bf37b0547c0e994af34ea1e128af320410736.tar.gz
gcc-618bf37b0547c0e994af34ea1e128af320410736.tar.bz2
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
Diffstat (limited to 'libjava/java/util')
-rw-r--r--libjava/java/util/Currency.h3
-rw-r--r--libjava/java/util/Currency.java73
2 files changed, 73 insertions, 3 deletions
diff --git a/libjava/java/util/Currency.h b/libjava/java/util/Currency.h
index c868cef..ac8878c 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 e1a28e0..66888fa 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;
@@ -83,6 +84,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.
*
@@ -92,6 +103,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 <code>Currency</code> instances to
* ensure the singleton nature of this class. The key
* is the locale of the currency.
@@ -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]);