diff --git a/icu4j/src/com/ibm/icu/text/DecimalFormat.java b/icu4j/src/com/ibm/icu/text/DecimalFormat.java index e9aba6be29a..a831ddffd01 100755 --- a/icu4j/src/com/ibm/icu/text/DecimalFormat.java +++ b/icu4j/src/com/ibm/icu/text/DecimalFormat.java @@ -5,8 +5,8 @@ ******************************************************************************* * * $Source: /xsrl/Nsvn/icu/icu4j/src/com/ibm/icu/text/DecimalFormat.java,v $ - * $Date: 2002/05/08 23:36:37 $ - * $Revision: 1.16 $ + * $Date: 2002/05/09 16:59:20 $ + * $Revision: 1.17 $ * ***************************************************************************************** */ @@ -446,7 +446,8 @@ public class DecimalFormat extends NumberFormat { */ public DecimalFormat (String pattern, DecimalFormatSymbols symbols) { // Always applyPattern after the symbols are set - _setDecimalFormatSymbols(symbols); + this.symbols = (DecimalFormatSymbols) symbols.clone(); + setCurrencyForSymbols(); applyPattern( pattern, false ); } @@ -1389,13 +1390,17 @@ public class DecimalFormat extends NumberFormat { * @see DecimalFormatSymbols */ public void setDecimalFormatSymbols(DecimalFormatSymbols newSymbols) { - _setDecimalFormatSymbols(newSymbols); + symbols = (DecimalFormatSymbols) newSymbols.clone(); + setCurrencyForSymbols(); expandAffixes(); } - private void _setDecimalFormatSymbols(DecimalFormatSymbols newSymbols) { - // don't allow multiple references - symbols = (DecimalFormatSymbols) newSymbols.clone(); + /** + * Update the currency object to match the symbols. This method + * is used only when the caller has passed in a symbols object + * that may not be the default object for its locale. + */ + private void setCurrencyForSymbols() { /*Bug 4212072 Update the affix strings accroding to symbols in order to keep the affix strings up to date. @@ -1407,7 +1412,7 @@ public class DecimalFormat extends NumberFormat { // compatibility, we check any explicitly set DFS object. If it // is a default symbols object for its locale, we change the // currency object to one for that locale. If it is custom, - // we create a CompatibilityCurrency object and use that. + // we set the currency to null. DecimalFormatSymbols def = new DecimalFormatSymbols(symbols.getLocale()); @@ -1417,7 +1422,7 @@ public class DecimalFormat extends NumberFormat { def.getInternationalCurrencySymbol())) { currency = Currency.getInstance(symbols.getLocale()); } else { - currency = Currency.getCompatibilityInstance(symbols); + currency = null; } } @@ -2020,14 +2025,24 @@ public class DecimalFormat extends NumberFormat { switch (c) { case CURRENCY_SIGN: // As of ICU 2.2 we use the currency object, and - // ignore the currency symbols in the DFS. - if (iCurrency object used to display currency - * amounts. + * amounts. This will be null if a object is resurrected with a + * custom DecimalFormatSymbols object, or if the user sets a + * custom DecimalFormatSymbols object. A custom + * DecimalFormatSymbols object has currency symbols that are not + * the standard ones for its locale. * @since ICU 2.2 */ public Currency getCurrency() { @@ -2893,6 +2914,11 @@ public class DecimalFormat extends NumberFormat { useExponentialNotation = false; } } + if (serialVersionOnStream < 3) { + // Versions prior to 3 do not store a currency object. + // Create one to match the DecimalFormatSymbols object. + setCurrencyForSymbols(); + } serialVersionOnStream = currentSerialVersion; digitList = new DigitList(); } @@ -3140,14 +3166,18 @@ public class DecimalFormat extends NumberFormat { /** * Currency object used to format currencies. Only used if - * isCurrencyFormat is true. + * isCurrencyFormat is true. In some cases this will be + * null: If a pre-2.2 object is resurrected with a custom + * DecimalFormatSymbols object, or if the user sets a custom DFS + * object. A custom DFS object has currency symbols that are not + * the standard ones for its locale. * @since ICU 2.2 */ private Currency currency; //---------------------------------------------------------------------- - static final int currentSerialVersion = 2; + static final int currentSerialVersion = 3; /** * The internal serial version which says which version was written @@ -3158,6 +3188,7 @@ public class DecimalFormat extends NumberFormat { * useExponentialNotation and minExponentDigits. *
  • 2: version on AlphaWorks, which adds roundingMode, formatWidth, * pad, padPosition, exponentSignAlwaysShown, roundingIncrement. + *
  • 3: ICU 2.2. Adds currency object. * * @serial */ private int serialVersionOnStream = currentSerialVersion; diff --git a/icu4j/src/com/ibm/icu/util/Currency.java b/icu4j/src/com/ibm/icu/util/Currency.java index 96a4dd1e3fd..cc6f3bf7e27 100644 --- a/icu4j/src/com/ibm/icu/util/Currency.java +++ b/icu4j/src/com/ibm/icu/util/Currency.java @@ -61,39 +61,6 @@ public class Currency implements Serializable { return isoCode; } - /** - * A Currency subclass that emulates legacy (pre ICU 2.2) - * behavior. For internal use only. - * @internal - */ - private static class CompatibilityCurrency extends Currency { - - private String symbol; - - public CompatibilityCurrency(DecimalFormatSymbols sym) { - super(sym.getInternationalCurrencySymbol()); - this.symbol = sym.getCurrencySymbol(); - } - - public String getSymbol(Locale locale) { - return symbol; - } - } - - /** - * Returns a compatibility object that mimics legacy behavior of - * the given symbols. This is used internally for consistency - * with ICU versions prior to 2.2. To obtain modern behavior, do - * not modify the currency symbol or international currency symbol - * of the DecimalFormatSymbols object used by a - * DecimalFormat. Doing so will cause those symbols to - * be used instead of a "smart" Currency object. - * @internal - */ - public static Currency getCompatibilityInstance(DecimalFormatSymbols sym) { - return new CompatibilityCurrency(sym); - } - /** * Returns the display string for this currency object in the * given locale. For example, the display string for the USD