rt/emul/compact/src/main/java/java/text/DecimalFormatSymbols.java
author Jaroslav Tulach <jaroslav.tulach@apidesign.org>
Fri, 04 Oct 2013 11:07:00 +0200
changeset 1339 8cc04f85a683
parent 1334 588d5bf7a560
permissions -rw-r--r--
Commenting out stuff in java.text so the classes compile
jtulach@1334
     1
/*
jtulach@1334
     2
 * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
jtulach@1334
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
jtulach@1334
     4
 *
jtulach@1334
     5
 * This code is free software; you can redistribute it and/or modify it
jtulach@1334
     6
 * under the terms of the GNU General Public License version 2 only, as
jtulach@1334
     7
 * published by the Free Software Foundation.  Oracle designates this
jtulach@1334
     8
 * particular file as subject to the "Classpath" exception as provided
jtulach@1334
     9
 * by Oracle in the LICENSE file that accompanied this code.
jtulach@1334
    10
 *
jtulach@1334
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
jtulach@1334
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
jtulach@1334
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
jtulach@1334
    14
 * version 2 for more details (a copy is included in the LICENSE file that
jtulach@1334
    15
 * accompanied this code).
jtulach@1334
    16
 *
jtulach@1334
    17
 * You should have received a copy of the GNU General Public License version
jtulach@1334
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
jtulach@1334
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
jtulach@1334
    20
 *
jtulach@1334
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
jtulach@1334
    22
 * or visit www.oracle.com if you need additional information or have any
jtulach@1334
    23
 * questions.
jtulach@1334
    24
 */
jtulach@1334
    25
jtulach@1334
    26
/*
jtulach@1334
    27
 * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
jtulach@1334
    28
 * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
jtulach@1334
    29
 *
jtulach@1334
    30
 *   The original version of this source code and documentation is copyrighted
jtulach@1334
    31
 * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
jtulach@1334
    32
 * materials are provided under terms of a License Agreement between Taligent
jtulach@1334
    33
 * and Sun. This technology is protected by multiple US and International
jtulach@1334
    34
 * patents. This notice and attribution to Taligent may not be removed.
jtulach@1334
    35
 *   Taligent is a registered trademark of Taligent, Inc.
jtulach@1334
    36
 *
jtulach@1334
    37
 */
jtulach@1334
    38
jtulach@1334
    39
package java.text;
jtulach@1334
    40
jtulach@1334
    41
import java.io.IOException;
jtulach@1334
    42
import java.io.ObjectInputStream;
jtulach@1334
    43
import java.io.Serializable;
jtulach@1334
    44
import java.util.Currency;
jtulach@1334
    45
import java.util.Locale;
jtulach@1334
    46
import java.util.ResourceBundle;
jtulach@1334
    47
import java.util.concurrent.ConcurrentHashMap;
jtulach@1334
    48
jtulach@1334
    49
/**
jtulach@1334
    50
 * This class represents the set of symbols (such as the decimal separator,
jtulach@1334
    51
 * the grouping separator, and so on) needed by <code>DecimalFormat</code>
jtulach@1334
    52
 * to format numbers. <code>DecimalFormat</code> creates for itself an instance of
jtulach@1334
    53
 * <code>DecimalFormatSymbols</code> from its locale data.  If you need to change any
jtulach@1334
    54
 * of these symbols, you can get the <code>DecimalFormatSymbols</code> object from
jtulach@1334
    55
 * your <code>DecimalFormat</code> and modify it.
jtulach@1334
    56
 *
jtulach@1334
    57
 * @see          java.util.Locale
jtulach@1334
    58
 * @see          DecimalFormat
jtulach@1334
    59
 * @author       Mark Davis
jtulach@1334
    60
 * @author       Alan Liu
jtulach@1334
    61
 */
jtulach@1334
    62
jtulach@1334
    63
public class DecimalFormatSymbols implements Cloneable, Serializable {
jtulach@1334
    64
jtulach@1334
    65
    /**
jtulach@1334
    66
     * Create a DecimalFormatSymbols object for the default locale.
jtulach@1334
    67
     * This constructor can only construct instances for the locales
jtulach@1334
    68
     * supported by the Java runtime environment, not for those
jtulach@1334
    69
     * supported by installed
jtulach@1334
    70
     * {@link java.text.spi.DecimalFormatSymbolsProvider DecimalFormatSymbolsProvider}
jtulach@1334
    71
     * implementations. For full locale coverage, use the
jtulach@1334
    72
     * {@link #getInstance(Locale) getInstance} method.
jtulach@1334
    73
     */
jtulach@1334
    74
    public DecimalFormatSymbols() {
jtulach@1334
    75
        initialize( Locale.getDefault(Locale.Category.FORMAT) );
jtulach@1334
    76
    }
jtulach@1334
    77
jtulach@1334
    78
    /**
jtulach@1334
    79
     * Create a DecimalFormatSymbols object for the given locale.
jtulach@1334
    80
     * This constructor can only construct instances for the locales
jtulach@1334
    81
     * supported by the Java runtime environment, not for those
jtulach@1334
    82
     * supported by installed
jtulach@1334
    83
     * {@link java.text.spi.DecimalFormatSymbolsProvider DecimalFormatSymbolsProvider}
jtulach@1334
    84
     * implementations. For full locale coverage, use the
jtulach@1334
    85
     * {@link #getInstance(Locale) getInstance} method.
jtulach@1334
    86
     *
jtulach@1334
    87
     * @exception NullPointerException if <code>locale</code> is null
jtulach@1334
    88
     */
jtulach@1334
    89
    public DecimalFormatSymbols( Locale locale ) {
jtulach@1334
    90
        initialize( locale );
jtulach@1334
    91
    }
jtulach@1334
    92
jtulach@1334
    93
    /**
jtulach@1334
    94
     * Returns an array of all locales for which the
jtulach@1334
    95
     * <code>getInstance</code> methods of this class can return
jtulach@1334
    96
     * localized instances.
jtulach@1334
    97
     * The returned array represents the union of locales supported by the Java
jtulach@1334
    98
     * runtime and by installed
jtulach@1334
    99
     * {@link java.text.spi.DecimalFormatSymbolsProvider DecimalFormatSymbolsProvider}
jtulach@1334
   100
     * implementations.  It must contain at least a <code>Locale</code>
jtulach@1334
   101
     * instance equal to {@link java.util.Locale#US Locale.US}.
jtulach@1334
   102
     *
jtulach@1334
   103
     * @return An array of locales for which localized
jtulach@1334
   104
     *         <code>DecimalFormatSymbols</code> instances are available.
jtulach@1334
   105
     * @since 1.6
jtulach@1334
   106
     */
jtulach@1334
   107
    public static Locale[] getAvailableLocales() {
jaroslav@1339
   108
        return new Locale[] { Locale.US };
jaroslav@1339
   109
//        LocaleServiceProviderPool pool =
jaroslav@1339
   110
//            LocaleServiceProviderPool.getPool(DecimalFormatSymbolsProvider.class);
jaroslav@1339
   111
//        return pool.getAvailableLocales();
jtulach@1334
   112
    }
jtulach@1334
   113
jtulach@1334
   114
    /**
jtulach@1334
   115
     * Gets the <code>DecimalFormatSymbols</code> instance for the default
jtulach@1334
   116
     * locale.  This method provides access to <code>DecimalFormatSymbols</code>
jtulach@1334
   117
     * instances for locales supported by the Java runtime itself as well
jtulach@1334
   118
     * as for those supported by installed
jtulach@1334
   119
     * {@link java.text.spi.DecimalFormatSymbolsProvider
jtulach@1334
   120
     * DecimalFormatSymbolsProvider} implementations.
jtulach@1334
   121
     * @return a <code>DecimalFormatSymbols</code> instance.
jtulach@1334
   122
     * @since 1.6
jtulach@1334
   123
     */
jtulach@1334
   124
    public static final DecimalFormatSymbols getInstance() {
jtulach@1334
   125
        return getInstance(Locale.getDefault(Locale.Category.FORMAT));
jtulach@1334
   126
    }
jtulach@1334
   127
jtulach@1334
   128
    /**
jtulach@1334
   129
     * Gets the <code>DecimalFormatSymbols</code> instance for the specified
jtulach@1334
   130
     * locale.  This method provides access to <code>DecimalFormatSymbols</code>
jtulach@1334
   131
     * instances for locales supported by the Java runtime itself as well
jtulach@1334
   132
     * as for those supported by installed
jtulach@1334
   133
     * {@link java.text.spi.DecimalFormatSymbolsProvider
jtulach@1334
   134
     * DecimalFormatSymbolsProvider} implementations.
jtulach@1334
   135
     * @param locale the desired locale.
jtulach@1334
   136
     * @return a <code>DecimalFormatSymbols</code> instance.
jtulach@1334
   137
     * @exception NullPointerException if <code>locale</code> is null
jtulach@1334
   138
     * @since 1.6
jtulach@1334
   139
     */
jtulach@1334
   140
    public static final DecimalFormatSymbols getInstance(Locale locale) {
jaroslav@1339
   141
/*
jtulach@1334
   142
        // Check whether a provider can provide an implementation that's closer
jtulach@1334
   143
        // to the requested locale than what the Java runtime itself can provide.
jtulach@1334
   144
        LocaleServiceProviderPool pool =
jtulach@1334
   145
            LocaleServiceProviderPool.getPool(DecimalFormatSymbolsProvider.class);
jtulach@1334
   146
        if (pool.hasProviders()) {
jtulach@1334
   147
            DecimalFormatSymbols providersInstance = pool.getLocalizedObject(
jtulach@1334
   148
                                DecimalFormatSymbolsGetter.INSTANCE, locale);
jtulach@1334
   149
            if (providersInstance != null) {
jtulach@1334
   150
                return providersInstance;
jtulach@1334
   151
            }
jtulach@1334
   152
        }
jaroslav@1339
   153
*/
jtulach@1334
   154
        return new DecimalFormatSymbols(locale);
jtulach@1334
   155
    }
jtulach@1334
   156
jtulach@1334
   157
    /**
jtulach@1334
   158
     * Gets the character used for zero. Different for Arabic, etc.
jtulach@1334
   159
     */
jtulach@1334
   160
    public char getZeroDigit() {
jtulach@1334
   161
        return zeroDigit;
jtulach@1334
   162
    }
jtulach@1334
   163
jtulach@1334
   164
    /**
jtulach@1334
   165
     * Sets the character used for zero. Different for Arabic, etc.
jtulach@1334
   166
     */
jtulach@1334
   167
    public void setZeroDigit(char zeroDigit) {
jtulach@1334
   168
        this.zeroDigit = zeroDigit;
jtulach@1334
   169
    }
jtulach@1334
   170
jtulach@1334
   171
    /**
jtulach@1334
   172
     * Gets the character used for thousands separator. Different for French, etc.
jtulach@1334
   173
     */
jtulach@1334
   174
    public char getGroupingSeparator() {
jtulach@1334
   175
        return groupingSeparator;
jtulach@1334
   176
    }
jtulach@1334
   177
jtulach@1334
   178
    /**
jtulach@1334
   179
     * Sets the character used for thousands separator. Different for French, etc.
jtulach@1334
   180
     */
jtulach@1334
   181
    public void setGroupingSeparator(char groupingSeparator) {
jtulach@1334
   182
        this.groupingSeparator = groupingSeparator;
jtulach@1334
   183
    }
jtulach@1334
   184
jtulach@1334
   185
    /**
jtulach@1334
   186
     * Gets the character used for decimal sign. Different for French, etc.
jtulach@1334
   187
     */
jtulach@1334
   188
    public char getDecimalSeparator() {
jtulach@1334
   189
        return decimalSeparator;
jtulach@1334
   190
    }
jtulach@1334
   191
jtulach@1334
   192
    /**
jtulach@1334
   193
     * Sets the character used for decimal sign. Different for French, etc.
jtulach@1334
   194
     */
jtulach@1334
   195
    public void setDecimalSeparator(char decimalSeparator) {
jtulach@1334
   196
        this.decimalSeparator = decimalSeparator;
jtulach@1334
   197
    }
jtulach@1334
   198
jtulach@1334
   199
    /**
jtulach@1334
   200
     * Gets the character used for per mille sign. Different for Arabic, etc.
jtulach@1334
   201
     */
jtulach@1334
   202
    public char getPerMill() {
jtulach@1334
   203
        return perMill;
jtulach@1334
   204
    }
jtulach@1334
   205
jtulach@1334
   206
    /**
jtulach@1334
   207
     * Sets the character used for per mille sign. Different for Arabic, etc.
jtulach@1334
   208
     */
jtulach@1334
   209
    public void setPerMill(char perMill) {
jtulach@1334
   210
        this.perMill = perMill;
jtulach@1334
   211
    }
jtulach@1334
   212
jtulach@1334
   213
    /**
jtulach@1334
   214
     * Gets the character used for percent sign. Different for Arabic, etc.
jtulach@1334
   215
     */
jtulach@1334
   216
    public char getPercent() {
jtulach@1334
   217
        return percent;
jtulach@1334
   218
    }
jtulach@1334
   219
jtulach@1334
   220
    /**
jtulach@1334
   221
     * Sets the character used for percent sign. Different for Arabic, etc.
jtulach@1334
   222
     */
jtulach@1334
   223
    public void setPercent(char percent) {
jtulach@1334
   224
        this.percent = percent;
jtulach@1334
   225
    }
jtulach@1334
   226
jtulach@1334
   227
    /**
jtulach@1334
   228
     * Gets the character used for a digit in a pattern.
jtulach@1334
   229
     */
jtulach@1334
   230
    public char getDigit() {
jtulach@1334
   231
        return digit;
jtulach@1334
   232
    }
jtulach@1334
   233
jtulach@1334
   234
    /**
jtulach@1334
   235
     * Sets the character used for a digit in a pattern.
jtulach@1334
   236
     */
jtulach@1334
   237
    public void setDigit(char digit) {
jtulach@1334
   238
        this.digit = digit;
jtulach@1334
   239
    }
jtulach@1334
   240
jtulach@1334
   241
    /**
jtulach@1334
   242
     * Gets the character used to separate positive and negative subpatterns
jtulach@1334
   243
     * in a pattern.
jtulach@1334
   244
     */
jtulach@1334
   245
    public char getPatternSeparator() {
jtulach@1334
   246
        return patternSeparator;
jtulach@1334
   247
    }
jtulach@1334
   248
jtulach@1334
   249
    /**
jtulach@1334
   250
     * Sets the character used to separate positive and negative subpatterns
jtulach@1334
   251
     * in a pattern.
jtulach@1334
   252
     */
jtulach@1334
   253
    public void setPatternSeparator(char patternSeparator) {
jtulach@1334
   254
        this.patternSeparator = patternSeparator;
jtulach@1334
   255
    }
jtulach@1334
   256
jtulach@1334
   257
    /**
jtulach@1334
   258
     * Gets the string used to represent infinity. Almost always left
jtulach@1334
   259
     * unchanged.
jtulach@1334
   260
     */
jtulach@1334
   261
    public String getInfinity() {
jtulach@1334
   262
        return infinity;
jtulach@1334
   263
    }
jtulach@1334
   264
jtulach@1334
   265
    /**
jtulach@1334
   266
     * Sets the string used to represent infinity. Almost always left
jtulach@1334
   267
     * unchanged.
jtulach@1334
   268
     */
jtulach@1334
   269
    public void setInfinity(String infinity) {
jtulach@1334
   270
        this.infinity = infinity;
jtulach@1334
   271
    }
jtulach@1334
   272
jtulach@1334
   273
    /**
jtulach@1334
   274
     * Gets the string used to represent "not a number". Almost always left
jtulach@1334
   275
     * unchanged.
jtulach@1334
   276
     */
jtulach@1334
   277
    public String getNaN() {
jtulach@1334
   278
        return NaN;
jtulach@1334
   279
    }
jtulach@1334
   280
jtulach@1334
   281
    /**
jtulach@1334
   282
     * Sets the string used to represent "not a number". Almost always left
jtulach@1334
   283
     * unchanged.
jtulach@1334
   284
     */
jtulach@1334
   285
    public void setNaN(String NaN) {
jtulach@1334
   286
        this.NaN = NaN;
jtulach@1334
   287
    }
jtulach@1334
   288
jtulach@1334
   289
    /**
jtulach@1334
   290
     * Gets the character used to represent minus sign. If no explicit
jtulach@1334
   291
     * negative format is specified, one is formed by prefixing
jtulach@1334
   292
     * minusSign to the positive format.
jtulach@1334
   293
     */
jtulach@1334
   294
    public char getMinusSign() {
jtulach@1334
   295
        return minusSign;
jtulach@1334
   296
    }
jtulach@1334
   297
jtulach@1334
   298
    /**
jtulach@1334
   299
     * Sets the character used to represent minus sign. If no explicit
jtulach@1334
   300
     * negative format is specified, one is formed by prefixing
jtulach@1334
   301
     * minusSign to the positive format.
jtulach@1334
   302
     */
jtulach@1334
   303
    public void setMinusSign(char minusSign) {
jtulach@1334
   304
        this.minusSign = minusSign;
jtulach@1334
   305
    }
jtulach@1334
   306
jtulach@1334
   307
    /**
jtulach@1334
   308
     * Returns the currency symbol for the currency of these
jtulach@1334
   309
     * DecimalFormatSymbols in their locale.
jtulach@1334
   310
     * @since 1.2
jtulach@1334
   311
     */
jtulach@1334
   312
    public String getCurrencySymbol()
jtulach@1334
   313
    {
jtulach@1334
   314
        return currencySymbol;
jtulach@1334
   315
    }
jtulach@1334
   316
jtulach@1334
   317
    /**
jtulach@1334
   318
     * Sets the currency symbol for the currency of these
jtulach@1334
   319
     * DecimalFormatSymbols in their locale.
jtulach@1334
   320
     * @since 1.2
jtulach@1334
   321
     */
jtulach@1334
   322
    public void setCurrencySymbol(String currency)
jtulach@1334
   323
    {
jtulach@1334
   324
        currencySymbol = currency;
jtulach@1334
   325
    }
jtulach@1334
   326
jtulach@1334
   327
    /**
jtulach@1334
   328
     * Returns the ISO 4217 currency code of the currency of these
jtulach@1334
   329
     * DecimalFormatSymbols.
jtulach@1334
   330
     * @since 1.2
jtulach@1334
   331
     */
jtulach@1334
   332
    public String getInternationalCurrencySymbol()
jtulach@1334
   333
    {
jtulach@1334
   334
        return intlCurrencySymbol;
jtulach@1334
   335
    }
jtulach@1334
   336
jtulach@1334
   337
    /**
jtulach@1334
   338
     * Sets the ISO 4217 currency code of the currency of these
jtulach@1334
   339
     * DecimalFormatSymbols.
jtulach@1334
   340
     * If the currency code is valid (as defined by
jtulach@1334
   341
     * {@link java.util.Currency#getInstance(java.lang.String) Currency.getInstance}),
jtulach@1334
   342
     * this also sets the currency attribute to the corresponding Currency
jtulach@1334
   343
     * instance and the currency symbol attribute to the currency's symbol
jtulach@1334
   344
     * in the DecimalFormatSymbols' locale. If the currency code is not valid,
jtulach@1334
   345
     * then the currency attribute is set to null and the currency symbol
jtulach@1334
   346
     * attribute is not modified.
jtulach@1334
   347
     *
jtulach@1334
   348
     * @see #setCurrency
jtulach@1334
   349
     * @see #setCurrencySymbol
jtulach@1334
   350
     * @since 1.2
jtulach@1334
   351
     */
jtulach@1334
   352
    public void setInternationalCurrencySymbol(String currencyCode)
jtulach@1334
   353
    {
jtulach@1334
   354
        intlCurrencySymbol = currencyCode;
jtulach@1334
   355
        currency = null;
jtulach@1334
   356
        if (currencyCode != null) {
jtulach@1334
   357
            try {
jtulach@1334
   358
                currency = Currency.getInstance(currencyCode);
jtulach@1334
   359
                currencySymbol = currency.getSymbol();
jtulach@1334
   360
            } catch (IllegalArgumentException e) {
jtulach@1334
   361
            }
jtulach@1334
   362
        }
jtulach@1334
   363
    }
jtulach@1334
   364
jtulach@1334
   365
    /**
jtulach@1334
   366
     * Gets the currency of these DecimalFormatSymbols. May be null if the
jtulach@1334
   367
     * currency symbol attribute was previously set to a value that's not
jtulach@1334
   368
     * a valid ISO 4217 currency code.
jtulach@1334
   369
     *
jtulach@1334
   370
     * @return the currency used, or null
jtulach@1334
   371
     * @since 1.4
jtulach@1334
   372
     */
jtulach@1334
   373
    public Currency getCurrency() {
jtulach@1334
   374
        return currency;
jtulach@1334
   375
    }
jtulach@1334
   376
jtulach@1334
   377
    /**
jtulach@1334
   378
     * Sets the currency of these DecimalFormatSymbols.
jtulach@1334
   379
     * This also sets the currency symbol attribute to the currency's symbol
jtulach@1334
   380
     * in the DecimalFormatSymbols' locale, and the international currency
jtulach@1334
   381
     * symbol attribute to the currency's ISO 4217 currency code.
jtulach@1334
   382
     *
jtulach@1334
   383
     * @param currency the new currency to be used
jtulach@1334
   384
     * @exception NullPointerException if <code>currency</code> is null
jtulach@1334
   385
     * @since 1.4
jtulach@1334
   386
     * @see #setCurrencySymbol
jtulach@1334
   387
     * @see #setInternationalCurrencySymbol
jtulach@1334
   388
     */
jtulach@1334
   389
    public void setCurrency(Currency currency) {
jtulach@1334
   390
        if (currency == null) {
jtulach@1334
   391
            throw new NullPointerException();
jtulach@1334
   392
        }
jtulach@1334
   393
        this.currency = currency;
jtulach@1334
   394
        intlCurrencySymbol = currency.getCurrencyCode();
jtulach@1334
   395
        currencySymbol = currency.getSymbol(locale);
jtulach@1334
   396
    }
jtulach@1334
   397
jtulach@1334
   398
jtulach@1334
   399
    /**
jtulach@1334
   400
     * Returns the monetary decimal separator.
jtulach@1334
   401
     * @since 1.2
jtulach@1334
   402
     */
jtulach@1334
   403
    public char getMonetaryDecimalSeparator()
jtulach@1334
   404
    {
jtulach@1334
   405
        return monetarySeparator;
jtulach@1334
   406
    }
jtulach@1334
   407
jtulach@1334
   408
    /**
jtulach@1334
   409
     * Sets the monetary decimal separator.
jtulach@1334
   410
     * @since 1.2
jtulach@1334
   411
     */
jtulach@1334
   412
    public void setMonetaryDecimalSeparator(char sep)
jtulach@1334
   413
    {
jtulach@1334
   414
        monetarySeparator = sep;
jtulach@1334
   415
    }
jtulach@1334
   416
jtulach@1334
   417
    //------------------------------------------------------------
jtulach@1334
   418
    // BEGIN   Package Private methods ... to be made public later
jtulach@1334
   419
    //------------------------------------------------------------
jtulach@1334
   420
jtulach@1334
   421
    /**
jtulach@1334
   422
     * Returns the character used to separate the mantissa from the exponent.
jtulach@1334
   423
     */
jtulach@1334
   424
    char getExponentialSymbol()
jtulach@1334
   425
    {
jtulach@1334
   426
        return exponential;
jtulach@1334
   427
    }
jtulach@1334
   428
  /**
jtulach@1334
   429
   * Returns the string used to separate the mantissa from the exponent.
jtulach@1334
   430
   * Examples: "x10^" for 1.23x10^4, "E" for 1.23E4.
jtulach@1334
   431
   *
jtulach@1334
   432
   * @return the exponent separator string
jtulach@1334
   433
   * @see #setExponentSeparator(java.lang.String)
jtulach@1334
   434
   * @since 1.6
jtulach@1334
   435
   */
jtulach@1334
   436
    public String getExponentSeparator()
jtulach@1334
   437
    {
jtulach@1334
   438
        return exponentialSeparator;
jtulach@1334
   439
    }
jtulach@1334
   440
jtulach@1334
   441
    /**
jtulach@1334
   442
     * Sets the character used to separate the mantissa from the exponent.
jtulach@1334
   443
     */
jtulach@1334
   444
    void setExponentialSymbol(char exp)
jtulach@1334
   445
    {
jtulach@1334
   446
        exponential = exp;
jtulach@1334
   447
    }
jtulach@1334
   448
jtulach@1334
   449
  /**
jtulach@1334
   450
   * Sets the string used to separate the mantissa from the exponent.
jtulach@1334
   451
   * Examples: "x10^" for 1.23x10^4, "E" for 1.23E4.
jtulach@1334
   452
   *
jtulach@1334
   453
   * @param exp the exponent separator string
jtulach@1334
   454
   * @exception NullPointerException if <code>exp</code> is null
jtulach@1334
   455
   * @see #getExponentSeparator()
jtulach@1334
   456
   * @since 1.6
jtulach@1334
   457
   */
jtulach@1334
   458
    public void setExponentSeparator(String exp)
jtulach@1334
   459
    {
jtulach@1334
   460
        if (exp == null) {
jtulach@1334
   461
            throw new NullPointerException();
jtulach@1334
   462
        }
jtulach@1334
   463
        exponentialSeparator = exp;
jtulach@1334
   464
     }
jtulach@1334
   465
jtulach@1334
   466
jtulach@1334
   467
    //------------------------------------------------------------
jtulach@1334
   468
    // END     Package Private methods ... to be made public later
jtulach@1334
   469
    //------------------------------------------------------------
jtulach@1334
   470
jtulach@1334
   471
    /**
jtulach@1334
   472
     * Standard override.
jtulach@1334
   473
     */
jtulach@1334
   474
    public Object clone() {
jtulach@1334
   475
        try {
jtulach@1334
   476
            return (DecimalFormatSymbols)super.clone();
jtulach@1334
   477
            // other fields are bit-copied
jtulach@1334
   478
        } catch (CloneNotSupportedException e) {
jtulach@1334
   479
            throw new InternalError();
jtulach@1334
   480
        }
jtulach@1334
   481
    }
jtulach@1334
   482
jtulach@1334
   483
    /**
jtulach@1334
   484
     * Override equals.
jtulach@1334
   485
     */
jtulach@1334
   486
    public boolean equals(Object obj) {
jtulach@1334
   487
        if (obj == null) return false;
jtulach@1334
   488
        if (this == obj) return true;
jtulach@1334
   489
        if (getClass() != obj.getClass()) return false;
jtulach@1334
   490
        DecimalFormatSymbols other = (DecimalFormatSymbols) obj;
jtulach@1334
   491
        return (zeroDigit == other.zeroDigit &&
jtulach@1334
   492
        groupingSeparator == other.groupingSeparator &&
jtulach@1334
   493
        decimalSeparator == other.decimalSeparator &&
jtulach@1334
   494
        percent == other.percent &&
jtulach@1334
   495
        perMill == other.perMill &&
jtulach@1334
   496
        digit == other.digit &&
jtulach@1334
   497
        minusSign == other.minusSign &&
jtulach@1334
   498
        patternSeparator == other.patternSeparator &&
jtulach@1334
   499
        infinity.equals(other.infinity) &&
jtulach@1334
   500
        NaN.equals(other.NaN) &&
jtulach@1334
   501
        currencySymbol.equals(other.currencySymbol) &&
jtulach@1334
   502
        intlCurrencySymbol.equals(other.intlCurrencySymbol) &&
jtulach@1334
   503
        currency == other.currency &&
jtulach@1334
   504
        monetarySeparator == other.monetarySeparator &&
jtulach@1334
   505
        exponentialSeparator.equals(other.exponentialSeparator) &&
jtulach@1334
   506
        locale.equals(other.locale));
jtulach@1334
   507
    }
jtulach@1334
   508
jtulach@1334
   509
    /**
jtulach@1334
   510
     * Override hashCode.
jtulach@1334
   511
     */
jtulach@1334
   512
    public int hashCode() {
jtulach@1334
   513
            int result = zeroDigit;
jtulach@1334
   514
            result = result * 37 + groupingSeparator;
jtulach@1334
   515
            result = result * 37 + decimalSeparator;
jtulach@1334
   516
            return result;
jtulach@1334
   517
    }
jtulach@1334
   518
jtulach@1334
   519
    /**
jtulach@1334
   520
     * Initializes the symbols from the FormatData resource bundle.
jtulach@1334
   521
     */
jtulach@1334
   522
    private void initialize( Locale locale ) {
jtulach@1334
   523
        this.locale = locale;
jtulach@1334
   524
jtulach@1334
   525
        // get resource bundle data - try the cache first
jtulach@1334
   526
        boolean needCacheUpdate = false;
jtulach@1334
   527
        Object[] data = cachedLocaleData.get(locale);
jtulach@1334
   528
        if (data == null) {  /* cache miss */
jtulach@1334
   529
            // When numbering system is thai (Locale's extension contains u-nu-thai),
jtulach@1334
   530
            // we read the data from th_TH_TH.
jtulach@1334
   531
            Locale lookupLocale = locale;
jtulach@1334
   532
            String numberType = locale.getUnicodeLocaleType("nu");
jtulach@1334
   533
            if (numberType != null && numberType.equals("thai")) {
jtulach@1334
   534
                lookupLocale = new Locale("th", "TH", "TH");
jtulach@1334
   535
            }
jtulach@1334
   536
            data = new Object[3];
jaroslav@1339
   537
//            ResourceBundle rb = LocaleData.getNumberFormatData(lookupLocale);
jaroslav@1339
   538
//            data[0] = rb.getStringArray("NumberElements");
jtulach@1334
   539
            needCacheUpdate = true;
jtulach@1334
   540
        }
jtulach@1334
   541
jtulach@1334
   542
        String[] numberElements = (String[]) data[0];
jtulach@1334
   543
jtulach@1334
   544
        decimalSeparator = numberElements[0].charAt(0);
jtulach@1334
   545
        groupingSeparator = numberElements[1].charAt(0);
jtulach@1334
   546
        patternSeparator = numberElements[2].charAt(0);
jtulach@1334
   547
        percent = numberElements[3].charAt(0);
jtulach@1334
   548
        zeroDigit = numberElements[4].charAt(0); //different for Arabic,etc.
jtulach@1334
   549
        digit = numberElements[5].charAt(0);
jtulach@1334
   550
        minusSign = numberElements[6].charAt(0);
jtulach@1334
   551
        exponential = numberElements[7].charAt(0);
jtulach@1334
   552
        exponentialSeparator = numberElements[7]; //string representation new since 1.6
jtulach@1334
   553
        perMill = numberElements[8].charAt(0);
jtulach@1334
   554
        infinity  = numberElements[9];
jtulach@1334
   555
        NaN = numberElements[10];
jtulach@1334
   556
jtulach@1334
   557
        // Try to obtain the currency used in the locale's country.
jtulach@1334
   558
        // Check for empty country string separately because it's a valid
jtulach@1334
   559
        // country ID for Locale (and used for the C locale), but not a valid
jtulach@1334
   560
        // ISO 3166 country code, and exceptions are expensive.
jtulach@1334
   561
        if (!"".equals(locale.getCountry())) {
jtulach@1334
   562
            try {
jtulach@1334
   563
                currency = Currency.getInstance(locale);
jtulach@1334
   564
            } catch (IllegalArgumentException e) {
jtulach@1334
   565
                // use default values below for compatibility
jtulach@1334
   566
            }
jtulach@1334
   567
        }
jtulach@1334
   568
        if (currency != null) {
jtulach@1334
   569
            intlCurrencySymbol = currency.getCurrencyCode();
jtulach@1334
   570
            if (data[1] != null && data[1] == intlCurrencySymbol) {
jtulach@1334
   571
                currencySymbol = (String) data[2];
jtulach@1334
   572
            } else {
jtulach@1334
   573
                currencySymbol = currency.getSymbol(locale);
jtulach@1334
   574
                data[1] = intlCurrencySymbol;
jtulach@1334
   575
                data[2] = currencySymbol;
jtulach@1334
   576
                needCacheUpdate = true;
jtulach@1334
   577
            }
jtulach@1334
   578
        } else {
jtulach@1334
   579
            // default values
jtulach@1334
   580
            intlCurrencySymbol = "XXX";
jtulach@1334
   581
            try {
jtulach@1334
   582
                currency = Currency.getInstance(intlCurrencySymbol);
jtulach@1334
   583
            } catch (IllegalArgumentException e) {
jtulach@1334
   584
            }
jtulach@1334
   585
            currencySymbol = "\u00A4";
jtulach@1334
   586
        }
jtulach@1334
   587
        // Currently the monetary decimal separator is the same as the
jtulach@1334
   588
        // standard decimal separator for all locales that we support.
jtulach@1334
   589
        // If that changes, add a new entry to NumberElements.
jtulach@1334
   590
        monetarySeparator = decimalSeparator;
jtulach@1334
   591
jtulach@1334
   592
        if (needCacheUpdate) {
jtulach@1334
   593
            cachedLocaleData.putIfAbsent(locale, data);
jtulach@1334
   594
        }
jtulach@1334
   595
    }
jtulach@1334
   596
jtulach@1334
   597
    /**
jtulach@1334
   598
     * Reads the default serializable fields, provides default values for objects
jtulach@1334
   599
     * in older serial versions, and initializes non-serializable fields.
jtulach@1334
   600
     * If <code>serialVersionOnStream</code>
jtulach@1334
   601
     * is less than 1, initializes <code>monetarySeparator</code> to be
jtulach@1334
   602
     * the same as <code>decimalSeparator</code> and <code>exponential</code>
jtulach@1334
   603
     * to be 'E'.
jtulach@1334
   604
     * If <code>serialVersionOnStream</code> is less than 2,
jtulach@1334
   605
     * initializes <code>locale</code>to the root locale, and initializes
jtulach@1334
   606
     * If <code>serialVersionOnStream</code> is less than 3, it initializes
jtulach@1334
   607
     * <code>exponentialSeparator</code> using <code>exponential</code>.
jtulach@1334
   608
     * Sets <code>serialVersionOnStream</code> back to the maximum allowed value so that
jtulach@1334
   609
     * default serialization will work properly if this object is streamed out again.
jtulach@1334
   610
     * Initializes the currency from the intlCurrencySymbol field.
jtulach@1334
   611
     *
jtulach@1334
   612
     * @since JDK 1.1.6
jtulach@1334
   613
     */
jtulach@1334
   614
    private void readObject(ObjectInputStream stream)
jtulach@1334
   615
            throws IOException, ClassNotFoundException {
jtulach@1334
   616
        stream.defaultReadObject();
jtulach@1334
   617
        if (serialVersionOnStream < 1) {
jtulach@1334
   618
            // Didn't have monetarySeparator or exponential field;
jtulach@1334
   619
            // use defaults.
jtulach@1334
   620
            monetarySeparator = decimalSeparator;
jtulach@1334
   621
            exponential       = 'E';
jtulach@1334
   622
        }
jtulach@1334
   623
        if (serialVersionOnStream < 2) {
jtulach@1334
   624
            // didn't have locale; use root locale
jtulach@1334
   625
            locale = Locale.ROOT;
jtulach@1334
   626
        }
jtulach@1334
   627
        if (serialVersionOnStream < 3) {
jtulach@1334
   628
            // didn't have exponentialSeparator. Create one using exponential
jtulach@1334
   629
            exponentialSeparator = Character.toString(exponential);
jtulach@1334
   630
        }
jtulach@1334
   631
        serialVersionOnStream = currentSerialVersion;
jtulach@1334
   632
jtulach@1334
   633
        if (intlCurrencySymbol != null) {
jtulach@1334
   634
            try {
jtulach@1334
   635
                 currency = Currency.getInstance(intlCurrencySymbol);
jtulach@1334
   636
            } catch (IllegalArgumentException e) {
jtulach@1334
   637
            }
jtulach@1334
   638
        }
jtulach@1334
   639
    }
jtulach@1334
   640
jtulach@1334
   641
    /**
jtulach@1334
   642
     * Character used for zero.
jtulach@1334
   643
     *
jtulach@1334
   644
     * @serial
jtulach@1334
   645
     * @see #getZeroDigit
jtulach@1334
   646
     */
jtulach@1334
   647
    private  char    zeroDigit;
jtulach@1334
   648
jtulach@1334
   649
    /**
jtulach@1334
   650
     * Character used for thousands separator.
jtulach@1334
   651
     *
jtulach@1334
   652
     * @serial
jtulach@1334
   653
     * @see #getGroupingSeparator
jtulach@1334
   654
     */
jtulach@1334
   655
    private  char    groupingSeparator;
jtulach@1334
   656
jtulach@1334
   657
    /**
jtulach@1334
   658
     * Character used for decimal sign.
jtulach@1334
   659
     *
jtulach@1334
   660
     * @serial
jtulach@1334
   661
     * @see #getDecimalSeparator
jtulach@1334
   662
     */
jtulach@1334
   663
    private  char    decimalSeparator;
jtulach@1334
   664
jtulach@1334
   665
    /**
jtulach@1334
   666
     * Character used for per mille sign.
jtulach@1334
   667
     *
jtulach@1334
   668
     * @serial
jtulach@1334
   669
     * @see #getPerMill
jtulach@1334
   670
     */
jtulach@1334
   671
    private  char    perMill;
jtulach@1334
   672
jtulach@1334
   673
    /**
jtulach@1334
   674
     * Character used for percent sign.
jtulach@1334
   675
     * @serial
jtulach@1334
   676
     * @see #getPercent
jtulach@1334
   677
     */
jtulach@1334
   678
    private  char    percent;
jtulach@1334
   679
jtulach@1334
   680
    /**
jtulach@1334
   681
     * Character used for a digit in a pattern.
jtulach@1334
   682
     *
jtulach@1334
   683
     * @serial
jtulach@1334
   684
     * @see #getDigit
jtulach@1334
   685
     */
jtulach@1334
   686
    private  char    digit;
jtulach@1334
   687
jtulach@1334
   688
    /**
jtulach@1334
   689
     * Character used to separate positive and negative subpatterns
jtulach@1334
   690
     * in a pattern.
jtulach@1334
   691
     *
jtulach@1334
   692
     * @serial
jtulach@1334
   693
     * @see #getPatternSeparator
jtulach@1334
   694
     */
jtulach@1334
   695
    private  char    patternSeparator;
jtulach@1334
   696
jtulach@1334
   697
    /**
jtulach@1334
   698
     * String used to represent infinity.
jtulach@1334
   699
     * @serial
jtulach@1334
   700
     * @see #getInfinity
jtulach@1334
   701
     */
jtulach@1334
   702
    private  String  infinity;
jtulach@1334
   703
jtulach@1334
   704
    /**
jtulach@1334
   705
     * String used to represent "not a number".
jtulach@1334
   706
     * @serial
jtulach@1334
   707
     * @see #getNaN
jtulach@1334
   708
     */
jtulach@1334
   709
    private  String  NaN;
jtulach@1334
   710
jtulach@1334
   711
    /**
jtulach@1334
   712
     * Character used to represent minus sign.
jtulach@1334
   713
     * @serial
jtulach@1334
   714
     * @see #getMinusSign
jtulach@1334
   715
     */
jtulach@1334
   716
    private  char    minusSign;
jtulach@1334
   717
jtulach@1334
   718
    /**
jtulach@1334
   719
     * String denoting the local currency, e.g. "$".
jtulach@1334
   720
     * @serial
jtulach@1334
   721
     * @see #getCurrencySymbol
jtulach@1334
   722
     */
jtulach@1334
   723
    private  String  currencySymbol;
jtulach@1334
   724
jtulach@1334
   725
    /**
jtulach@1334
   726
     * ISO 4217 currency code denoting the local currency, e.g. "USD".
jtulach@1334
   727
     * @serial
jtulach@1334
   728
     * @see #getInternationalCurrencySymbol
jtulach@1334
   729
     */
jtulach@1334
   730
    private  String  intlCurrencySymbol;
jtulach@1334
   731
jtulach@1334
   732
    /**
jtulach@1334
   733
     * The decimal separator used when formatting currency values.
jtulach@1334
   734
     * @serial
jtulach@1334
   735
     * @since JDK 1.1.6
jtulach@1334
   736
     * @see #getMonetaryDecimalSeparator
jtulach@1334
   737
     */
jtulach@1334
   738
    private  char    monetarySeparator; // Field new in JDK 1.1.6
jtulach@1334
   739
jtulach@1334
   740
    /**
jtulach@1334
   741
     * The character used to distinguish the exponent in a number formatted
jtulach@1334
   742
     * in exponential notation, e.g. 'E' for a number such as "1.23E45".
jtulach@1334
   743
     * <p>
jtulach@1334
   744
     * Note that the public API provides no way to set this field,
jtulach@1334
   745
     * even though it is supported by the implementation and the stream format.
jtulach@1334
   746
     * The intent is that this will be added to the API in the future.
jtulach@1334
   747
     *
jtulach@1334
   748
     * @serial
jtulach@1334
   749
     * @since JDK 1.1.6
jtulach@1334
   750
     */
jtulach@1334
   751
    private  char    exponential;       // Field new in JDK 1.1.6
jtulach@1334
   752
jtulach@1334
   753
  /**
jtulach@1334
   754
   * The string used to separate the mantissa from the exponent.
jtulach@1334
   755
   * Examples: "x10^" for 1.23x10^4, "E" for 1.23E4.
jtulach@1334
   756
   * <p>
jtulach@1334
   757
   * If both <code>exponential</code> and <code>exponentialSeparator</code>
jtulach@1334
   758
   * exist, this <code>exponentialSeparator</code> has the precedence.
jtulach@1334
   759
   *
jtulach@1334
   760
   * @serial
jtulach@1334
   761
   * @since 1.6
jtulach@1334
   762
   */
jtulach@1334
   763
    private  String    exponentialSeparator;       // Field new in JDK 1.6
jtulach@1334
   764
jtulach@1334
   765
    /**
jtulach@1334
   766
     * The locale of these currency format symbols.
jtulach@1334
   767
     *
jtulach@1334
   768
     * @serial
jtulach@1334
   769
     * @since 1.4
jtulach@1334
   770
     */
jtulach@1334
   771
    private Locale locale;
jtulach@1334
   772
jtulach@1334
   773
    // currency; only the ISO code is serialized.
jtulach@1334
   774
    private transient Currency currency;
jtulach@1334
   775
jtulach@1334
   776
    // Proclaim JDK 1.1 FCS compatibility
jtulach@1334
   777
    static final long serialVersionUID = 5772796243397350300L;
jtulach@1334
   778
jtulach@1334
   779
    // The internal serial version which says which version was written
jtulach@1334
   780
    // - 0 (default) for version up to JDK 1.1.5
jtulach@1334
   781
    // - 1 for version from JDK 1.1.6, which includes two new fields:
jtulach@1334
   782
    //     monetarySeparator and exponential.
jtulach@1334
   783
    // - 2 for version from J2SE 1.4, which includes locale field.
jtulach@1334
   784
    // - 3 for version from J2SE 1.6, which includes exponentialSeparator field.
jtulach@1334
   785
    private static final int currentSerialVersion = 3;
jtulach@1334
   786
jtulach@1334
   787
    /**
jtulach@1334
   788
     * Describes the version of <code>DecimalFormatSymbols</code> present on the stream.
jtulach@1334
   789
     * Possible values are:
jtulach@1334
   790
     * <ul>
jtulach@1334
   791
     * <li><b>0</b> (or uninitialized): versions prior to JDK 1.1.6.
jtulach@1334
   792
     *
jtulach@1334
   793
     * <li><b>1</b>: Versions written by JDK 1.1.6 or later, which include
jtulach@1334
   794
     *      two new fields: <code>monetarySeparator</code> and <code>exponential</code>.
jtulach@1334
   795
     * <li><b>2</b>: Versions written by J2SE 1.4 or later, which include a
jtulach@1334
   796
     *      new <code>locale</code> field.
jtulach@1334
   797
     * <li><b>3</b>: Versions written by J2SE 1.6 or later, which include a
jtulach@1334
   798
     *      new <code>exponentialSeparator</code> field.
jtulach@1334
   799
     * </ul>
jtulach@1334
   800
     * When streaming out a <code>DecimalFormatSymbols</code>, the most recent format
jtulach@1334
   801
     * (corresponding to the highest allowable <code>serialVersionOnStream</code>)
jtulach@1334
   802
     * is always written.
jtulach@1334
   803
     *
jtulach@1334
   804
     * @serial
jtulach@1334
   805
     * @since JDK 1.1.6
jtulach@1334
   806
     */
jtulach@1334
   807
    private int serialVersionOnStream = currentSerialVersion;
jtulach@1334
   808
jtulach@1334
   809
    /**
jtulach@1334
   810
     * cache to hold the NumberElements and the Currency
jtulach@1334
   811
     * of a Locale.
jtulach@1334
   812
     */
jtulach@1334
   813
    private static final ConcurrentHashMap<Locale, Object[]> cachedLocaleData = new ConcurrentHashMap<Locale, Object[]>(3);
jtulach@1334
   814
jtulach@1334
   815
    /**
jtulach@1334
   816
     * Obtains a DecimalFormatSymbols instance from a DecimalFormatSymbolsProvider
jtulach@1334
   817
     * implementation.
jtulach@1334
   818
    private static class DecimalFormatSymbolsGetter
jtulach@1334
   819
        implements LocaleServiceProviderPool.LocalizedObjectGetter<DecimalFormatSymbolsProvider,
jtulach@1334
   820
                                                                   DecimalFormatSymbols> {
jtulach@1334
   821
        private static final DecimalFormatSymbolsGetter INSTANCE =
jtulach@1334
   822
            new DecimalFormatSymbolsGetter();
jtulach@1334
   823
jtulach@1334
   824
        public DecimalFormatSymbols getObject(
jtulach@1334
   825
                                DecimalFormatSymbolsProvider decimalFormatSymbolsProvider,
jtulach@1334
   826
                                Locale locale,
jtulach@1334
   827
                                String key,
jtulach@1334
   828
                                Object... params) {
jtulach@1334
   829
            assert params.length == 0;
jtulach@1334
   830
            return decimalFormatSymbolsProvider.getInstance(locale);
jtulach@1334
   831
        }
jtulach@1334
   832
    }
jaroslav@1339
   833
     */
jtulach@1334
   834
}