aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/text
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/text
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/text')
-rw-r--r--libjava/java/text/DecimalFormatSymbols.h1
-rw-r--r--libjava/java/text/DecimalFormatSymbols.java84
2 files changed, 70 insertions, 15 deletions
diff --git a/libjava/java/text/DecimalFormatSymbols.h b/libjava/java/text/DecimalFormatSymbols.h
index 96bd286..b38140c 100644
--- a/libjava/java/text/DecimalFormatSymbols.h
+++ b/libjava/java/text/DecimalFormatSymbols.h
@@ -83,6 +83,7 @@ private:
jint serialVersionOnStream;
jchar zeroDigit;
::java::util::Locale * locale;
+ ::java::util::Currency * currency;
static const jlong serialVersionUID = 5772796243397350300LL;
public:
static ::java::lang::Class class$;
diff --git a/libjava/java/text/DecimalFormatSymbols.java b/libjava/java/text/DecimalFormatSymbols.java
index c58530f..110e45f 100644
--- a/libjava/java/text/DecimalFormatSymbols.java
+++ b/libjava/java/text/DecimalFormatSymbols.java
@@ -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)