rt/emul/compact/src/main/java/java/text/DecimalFormatSymbols.java
branchjdk7-b147
changeset 1334 588d5bf7a560
child 1339 8cc04f85a683
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/rt/emul/compact/src/main/java/java/text/DecimalFormatSymbols.java	Thu Oct 03 15:40:35 2013 +0200
     1.3 @@ -0,0 +1,837 @@
     1.4 +/*
     1.5 + * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +/*
    1.30 + * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
    1.31 + * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
    1.32 + *
    1.33 + *   The original version of this source code and documentation is copyrighted
    1.34 + * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
    1.35 + * materials are provided under terms of a License Agreement between Taligent
    1.36 + * and Sun. This technology is protected by multiple US and International
    1.37 + * patents. This notice and attribution to Taligent may not be removed.
    1.38 + *   Taligent is a registered trademark of Taligent, Inc.
    1.39 + *
    1.40 + */
    1.41 +
    1.42 +package java.text;
    1.43 +
    1.44 +import java.io.IOException;
    1.45 +import java.io.ObjectInputStream;
    1.46 +import java.io.Serializable;
    1.47 +import java.text.spi.DecimalFormatSymbolsProvider;
    1.48 +import java.util.Currency;
    1.49 +import java.util.Locale;
    1.50 +import java.util.ResourceBundle;
    1.51 +import java.util.concurrent.ConcurrentHashMap;
    1.52 +
    1.53 +import sun.util.LocaleServiceProviderPool;
    1.54 +import sun.util.resources.LocaleData;
    1.55 +
    1.56 +/**
    1.57 + * This class represents the set of symbols (such as the decimal separator,
    1.58 + * the grouping separator, and so on) needed by <code>DecimalFormat</code>
    1.59 + * to format numbers. <code>DecimalFormat</code> creates for itself an instance of
    1.60 + * <code>DecimalFormatSymbols</code> from its locale data.  If you need to change any
    1.61 + * of these symbols, you can get the <code>DecimalFormatSymbols</code> object from
    1.62 + * your <code>DecimalFormat</code> and modify it.
    1.63 + *
    1.64 + * @see          java.util.Locale
    1.65 + * @see          DecimalFormat
    1.66 + * @author       Mark Davis
    1.67 + * @author       Alan Liu
    1.68 + */
    1.69 +
    1.70 +public class DecimalFormatSymbols implements Cloneable, Serializable {
    1.71 +
    1.72 +    /**
    1.73 +     * Create a DecimalFormatSymbols object for the default locale.
    1.74 +     * This constructor can only construct instances for the locales
    1.75 +     * supported by the Java runtime environment, not for those
    1.76 +     * supported by installed
    1.77 +     * {@link java.text.spi.DecimalFormatSymbolsProvider DecimalFormatSymbolsProvider}
    1.78 +     * implementations. For full locale coverage, use the
    1.79 +     * {@link #getInstance(Locale) getInstance} method.
    1.80 +     */
    1.81 +    public DecimalFormatSymbols() {
    1.82 +        initialize( Locale.getDefault(Locale.Category.FORMAT) );
    1.83 +    }
    1.84 +
    1.85 +    /**
    1.86 +     * Create a DecimalFormatSymbols object for the given locale.
    1.87 +     * This constructor can only construct instances for the locales
    1.88 +     * supported by the Java runtime environment, not for those
    1.89 +     * supported by installed
    1.90 +     * {@link java.text.spi.DecimalFormatSymbolsProvider DecimalFormatSymbolsProvider}
    1.91 +     * implementations. For full locale coverage, use the
    1.92 +     * {@link #getInstance(Locale) getInstance} method.
    1.93 +     *
    1.94 +     * @exception NullPointerException if <code>locale</code> is null
    1.95 +     */
    1.96 +    public DecimalFormatSymbols( Locale locale ) {
    1.97 +        initialize( locale );
    1.98 +    }
    1.99 +
   1.100 +    /**
   1.101 +     * Returns an array of all locales for which the
   1.102 +     * <code>getInstance</code> methods of this class can return
   1.103 +     * localized instances.
   1.104 +     * The returned array represents the union of locales supported by the Java
   1.105 +     * runtime and by installed
   1.106 +     * {@link java.text.spi.DecimalFormatSymbolsProvider DecimalFormatSymbolsProvider}
   1.107 +     * implementations.  It must contain at least a <code>Locale</code>
   1.108 +     * instance equal to {@link java.util.Locale#US Locale.US}.
   1.109 +     *
   1.110 +     * @return An array of locales for which localized
   1.111 +     *         <code>DecimalFormatSymbols</code> instances are available.
   1.112 +     * @since 1.6
   1.113 +     */
   1.114 +    public static Locale[] getAvailableLocales() {
   1.115 +        LocaleServiceProviderPool pool =
   1.116 +            LocaleServiceProviderPool.getPool(DecimalFormatSymbolsProvider.class);
   1.117 +        return pool.getAvailableLocales();
   1.118 +    }
   1.119 +
   1.120 +    /**
   1.121 +     * Gets the <code>DecimalFormatSymbols</code> instance for the default
   1.122 +     * locale.  This method provides access to <code>DecimalFormatSymbols</code>
   1.123 +     * instances for locales supported by the Java runtime itself as well
   1.124 +     * as for those supported by installed
   1.125 +     * {@link java.text.spi.DecimalFormatSymbolsProvider
   1.126 +     * DecimalFormatSymbolsProvider} implementations.
   1.127 +     * @return a <code>DecimalFormatSymbols</code> instance.
   1.128 +     * @since 1.6
   1.129 +     */
   1.130 +    public static final DecimalFormatSymbols getInstance() {
   1.131 +        return getInstance(Locale.getDefault(Locale.Category.FORMAT));
   1.132 +    }
   1.133 +
   1.134 +    /**
   1.135 +     * Gets the <code>DecimalFormatSymbols</code> instance for the specified
   1.136 +     * locale.  This method provides access to <code>DecimalFormatSymbols</code>
   1.137 +     * instances for locales supported by the Java runtime itself as well
   1.138 +     * as for those supported by installed
   1.139 +     * {@link java.text.spi.DecimalFormatSymbolsProvider
   1.140 +     * DecimalFormatSymbolsProvider} implementations.
   1.141 +     * @param locale the desired locale.
   1.142 +     * @return a <code>DecimalFormatSymbols</code> instance.
   1.143 +     * @exception NullPointerException if <code>locale</code> is null
   1.144 +     * @since 1.6
   1.145 +     */
   1.146 +    public static final DecimalFormatSymbols getInstance(Locale locale) {
   1.147 +
   1.148 +        // Check whether a provider can provide an implementation that's closer
   1.149 +        // to the requested locale than what the Java runtime itself can provide.
   1.150 +        LocaleServiceProviderPool pool =
   1.151 +            LocaleServiceProviderPool.getPool(DecimalFormatSymbolsProvider.class);
   1.152 +        if (pool.hasProviders()) {
   1.153 +            DecimalFormatSymbols providersInstance = pool.getLocalizedObject(
   1.154 +                                DecimalFormatSymbolsGetter.INSTANCE, locale);
   1.155 +            if (providersInstance != null) {
   1.156 +                return providersInstance;
   1.157 +            }
   1.158 +        }
   1.159 +
   1.160 +        return new DecimalFormatSymbols(locale);
   1.161 +    }
   1.162 +
   1.163 +    /**
   1.164 +     * Gets the character used for zero. Different for Arabic, etc.
   1.165 +     */
   1.166 +    public char getZeroDigit() {
   1.167 +        return zeroDigit;
   1.168 +    }
   1.169 +
   1.170 +    /**
   1.171 +     * Sets the character used for zero. Different for Arabic, etc.
   1.172 +     */
   1.173 +    public void setZeroDigit(char zeroDigit) {
   1.174 +        this.zeroDigit = zeroDigit;
   1.175 +    }
   1.176 +
   1.177 +    /**
   1.178 +     * Gets the character used for thousands separator. Different for French, etc.
   1.179 +     */
   1.180 +    public char getGroupingSeparator() {
   1.181 +        return groupingSeparator;
   1.182 +    }
   1.183 +
   1.184 +    /**
   1.185 +     * Sets the character used for thousands separator. Different for French, etc.
   1.186 +     */
   1.187 +    public void setGroupingSeparator(char groupingSeparator) {
   1.188 +        this.groupingSeparator = groupingSeparator;
   1.189 +    }
   1.190 +
   1.191 +    /**
   1.192 +     * Gets the character used for decimal sign. Different for French, etc.
   1.193 +     */
   1.194 +    public char getDecimalSeparator() {
   1.195 +        return decimalSeparator;
   1.196 +    }
   1.197 +
   1.198 +    /**
   1.199 +     * Sets the character used for decimal sign. Different for French, etc.
   1.200 +     */
   1.201 +    public void setDecimalSeparator(char decimalSeparator) {
   1.202 +        this.decimalSeparator = decimalSeparator;
   1.203 +    }
   1.204 +
   1.205 +    /**
   1.206 +     * Gets the character used for per mille sign. Different for Arabic, etc.
   1.207 +     */
   1.208 +    public char getPerMill() {
   1.209 +        return perMill;
   1.210 +    }
   1.211 +
   1.212 +    /**
   1.213 +     * Sets the character used for per mille sign. Different for Arabic, etc.
   1.214 +     */
   1.215 +    public void setPerMill(char perMill) {
   1.216 +        this.perMill = perMill;
   1.217 +    }
   1.218 +
   1.219 +    /**
   1.220 +     * Gets the character used for percent sign. Different for Arabic, etc.
   1.221 +     */
   1.222 +    public char getPercent() {
   1.223 +        return percent;
   1.224 +    }
   1.225 +
   1.226 +    /**
   1.227 +     * Sets the character used for percent sign. Different for Arabic, etc.
   1.228 +     */
   1.229 +    public void setPercent(char percent) {
   1.230 +        this.percent = percent;
   1.231 +    }
   1.232 +
   1.233 +    /**
   1.234 +     * Gets the character used for a digit in a pattern.
   1.235 +     */
   1.236 +    public char getDigit() {
   1.237 +        return digit;
   1.238 +    }
   1.239 +
   1.240 +    /**
   1.241 +     * Sets the character used for a digit in a pattern.
   1.242 +     */
   1.243 +    public void setDigit(char digit) {
   1.244 +        this.digit = digit;
   1.245 +    }
   1.246 +
   1.247 +    /**
   1.248 +     * Gets the character used to separate positive and negative subpatterns
   1.249 +     * in a pattern.
   1.250 +     */
   1.251 +    public char getPatternSeparator() {
   1.252 +        return patternSeparator;
   1.253 +    }
   1.254 +
   1.255 +    /**
   1.256 +     * Sets the character used to separate positive and negative subpatterns
   1.257 +     * in a pattern.
   1.258 +     */
   1.259 +    public void setPatternSeparator(char patternSeparator) {
   1.260 +        this.patternSeparator = patternSeparator;
   1.261 +    }
   1.262 +
   1.263 +    /**
   1.264 +     * Gets the string used to represent infinity. Almost always left
   1.265 +     * unchanged.
   1.266 +     */
   1.267 +    public String getInfinity() {
   1.268 +        return infinity;
   1.269 +    }
   1.270 +
   1.271 +    /**
   1.272 +     * Sets the string used to represent infinity. Almost always left
   1.273 +     * unchanged.
   1.274 +     */
   1.275 +    public void setInfinity(String infinity) {
   1.276 +        this.infinity = infinity;
   1.277 +    }
   1.278 +
   1.279 +    /**
   1.280 +     * Gets the string used to represent "not a number". Almost always left
   1.281 +     * unchanged.
   1.282 +     */
   1.283 +    public String getNaN() {
   1.284 +        return NaN;
   1.285 +    }
   1.286 +
   1.287 +    /**
   1.288 +     * Sets the string used to represent "not a number". Almost always left
   1.289 +     * unchanged.
   1.290 +     */
   1.291 +    public void setNaN(String NaN) {
   1.292 +        this.NaN = NaN;
   1.293 +    }
   1.294 +
   1.295 +    /**
   1.296 +     * Gets the character used to represent minus sign. If no explicit
   1.297 +     * negative format is specified, one is formed by prefixing
   1.298 +     * minusSign to the positive format.
   1.299 +     */
   1.300 +    public char getMinusSign() {
   1.301 +        return minusSign;
   1.302 +    }
   1.303 +
   1.304 +    /**
   1.305 +     * Sets the character used to represent minus sign. If no explicit
   1.306 +     * negative format is specified, one is formed by prefixing
   1.307 +     * minusSign to the positive format.
   1.308 +     */
   1.309 +    public void setMinusSign(char minusSign) {
   1.310 +        this.minusSign = minusSign;
   1.311 +    }
   1.312 +
   1.313 +    /**
   1.314 +     * Returns the currency symbol for the currency of these
   1.315 +     * DecimalFormatSymbols in their locale.
   1.316 +     * @since 1.2
   1.317 +     */
   1.318 +    public String getCurrencySymbol()
   1.319 +    {
   1.320 +        return currencySymbol;
   1.321 +    }
   1.322 +
   1.323 +    /**
   1.324 +     * Sets the currency symbol for the currency of these
   1.325 +     * DecimalFormatSymbols in their locale.
   1.326 +     * @since 1.2
   1.327 +     */
   1.328 +    public void setCurrencySymbol(String currency)
   1.329 +    {
   1.330 +        currencySymbol = currency;
   1.331 +    }
   1.332 +
   1.333 +    /**
   1.334 +     * Returns the ISO 4217 currency code of the currency of these
   1.335 +     * DecimalFormatSymbols.
   1.336 +     * @since 1.2
   1.337 +     */
   1.338 +    public String getInternationalCurrencySymbol()
   1.339 +    {
   1.340 +        return intlCurrencySymbol;
   1.341 +    }
   1.342 +
   1.343 +    /**
   1.344 +     * Sets the ISO 4217 currency code of the currency of these
   1.345 +     * DecimalFormatSymbols.
   1.346 +     * If the currency code is valid (as defined by
   1.347 +     * {@link java.util.Currency#getInstance(java.lang.String) Currency.getInstance}),
   1.348 +     * this also sets the currency attribute to the corresponding Currency
   1.349 +     * instance and the currency symbol attribute to the currency's symbol
   1.350 +     * in the DecimalFormatSymbols' locale. If the currency code is not valid,
   1.351 +     * then the currency attribute is set to null and the currency symbol
   1.352 +     * attribute is not modified.
   1.353 +     *
   1.354 +     * @see #setCurrency
   1.355 +     * @see #setCurrencySymbol
   1.356 +     * @since 1.2
   1.357 +     */
   1.358 +    public void setInternationalCurrencySymbol(String currencyCode)
   1.359 +    {
   1.360 +        intlCurrencySymbol = currencyCode;
   1.361 +        currency = null;
   1.362 +        if (currencyCode != null) {
   1.363 +            try {
   1.364 +                currency = Currency.getInstance(currencyCode);
   1.365 +                currencySymbol = currency.getSymbol();
   1.366 +            } catch (IllegalArgumentException e) {
   1.367 +            }
   1.368 +        }
   1.369 +    }
   1.370 +
   1.371 +    /**
   1.372 +     * Gets the currency of these DecimalFormatSymbols. May be null if the
   1.373 +     * currency symbol attribute was previously set to a value that's not
   1.374 +     * a valid ISO 4217 currency code.
   1.375 +     *
   1.376 +     * @return the currency used, or null
   1.377 +     * @since 1.4
   1.378 +     */
   1.379 +    public Currency getCurrency() {
   1.380 +        return currency;
   1.381 +    }
   1.382 +
   1.383 +    /**
   1.384 +     * Sets the currency of these DecimalFormatSymbols.
   1.385 +     * This also sets the currency symbol attribute to the currency's symbol
   1.386 +     * in the DecimalFormatSymbols' locale, and the international currency
   1.387 +     * symbol attribute to the currency's ISO 4217 currency code.
   1.388 +     *
   1.389 +     * @param currency the new currency to be used
   1.390 +     * @exception NullPointerException if <code>currency</code> is null
   1.391 +     * @since 1.4
   1.392 +     * @see #setCurrencySymbol
   1.393 +     * @see #setInternationalCurrencySymbol
   1.394 +     */
   1.395 +    public void setCurrency(Currency currency) {
   1.396 +        if (currency == null) {
   1.397 +            throw new NullPointerException();
   1.398 +        }
   1.399 +        this.currency = currency;
   1.400 +        intlCurrencySymbol = currency.getCurrencyCode();
   1.401 +        currencySymbol = currency.getSymbol(locale);
   1.402 +    }
   1.403 +
   1.404 +
   1.405 +    /**
   1.406 +     * Returns the monetary decimal separator.
   1.407 +     * @since 1.2
   1.408 +     */
   1.409 +    public char getMonetaryDecimalSeparator()
   1.410 +    {
   1.411 +        return monetarySeparator;
   1.412 +    }
   1.413 +
   1.414 +    /**
   1.415 +     * Sets the monetary decimal separator.
   1.416 +     * @since 1.2
   1.417 +     */
   1.418 +    public void setMonetaryDecimalSeparator(char sep)
   1.419 +    {
   1.420 +        monetarySeparator = sep;
   1.421 +    }
   1.422 +
   1.423 +    //------------------------------------------------------------
   1.424 +    // BEGIN   Package Private methods ... to be made public later
   1.425 +    //------------------------------------------------------------
   1.426 +
   1.427 +    /**
   1.428 +     * Returns the character used to separate the mantissa from the exponent.
   1.429 +     */
   1.430 +    char getExponentialSymbol()
   1.431 +    {
   1.432 +        return exponential;
   1.433 +    }
   1.434 +  /**
   1.435 +   * Returns the string used to separate the mantissa from the exponent.
   1.436 +   * Examples: "x10^" for 1.23x10^4, "E" for 1.23E4.
   1.437 +   *
   1.438 +   * @return the exponent separator string
   1.439 +   * @see #setExponentSeparator(java.lang.String)
   1.440 +   * @since 1.6
   1.441 +   */
   1.442 +    public String getExponentSeparator()
   1.443 +    {
   1.444 +        return exponentialSeparator;
   1.445 +    }
   1.446 +
   1.447 +    /**
   1.448 +     * Sets the character used to separate the mantissa from the exponent.
   1.449 +     */
   1.450 +    void setExponentialSymbol(char exp)
   1.451 +    {
   1.452 +        exponential = exp;
   1.453 +    }
   1.454 +
   1.455 +  /**
   1.456 +   * Sets the string used to separate the mantissa from the exponent.
   1.457 +   * Examples: "x10^" for 1.23x10^4, "E" for 1.23E4.
   1.458 +   *
   1.459 +   * @param exp the exponent separator string
   1.460 +   * @exception NullPointerException if <code>exp</code> is null
   1.461 +   * @see #getExponentSeparator()
   1.462 +   * @since 1.6
   1.463 +   */
   1.464 +    public void setExponentSeparator(String exp)
   1.465 +    {
   1.466 +        if (exp == null) {
   1.467 +            throw new NullPointerException();
   1.468 +        }
   1.469 +        exponentialSeparator = exp;
   1.470 +     }
   1.471 +
   1.472 +
   1.473 +    //------------------------------------------------------------
   1.474 +    // END     Package Private methods ... to be made public later
   1.475 +    //------------------------------------------------------------
   1.476 +
   1.477 +    /**
   1.478 +     * Standard override.
   1.479 +     */
   1.480 +    public Object clone() {
   1.481 +        try {
   1.482 +            return (DecimalFormatSymbols)super.clone();
   1.483 +            // other fields are bit-copied
   1.484 +        } catch (CloneNotSupportedException e) {
   1.485 +            throw new InternalError();
   1.486 +        }
   1.487 +    }
   1.488 +
   1.489 +    /**
   1.490 +     * Override equals.
   1.491 +     */
   1.492 +    public boolean equals(Object obj) {
   1.493 +        if (obj == null) return false;
   1.494 +        if (this == obj) return true;
   1.495 +        if (getClass() != obj.getClass()) return false;
   1.496 +        DecimalFormatSymbols other = (DecimalFormatSymbols) obj;
   1.497 +        return (zeroDigit == other.zeroDigit &&
   1.498 +        groupingSeparator == other.groupingSeparator &&
   1.499 +        decimalSeparator == other.decimalSeparator &&
   1.500 +        percent == other.percent &&
   1.501 +        perMill == other.perMill &&
   1.502 +        digit == other.digit &&
   1.503 +        minusSign == other.minusSign &&
   1.504 +        patternSeparator == other.patternSeparator &&
   1.505 +        infinity.equals(other.infinity) &&
   1.506 +        NaN.equals(other.NaN) &&
   1.507 +        currencySymbol.equals(other.currencySymbol) &&
   1.508 +        intlCurrencySymbol.equals(other.intlCurrencySymbol) &&
   1.509 +        currency == other.currency &&
   1.510 +        monetarySeparator == other.monetarySeparator &&
   1.511 +        exponentialSeparator.equals(other.exponentialSeparator) &&
   1.512 +        locale.equals(other.locale));
   1.513 +    }
   1.514 +
   1.515 +    /**
   1.516 +     * Override hashCode.
   1.517 +     */
   1.518 +    public int hashCode() {
   1.519 +            int result = zeroDigit;
   1.520 +            result = result * 37 + groupingSeparator;
   1.521 +            result = result * 37 + decimalSeparator;
   1.522 +            return result;
   1.523 +    }
   1.524 +
   1.525 +    /**
   1.526 +     * Initializes the symbols from the FormatData resource bundle.
   1.527 +     */
   1.528 +    private void initialize( Locale locale ) {
   1.529 +        this.locale = locale;
   1.530 +
   1.531 +        // get resource bundle data - try the cache first
   1.532 +        boolean needCacheUpdate = false;
   1.533 +        Object[] data = cachedLocaleData.get(locale);
   1.534 +        if (data == null) {  /* cache miss */
   1.535 +            // When numbering system is thai (Locale's extension contains u-nu-thai),
   1.536 +            // we read the data from th_TH_TH.
   1.537 +            Locale lookupLocale = locale;
   1.538 +            String numberType = locale.getUnicodeLocaleType("nu");
   1.539 +            if (numberType != null && numberType.equals("thai")) {
   1.540 +                lookupLocale = new Locale("th", "TH", "TH");
   1.541 +            }
   1.542 +            data = new Object[3];
   1.543 +            ResourceBundle rb = LocaleData.getNumberFormatData(lookupLocale);
   1.544 +            data[0] = rb.getStringArray("NumberElements");
   1.545 +            needCacheUpdate = true;
   1.546 +        }
   1.547 +
   1.548 +        String[] numberElements = (String[]) data[0];
   1.549 +
   1.550 +        decimalSeparator = numberElements[0].charAt(0);
   1.551 +        groupingSeparator = numberElements[1].charAt(0);
   1.552 +        patternSeparator = numberElements[2].charAt(0);
   1.553 +        percent = numberElements[3].charAt(0);
   1.554 +        zeroDigit = numberElements[4].charAt(0); //different for Arabic,etc.
   1.555 +        digit = numberElements[5].charAt(0);
   1.556 +        minusSign = numberElements[6].charAt(0);
   1.557 +        exponential = numberElements[7].charAt(0);
   1.558 +        exponentialSeparator = numberElements[7]; //string representation new since 1.6
   1.559 +        perMill = numberElements[8].charAt(0);
   1.560 +        infinity  = numberElements[9];
   1.561 +        NaN = numberElements[10];
   1.562 +
   1.563 +        // Try to obtain the currency used in the locale's country.
   1.564 +        // Check for empty country string separately because it's a valid
   1.565 +        // country ID for Locale (and used for the C locale), but not a valid
   1.566 +        // ISO 3166 country code, and exceptions are expensive.
   1.567 +        if (!"".equals(locale.getCountry())) {
   1.568 +            try {
   1.569 +                currency = Currency.getInstance(locale);
   1.570 +            } catch (IllegalArgumentException e) {
   1.571 +                // use default values below for compatibility
   1.572 +            }
   1.573 +        }
   1.574 +        if (currency != null) {
   1.575 +            intlCurrencySymbol = currency.getCurrencyCode();
   1.576 +            if (data[1] != null && data[1] == intlCurrencySymbol) {
   1.577 +                currencySymbol = (String) data[2];
   1.578 +            } else {
   1.579 +                currencySymbol = currency.getSymbol(locale);
   1.580 +                data[1] = intlCurrencySymbol;
   1.581 +                data[2] = currencySymbol;
   1.582 +                needCacheUpdate = true;
   1.583 +            }
   1.584 +        } else {
   1.585 +            // default values
   1.586 +            intlCurrencySymbol = "XXX";
   1.587 +            try {
   1.588 +                currency = Currency.getInstance(intlCurrencySymbol);
   1.589 +            } catch (IllegalArgumentException e) {
   1.590 +            }
   1.591 +            currencySymbol = "\u00A4";
   1.592 +        }
   1.593 +        // Currently the monetary decimal separator is the same as the
   1.594 +        // standard decimal separator for all locales that we support.
   1.595 +        // If that changes, add a new entry to NumberElements.
   1.596 +        monetarySeparator = decimalSeparator;
   1.597 +
   1.598 +        if (needCacheUpdate) {
   1.599 +            cachedLocaleData.putIfAbsent(locale, data);
   1.600 +        }
   1.601 +    }
   1.602 +
   1.603 +    /**
   1.604 +     * Reads the default serializable fields, provides default values for objects
   1.605 +     * in older serial versions, and initializes non-serializable fields.
   1.606 +     * If <code>serialVersionOnStream</code>
   1.607 +     * is less than 1, initializes <code>monetarySeparator</code> to be
   1.608 +     * the same as <code>decimalSeparator</code> and <code>exponential</code>
   1.609 +     * to be 'E'.
   1.610 +     * If <code>serialVersionOnStream</code> is less than 2,
   1.611 +     * initializes <code>locale</code>to the root locale, and initializes
   1.612 +     * If <code>serialVersionOnStream</code> is less than 3, it initializes
   1.613 +     * <code>exponentialSeparator</code> using <code>exponential</code>.
   1.614 +     * Sets <code>serialVersionOnStream</code> back to the maximum allowed value so that
   1.615 +     * default serialization will work properly if this object is streamed out again.
   1.616 +     * Initializes the currency from the intlCurrencySymbol field.
   1.617 +     *
   1.618 +     * @since JDK 1.1.6
   1.619 +     */
   1.620 +    private void readObject(ObjectInputStream stream)
   1.621 +            throws IOException, ClassNotFoundException {
   1.622 +        stream.defaultReadObject();
   1.623 +        if (serialVersionOnStream < 1) {
   1.624 +            // Didn't have monetarySeparator or exponential field;
   1.625 +            // use defaults.
   1.626 +            monetarySeparator = decimalSeparator;
   1.627 +            exponential       = 'E';
   1.628 +        }
   1.629 +        if (serialVersionOnStream < 2) {
   1.630 +            // didn't have locale; use root locale
   1.631 +            locale = Locale.ROOT;
   1.632 +        }
   1.633 +        if (serialVersionOnStream < 3) {
   1.634 +            // didn't have exponentialSeparator. Create one using exponential
   1.635 +            exponentialSeparator = Character.toString(exponential);
   1.636 +        }
   1.637 +        serialVersionOnStream = currentSerialVersion;
   1.638 +
   1.639 +        if (intlCurrencySymbol != null) {
   1.640 +            try {
   1.641 +                 currency = Currency.getInstance(intlCurrencySymbol);
   1.642 +            } catch (IllegalArgumentException e) {
   1.643 +            }
   1.644 +        }
   1.645 +    }
   1.646 +
   1.647 +    /**
   1.648 +     * Character used for zero.
   1.649 +     *
   1.650 +     * @serial
   1.651 +     * @see #getZeroDigit
   1.652 +     */
   1.653 +    private  char    zeroDigit;
   1.654 +
   1.655 +    /**
   1.656 +     * Character used for thousands separator.
   1.657 +     *
   1.658 +     * @serial
   1.659 +     * @see #getGroupingSeparator
   1.660 +     */
   1.661 +    private  char    groupingSeparator;
   1.662 +
   1.663 +    /**
   1.664 +     * Character used for decimal sign.
   1.665 +     *
   1.666 +     * @serial
   1.667 +     * @see #getDecimalSeparator
   1.668 +     */
   1.669 +    private  char    decimalSeparator;
   1.670 +
   1.671 +    /**
   1.672 +     * Character used for per mille sign.
   1.673 +     *
   1.674 +     * @serial
   1.675 +     * @see #getPerMill
   1.676 +     */
   1.677 +    private  char    perMill;
   1.678 +
   1.679 +    /**
   1.680 +     * Character used for percent sign.
   1.681 +     * @serial
   1.682 +     * @see #getPercent
   1.683 +     */
   1.684 +    private  char    percent;
   1.685 +
   1.686 +    /**
   1.687 +     * Character used for a digit in a pattern.
   1.688 +     *
   1.689 +     * @serial
   1.690 +     * @see #getDigit
   1.691 +     */
   1.692 +    private  char    digit;
   1.693 +
   1.694 +    /**
   1.695 +     * Character used to separate positive and negative subpatterns
   1.696 +     * in a pattern.
   1.697 +     *
   1.698 +     * @serial
   1.699 +     * @see #getPatternSeparator
   1.700 +     */
   1.701 +    private  char    patternSeparator;
   1.702 +
   1.703 +    /**
   1.704 +     * String used to represent infinity.
   1.705 +     * @serial
   1.706 +     * @see #getInfinity
   1.707 +     */
   1.708 +    private  String  infinity;
   1.709 +
   1.710 +    /**
   1.711 +     * String used to represent "not a number".
   1.712 +     * @serial
   1.713 +     * @see #getNaN
   1.714 +     */
   1.715 +    private  String  NaN;
   1.716 +
   1.717 +    /**
   1.718 +     * Character used to represent minus sign.
   1.719 +     * @serial
   1.720 +     * @see #getMinusSign
   1.721 +     */
   1.722 +    private  char    minusSign;
   1.723 +
   1.724 +    /**
   1.725 +     * String denoting the local currency, e.g. "$".
   1.726 +     * @serial
   1.727 +     * @see #getCurrencySymbol
   1.728 +     */
   1.729 +    private  String  currencySymbol;
   1.730 +
   1.731 +    /**
   1.732 +     * ISO 4217 currency code denoting the local currency, e.g. "USD".
   1.733 +     * @serial
   1.734 +     * @see #getInternationalCurrencySymbol
   1.735 +     */
   1.736 +    private  String  intlCurrencySymbol;
   1.737 +
   1.738 +    /**
   1.739 +     * The decimal separator used when formatting currency values.
   1.740 +     * @serial
   1.741 +     * @since JDK 1.1.6
   1.742 +     * @see #getMonetaryDecimalSeparator
   1.743 +     */
   1.744 +    private  char    monetarySeparator; // Field new in JDK 1.1.6
   1.745 +
   1.746 +    /**
   1.747 +     * The character used to distinguish the exponent in a number formatted
   1.748 +     * in exponential notation, e.g. 'E' for a number such as "1.23E45".
   1.749 +     * <p>
   1.750 +     * Note that the public API provides no way to set this field,
   1.751 +     * even though it is supported by the implementation and the stream format.
   1.752 +     * The intent is that this will be added to the API in the future.
   1.753 +     *
   1.754 +     * @serial
   1.755 +     * @since JDK 1.1.6
   1.756 +     */
   1.757 +    private  char    exponential;       // Field new in JDK 1.1.6
   1.758 +
   1.759 +  /**
   1.760 +   * The string used to separate the mantissa from the exponent.
   1.761 +   * Examples: "x10^" for 1.23x10^4, "E" for 1.23E4.
   1.762 +   * <p>
   1.763 +   * If both <code>exponential</code> and <code>exponentialSeparator</code>
   1.764 +   * exist, this <code>exponentialSeparator</code> has the precedence.
   1.765 +   *
   1.766 +   * @serial
   1.767 +   * @since 1.6
   1.768 +   */
   1.769 +    private  String    exponentialSeparator;       // Field new in JDK 1.6
   1.770 +
   1.771 +    /**
   1.772 +     * The locale of these currency format symbols.
   1.773 +     *
   1.774 +     * @serial
   1.775 +     * @since 1.4
   1.776 +     */
   1.777 +    private Locale locale;
   1.778 +
   1.779 +    // currency; only the ISO code is serialized.
   1.780 +    private transient Currency currency;
   1.781 +
   1.782 +    // Proclaim JDK 1.1 FCS compatibility
   1.783 +    static final long serialVersionUID = 5772796243397350300L;
   1.784 +
   1.785 +    // The internal serial version which says which version was written
   1.786 +    // - 0 (default) for version up to JDK 1.1.5
   1.787 +    // - 1 for version from JDK 1.1.6, which includes two new fields:
   1.788 +    //     monetarySeparator and exponential.
   1.789 +    // - 2 for version from J2SE 1.4, which includes locale field.
   1.790 +    // - 3 for version from J2SE 1.6, which includes exponentialSeparator field.
   1.791 +    private static final int currentSerialVersion = 3;
   1.792 +
   1.793 +    /**
   1.794 +     * Describes the version of <code>DecimalFormatSymbols</code> present on the stream.
   1.795 +     * Possible values are:
   1.796 +     * <ul>
   1.797 +     * <li><b>0</b> (or uninitialized): versions prior to JDK 1.1.6.
   1.798 +     *
   1.799 +     * <li><b>1</b>: Versions written by JDK 1.1.6 or later, which include
   1.800 +     *      two new fields: <code>monetarySeparator</code> and <code>exponential</code>.
   1.801 +     * <li><b>2</b>: Versions written by J2SE 1.4 or later, which include a
   1.802 +     *      new <code>locale</code> field.
   1.803 +     * <li><b>3</b>: Versions written by J2SE 1.6 or later, which include a
   1.804 +     *      new <code>exponentialSeparator</code> field.
   1.805 +     * </ul>
   1.806 +     * When streaming out a <code>DecimalFormatSymbols</code>, the most recent format
   1.807 +     * (corresponding to the highest allowable <code>serialVersionOnStream</code>)
   1.808 +     * is always written.
   1.809 +     *
   1.810 +     * @serial
   1.811 +     * @since JDK 1.1.6
   1.812 +     */
   1.813 +    private int serialVersionOnStream = currentSerialVersion;
   1.814 +
   1.815 +    /**
   1.816 +     * cache to hold the NumberElements and the Currency
   1.817 +     * of a Locale.
   1.818 +     */
   1.819 +    private static final ConcurrentHashMap<Locale, Object[]> cachedLocaleData = new ConcurrentHashMap<Locale, Object[]>(3);
   1.820 +
   1.821 +    /**
   1.822 +     * Obtains a DecimalFormatSymbols instance from a DecimalFormatSymbolsProvider
   1.823 +     * implementation.
   1.824 +     */
   1.825 +    private static class DecimalFormatSymbolsGetter
   1.826 +        implements LocaleServiceProviderPool.LocalizedObjectGetter<DecimalFormatSymbolsProvider,
   1.827 +                                                                   DecimalFormatSymbols> {
   1.828 +        private static final DecimalFormatSymbolsGetter INSTANCE =
   1.829 +            new DecimalFormatSymbolsGetter();
   1.830 +
   1.831 +        public DecimalFormatSymbols getObject(
   1.832 +                                DecimalFormatSymbolsProvider decimalFormatSymbolsProvider,
   1.833 +                                Locale locale,
   1.834 +                                String key,
   1.835 +                                Object... params) {
   1.836 +            assert params.length == 0;
   1.837 +            return decimalFormatSymbolsProvider.getInstance(locale);
   1.838 +        }
   1.839 +    }
   1.840 +}