jdk/src/share/classes/java/text/NumberFormat.java
author dbhole
Thu, 24 May 2012 19:00:16 -0700
changeset 12848 da701d422d2c
parent 7668 d4a77089c587
child 13583 dc0017b1a452
permissions -rw-r--r--
7117230: clean up warnings in java.text Reviewed-by: jrose, smarks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 6489
diff changeset
     2
 * Copyright (c) 1996, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 *   The original version of this source code and documentation is copyrighted
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * materials are provided under terms of a License Agreement between Taligent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * and Sun. This technology is protected by multiple US and International
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * patents. This notice and attribution to Taligent may not be removed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 *   Taligent is a registered trademark of Taligent, Inc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
package java.text;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.io.InvalidObjectException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.io.ObjectOutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.math.BigInteger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.math.RoundingMode;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.text.spi.NumberFormatProvider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.util.Currency;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.util.Hashtable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.util.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.util.ResourceBundle;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.util.concurrent.atomic.AtomicInteger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import java.util.concurrent.atomic.AtomicLong;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import java.util.spi.LocaleServiceProvider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import sun.util.LocaleServiceProviderPool;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import sun.util.resources.LocaleData;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <code>NumberFormat</code> is the abstract base class for all number
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * formats. This class provides the interface for formatting and parsing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * numbers. <code>NumberFormat</code> also provides methods for determining
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * which locales have number formats, and what their names are.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <code>NumberFormat</code> helps you to format and parse numbers for any locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * Your code can be completely independent of the locale conventions for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * decimal points, thousands-separators, or even the particular decimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * digits used, or whether the number format is even decimal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * To format a number for the current Locale, use one of the factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * class methods:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *  myString = NumberFormat.getInstance().format(myNumber);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * If you are formatting multiple numbers, it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * more efficient to get the format and use it multiple times so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * the system doesn't have to fetch the information about the local
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * language and country conventions multiple times.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * NumberFormat nf = NumberFormat.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * for (int i = 0; i < myNumber.length; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *     output.println(nf.format(myNumber[i]) + "; ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * To format a number for a different Locale, specify it in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 * call to <code>getInstance</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * NumberFormat nf = NumberFormat.getInstance(Locale.FRENCH);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * You can also use a <code>NumberFormat</code> to parse numbers:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * <blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * myNumber = nf.parse(myString);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * Use <code>getInstance</code> or <code>getNumberInstance</code> to get the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 * normal number format. Use <code>getIntegerInstance</code> to get an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * integer number format. Use <code>getCurrencyInstance</code> to get the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 * currency number format. And use <code>getPercentInstance</code> to get a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * format for displaying percentages. With this format, a fraction like
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 * 0.53 is displayed as 53%.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * You can also control the display of numbers with such methods as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * <code>setMinimumFractionDigits</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * If you want even more control over the format or parsing,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * or want to give your users more control,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * you can try casting the <code>NumberFormat</code> you get from the factory methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * to a <code>DecimalFormat</code>. This will work for the vast majority
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * of locales; just remember to put it in a <code>try</code> block in case you
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * encounter an unusual one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * NumberFormat and DecimalFormat are designed such that some controls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * work for formatting and others work for parsing.  The following is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
 * the detailed description for each these control methods,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
 * setParseIntegerOnly : only affects parsing, e.g.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
 * if true,  "3456.78" -> 3456 (and leaves the parse position just after index 6)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
 * if false, "3456.78" -> 3456.78 (and leaves the parse position just after index 8)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 * This is independent of formatting.  If you want to not show a decimal point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * where there might be no digits after the decimal point, use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * setDecimalSeparatorAlwaysShown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * setDecimalSeparatorAlwaysShown : only affects formatting, and only where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * there might be no digits after the decimal point, such as with a pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * like "#,##0.##", e.g.,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
 * if true,  3456.00 -> "3,456."
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
 * if false, 3456.00 -> "3456"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * This is independent of parsing.  If you want parsing to stop at the decimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * point, use setParseIntegerOnly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * You can also use forms of the <code>parse</code> and <code>format</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * methods with <code>ParsePosition</code> and <code>FieldPosition</code> to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * allow you to:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
 * <li> progressively parse through pieces of a string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * <li> align the decimal point and other areas
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 * For example, you can align numbers in two ways:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
 * <li> If you are using a monospaced font with spacing for alignment,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
 *      you can pass the <code>FieldPosition</code> in your format call, with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 *      <code>field</code> = <code>INTEGER_FIELD</code>. On output,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 *      <code>getEndIndex</code> will be set to the offset between the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 *      last character of the integer and the decimal. Add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 *      (desiredSpaceCount - getEndIndex) spaces at the front of the string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * <li> If you are using proportional fonts,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 *      instead of padding with spaces, measure the width
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 *      of the string in pixels from the start to <code>getEndIndex</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
 *      Then move the pen by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
 *      (desiredPixelWidth - widthToAlignmentPoint) before drawing the text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
 *      It also works where there is no decimal, but possibly additional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 *      characters at the end, e.g., with parentheses in negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 *      numbers: "(12)" for -12.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 * <h4><a name="synchronization">Synchronization</a></h4>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 * Number formats are generally not synchronized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 * It is recommended to create separate format instances for each thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 * If multiple threads access a format concurrently, it must be synchronized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 * externally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 * @see          DecimalFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
 * @see          ChoiceFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 * @author       Mark Davis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 * @author       Helena Shih
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
public abstract class NumberFormat extends Format  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * Field constant used to construct a FieldPosition object. Signifies that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * the position of the integer part of a formatted number should be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @see java.text.FieldPosition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public static final int INTEGER_FIELD = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Field constant used to construct a FieldPosition object. Signifies that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * the position of the fraction part of a formatted number should be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @see java.text.FieldPosition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    public static final int FRACTION_FIELD = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * Sole constructor.  (For invocation by subclass constructors, typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * implicit.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    protected NumberFormat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * Formats a number and appends the resulting text to the given string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * The number can be of any subclass of {@link java.lang.Number}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * This implementation extracts the number's value using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * {@link java.lang.Number#longValue()} for all integral type values that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * can be converted to <code>long</code> without loss of information,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * including <code>BigInteger</code> values with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * {@link java.math.BigInteger#bitLength() bit length} of less than 64,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * and {@link java.lang.Number#doubleValue()} for all other types. It
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * then calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * {@link #format(long,java.lang.StringBuffer,java.text.FieldPosition)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * or {@link #format(double,java.lang.StringBuffer,java.text.FieldPosition)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * This may result in loss of magnitude information and precision for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * <code>BigInteger</code> and <code>BigDecimal</code> values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @param number     the number to format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * @param toAppendTo the <code>StringBuffer</code> to which the formatted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *                   text is to be appended
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @param pos        On input: an alignment field, if desired.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     *                   On output: the offsets of the alignment field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * @return           the value passed in as <code>toAppendTo</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @exception        IllegalArgumentException if <code>number</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *                   null or not an instance of <code>Number</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * @exception        NullPointerException if <code>toAppendTo</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *                   <code>pos</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @exception        ArithmeticException if rounding is needed with rounding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *                   mode being set to RoundingMode.UNNECESSARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @see              java.text.FieldPosition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public StringBuffer format(Object number,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
                               StringBuffer toAppendTo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                               FieldPosition pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        if (number instanceof Long || number instanceof Integer ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            number instanceof Short || number instanceof Byte ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            number instanceof AtomicInteger || number instanceof AtomicLong ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            (number instanceof BigInteger &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
             ((BigInteger)number).bitLength() < 64)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            return format(((Number)number).longValue(), toAppendTo, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        } else if (number instanceof Number) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            return format(((Number)number).doubleValue(), toAppendTo, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            throw new IllegalArgumentException("Cannot format given Object as a Number");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * Parses text from a string to produce a <code>Number</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * The method attempts to parse text starting at the index given by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * <code>pos</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * If parsing succeeds, then the index of <code>pos</code> is updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * to the index after the last character used (parsing does not necessarily
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * use all characters up to the end of the string), and the parsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * number is returned. The updated <code>pos</code> can be used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * indicate the starting point for the next call to this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * If an error occurs, then the index of <code>pos</code> is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     * changed, the error index of <code>pos</code> is set to the index of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     * the character where the error occurred, and null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * See the {@link #parse(String, ParsePosition)} method for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * on number parsing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @param source A <code>String</code>, part of which should be parsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     * @param pos A <code>ParsePosition</code> object with index and error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     *            index information as described above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * @return A <code>Number</code> parsed from the string. In case of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     *         error, returns null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * @exception NullPointerException if <code>pos</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    public final Object parseObject(String source, ParsePosition pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        return parse(source, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * Specialization of format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @exception        ArithmeticException if rounding is needed with rounding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *                   mode being set to RoundingMode.UNNECESSARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @see java.text.Format#format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public final String format(double number) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        return format(number, new StringBuffer(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                      DontCareFieldPosition.INSTANCE).toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * Specialization of format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * @exception        ArithmeticException if rounding is needed with rounding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     *                   mode being set to RoundingMode.UNNECESSARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @see java.text.Format#format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    public final String format(long number) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        return format(number, new StringBuffer(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                      DontCareFieldPosition.INSTANCE).toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * Specialization of format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * @exception        ArithmeticException if rounding is needed with rounding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *                   mode being set to RoundingMode.UNNECESSARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @see java.text.Format#format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    public abstract StringBuffer format(double number,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                                        StringBuffer toAppendTo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                                        FieldPosition pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * Specialization of format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @exception        ArithmeticException if rounding is needed with rounding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     *                   mode being set to RoundingMode.UNNECESSARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * @see java.text.Format#format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
    public abstract StringBuffer format(long number,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                                        StringBuffer toAppendTo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
                                        FieldPosition pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * Returns a Long if possible (e.g., within the range [Long.MIN_VALUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * Long.MAX_VALUE] and with no decimals), otherwise a Double.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * If IntegerOnly is set, will stop at a decimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * point (or equivalent; e.g., for rational numbers "1 2/3", will stop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * after the 1).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * Does not throw an exception; if no object can be parsed, index is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * unchanged!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * @see java.text.NumberFormat#isParseIntegerOnly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @see java.text.Format#parseObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    public abstract Number parse(String source, ParsePosition parsePosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * Parses text from the beginning of the given string to produce a number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * The method may not use the entire text of the given string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * See the {@link #parse(String, ParsePosition)} method for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * on number parsing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * @param source A <code>String</code> whose beginning should be parsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * @return A <code>Number</code> parsed from the string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * @exception ParseException if the beginning of the specified string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     *            cannot be parsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
    public Number parse(String source) throws ParseException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        ParsePosition parsePosition = new ParsePosition(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        Number result = parse(source, parsePosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
        if (parsePosition.index == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
            throw new ParseException("Unparseable number: \"" + source + "\"",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                                     parsePosition.errorIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     * Returns true if this format will parse numbers as integers only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
     * For example in the English locale, with ParseIntegerOnly true, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
     * string "1234." would be parsed as the integer value 1234 and parsing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * would stop at the "." character.  Of course, the exact format accepted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     * by the parse operation is locale dependant and determined by sub-classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * of NumberFormat.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public boolean isParseIntegerOnly() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        return parseIntegerOnly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * Sets whether or not numbers should be parsed as integers only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @see #isParseIntegerOnly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    public void setParseIntegerOnly(boolean value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        parseIntegerOnly = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    //============== Locale Stuff =====================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * Returns a general-purpose number format for the current default locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * This is the same as calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * {@link #getNumberInstance() getNumberInstance()}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    public final static NumberFormat getInstance() {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   384
        return getInstance(Locale.getDefault(Locale.Category.FORMAT), NUMBERSTYLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * Returns a general-purpose number format for the specified locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * This is the same as calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * {@link #getNumberInstance(java.util.Locale) getNumberInstance(inLocale)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    public static NumberFormat getInstance(Locale inLocale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
        return getInstance(inLocale, NUMBERSTYLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * Returns a general-purpose number format for the current default locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
    public final static NumberFormat getNumberInstance() {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   400
        return getInstance(Locale.getDefault(Locale.Category.FORMAT), NUMBERSTYLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * Returns a general-purpose number format for the specified locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    public static NumberFormat getNumberInstance(Locale inLocale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        return getInstance(inLocale, NUMBERSTYLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * Returns an integer number format for the current default locale. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * returned number format is configured to round floating point numbers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * to the nearest integer using half-even rounding (see {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * java.math.RoundingMode#HALF_EVEN RoundingMode.HALF_EVEN}) for formatting,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * and to parse only the integer part of an input string (see {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * #isParseIntegerOnly isParseIntegerOnly}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * @see #getRoundingMode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @return a number format for integer values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    public final static NumberFormat getIntegerInstance() {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   423
        return getInstance(Locale.getDefault(Locale.Category.FORMAT), INTEGERSTYLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * Returns an integer number format for the specified locale. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     * returned number format is configured to round floating point numbers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * to the nearest integer using half-even rounding (see {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * java.math.RoundingMode#HALF_EVEN RoundingMode.HALF_EVEN}) for formatting,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * and to parse only the integer part of an input string (see {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * #isParseIntegerOnly isParseIntegerOnly}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * @see #getRoundingMode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     * @return a number format for integer values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    public static NumberFormat getIntegerInstance(Locale inLocale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        return getInstance(inLocale, INTEGERSTYLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * Returns a currency format for the current default locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    public final static NumberFormat getCurrencyInstance() {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   446
        return getInstance(Locale.getDefault(Locale.Category.FORMAT), CURRENCYSTYLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * Returns a currency format for the specified locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    public static NumberFormat getCurrencyInstance(Locale inLocale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        return getInstance(inLocale, CURRENCYSTYLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * Returns a percentage format for the current default locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    public final static NumberFormat getPercentInstance() {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   460
        return getInstance(Locale.getDefault(Locale.Category.FORMAT), PERCENTSTYLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * Returns a percentage format for the specified locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    public static NumberFormat getPercentInstance(Locale inLocale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        return getInstance(inLocale, PERCENTSTYLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * Returns a scientific format for the current default locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    /*public*/ final static NumberFormat getScientificInstance() {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   474
        return getInstance(Locale.getDefault(Locale.Category.FORMAT), SCIENTIFICSTYLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * Returns a scientific format for the specified locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    /*public*/ static NumberFormat getScientificInstance(Locale inLocale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        return getInstance(inLocale, SCIENTIFICSTYLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * Returns an array of all locales for which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * <code>get*Instance</code> methods of this class can return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * localized instances.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * The returned array represents the union of locales supported by the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * runtime and by installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * {@link java.text.spi.NumberFormatProvider NumberFormatProvider} implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * It must contain at least a <code>Locale</code> instance equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * {@link java.util.Locale#US Locale.US}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * @return An array of locales for which localized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     *         <code>NumberFormat</code> instances are available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    public static Locale[] getAvailableLocales() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        LocaleServiceProviderPool pool =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            LocaleServiceProviderPool.getPool(NumberFormatProvider.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        return pool.getAvailableLocales();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * Overrides hashCode
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        return maximumIntegerDigits * 37 + maxFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        // just enough fields for a reasonable distribution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * Overrides equals
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        if (obj == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        if (this == obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        if (getClass() != obj.getClass()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        NumberFormat other = (NumberFormat) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        return (maximumIntegerDigits == other.maximumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            && minimumIntegerDigits == other.minimumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            && maximumFractionDigits == other.maximumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
            && minimumFractionDigits == other.minimumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            && groupingUsed == other.groupingUsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
            && parseIntegerOnly == other.parseIntegerOnly);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * Overrides Cloneable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        NumberFormat other = (NumberFormat) super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        return other;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * Returns true if grouping is used in this format. For example, in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * English locale, with grouping on, the number 1234567 might be formatted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * as "1,234,567". The grouping separator as well as the size of each group
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * is locale dependant and is determined by sub-classes of NumberFormat.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * @see #setGroupingUsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    public boolean isGroupingUsed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        return groupingUsed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * Set whether or not grouping will be used in this format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * @see #isGroupingUsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    public void setGroupingUsed(boolean newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
        groupingUsed = newValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
     * Returns the maximum number of digits allowed in the integer portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
     * number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
     * @see #setMaximumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    public int getMaximumIntegerDigits() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        return maximumIntegerDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     * Sets the maximum number of digits allowed in the integer portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
     * number. maximumIntegerDigits must be >= minimumIntegerDigits.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
     * new value for maximumIntegerDigits is less than the current value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
     * of minimumIntegerDigits, then minimumIntegerDigits will also be set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
     * the new value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
     * @param newValue the maximum number of integer digits to be shown; if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * less than zero, then zero is used. The concrete subclass may enforce an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
     * upper limit to this value appropriate to the numeric type being formatted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
     * @see #getMaximumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    public void setMaximumIntegerDigits(int newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
        maximumIntegerDigits = Math.max(0,newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
        if (minimumIntegerDigits > maximumIntegerDigits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
            minimumIntegerDigits = maximumIntegerDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
     * Returns the minimum number of digits allowed in the integer portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     * number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
     * @see #setMinimumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    public int getMinimumIntegerDigits() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
        return minimumIntegerDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
     * Sets the minimum number of digits allowed in the integer portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
     * number. minimumIntegerDigits must be <= maximumIntegerDigits.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
     * new value for minimumIntegerDigits exceeds the current value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
     * of maximumIntegerDigits, then maximumIntegerDigits will also be set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * the new value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     * @param newValue the minimum number of integer digits to be shown; if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
     * less than zero, then zero is used. The concrete subclass may enforce an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     * upper limit to this value appropriate to the numeric type being formatted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
     * @see #getMinimumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    public void setMinimumIntegerDigits(int newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
        minimumIntegerDigits = Math.max(0,newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        if (minimumIntegerDigits > maximumIntegerDigits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            maximumIntegerDigits = minimumIntegerDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
     * Returns the maximum number of digits allowed in the fraction portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
     * number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * @see #setMaximumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    public int getMaximumFractionDigits() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        return maximumFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * Sets the maximum number of digits allowed in the fraction portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     * number. maximumFractionDigits must be >= minimumFractionDigits.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * new value for maximumFractionDigits is less than the current value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * of minimumFractionDigits, then minimumFractionDigits will also be set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     * the new value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
     * @param newValue the maximum number of fraction digits to be shown; if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * less than zero, then zero is used. The concrete subclass may enforce an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     * upper limit to this value appropriate to the numeric type being formatted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
     * @see #getMaximumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
    public void setMaximumFractionDigits(int newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        maximumFractionDigits = Math.max(0,newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        if (maximumFractionDigits < minimumFractionDigits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
            minimumFractionDigits = maximumFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
     * Returns the minimum number of digits allowed in the fraction portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
     * number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
     * @see #setMinimumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
    public int getMinimumFractionDigits() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
        return minimumFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
     * Sets the minimum number of digits allowed in the fraction portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
     * number. minimumFractionDigits must be <= maximumFractionDigits.  If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
     * new value for minimumFractionDigits exceeds the current value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
     * of maximumFractionDigits, then maximumIntegerDigits will also be set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
     * the new value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
     * @param newValue the minimum number of fraction digits to be shown; if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
     * less than zero, then zero is used. The concrete subclass may enforce an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
     * upper limit to this value appropriate to the numeric type being formatted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
     * @see #getMinimumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
    public void setMinimumFractionDigits(int newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
        minimumFractionDigits = Math.max(0,newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        if (maximumFractionDigits < minimumFractionDigits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            maximumFractionDigits = minimumFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     * Gets the currency used by this number format when formatting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
     * currency values. The initial value is derived in a locale dependent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
     * way. The returned value may be null if no valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
     * currency could be determined and no currency has been set using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
     * {@link #setCurrency(java.util.Currency) setCurrency}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
     * The default implementation throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
     * <code>UnsupportedOperationException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * @return the currency used by this number format, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * @exception UnsupportedOperationException if the number format class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
     * doesn't implement currency formatting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
    public Currency getCurrency() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * Sets the currency used by this number format when formatting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
     * currency values. This does not update the minimum or maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     * number of fraction digits used by the number format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
     * The default implementation throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
     * <code>UnsupportedOperationException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * @param currency the new currency to be used by this number format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     * @exception UnsupportedOperationException if the number format class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
     * doesn't implement currency formatting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
     * @exception NullPointerException if <code>currency</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    public void setCurrency(Currency currency) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * Gets the {@link java.math.RoundingMode} used in this NumberFormat.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     * The default implementation of this method in NumberFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     * always throws {@link java.lang.UnsupportedOperationException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
     * Subclasses which handle different rounding modes should override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
     * this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
     * @exception UnsupportedOperationException The default implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     *     always throws this exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
     * @return The <code>RoundingMode</code> used for this NumberFormat.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * @see #setRoundingMode(RoundingMode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
    public RoundingMode getRoundingMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     * Sets the {@link java.math.RoundingMode} used in this NumberFormat.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
     * The default implementation of this method in NumberFormat always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
     * throws {@link java.lang.UnsupportedOperationException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
     * Subclasses which handle different rounding modes should override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
     * this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
     * @exception UnsupportedOperationException The default implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
     *     always throws this exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     * @exception NullPointerException if <code>roundingMode</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * @param roundingMode The <code>RoundingMode</code> to be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * @see #getRoundingMode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    public void setRoundingMode(RoundingMode roundingMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    // =======================privates===============================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    private static NumberFormat getInstance(Locale desiredLocale,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
                                           int choice) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   744
        // Check whether a provider can provide an implementation that's closer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
        // to the requested locale than what the Java runtime itself can provide.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
        LocaleServiceProviderPool pool =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
            LocaleServiceProviderPool.getPool(NumberFormatProvider.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
        if (pool.hasProviders()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
            NumberFormat providersInstance = pool.getLocalizedObject(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
                                    NumberFormatGetter.INSTANCE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
                                    desiredLocale,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
                                    choice);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            if (providersInstance != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
                return providersInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        /* try the cache first */
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 7668
diff changeset
   759
        String[] numberPatterns = cachedLocaleData.get(desiredLocale);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        if (numberPatterns == null) { /* cache miss */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            ResourceBundle resource = LocaleData.getNumberFormatData(desiredLocale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            numberPatterns = resource.getStringArray("NumberPatterns");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
            /* update cache */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            cachedLocaleData.put(desiredLocale, numberPatterns);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        DecimalFormatSymbols symbols = DecimalFormatSymbols.getInstance(desiredLocale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
        int entry = (choice == INTEGERSTYLE) ? NUMBERSTYLE : choice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        DecimalFormat format = new DecimalFormat(numberPatterns[entry], symbols);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        if (choice == INTEGERSTYLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            format.setMaximumFractionDigits(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
            format.setDecimalSeparatorAlwaysShown(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            format.setParseIntegerOnly(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
        } else if (choice == CURRENCYSTYLE) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
            format.adjustForCurrencyDefaultFractionDigits();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        return format;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * First, read in the default serializable data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     * Then, if <code>serialVersionOnStream</code> is less than 1, indicating that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
     * the stream was written by JDK 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
     * set the <code>int</code> fields such as <code>maximumIntegerDigits</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
     * to be equal to the <code>byte</code> fields such as <code>maxIntegerDigits</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
     * since the <code>int</code> fields were not present in JDK 1.1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
     * Finally, set serialVersionOnStream back to the maximum allowed value so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
     * default serialization will work properly if this object is streamed out again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * <p>If <code>minimumIntegerDigits</code> is greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * <code>maximumIntegerDigits</code> or <code>minimumFractionDigits</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * is greater than <code>maximumFractionDigits</code>, then the stream data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * is invalid and this method throws an <code>InvalidObjectException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     * In addition, if any of these values is negative, then this method throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * an <code>InvalidObjectException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    private void readObject(ObjectInputStream stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
         throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
        stream.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
        if (serialVersionOnStream < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
            // Didn't have additional int fields, reassign to use them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            maximumIntegerDigits = maxIntegerDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            minimumIntegerDigits = minIntegerDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
            maximumFractionDigits = maxFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            minimumFractionDigits = minFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
        if (minimumIntegerDigits > maximumIntegerDigits ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
            minimumFractionDigits > maximumFractionDigits ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            minimumIntegerDigits < 0 || minimumFractionDigits < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
            throw new InvalidObjectException("Digit count range invalid");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        serialVersionOnStream = currentSerialVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
     * Write out the default serializable data, after first setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * the <code>byte</code> fields such as <code>maxIntegerDigits</code> to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * equal to the <code>int</code> fields such as <code>maximumIntegerDigits</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * (or to <code>Byte.MAX_VALUE</code>, whichever is smaller), for compatibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * with the JDK 1.1 version of the stream format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    private void writeObject(ObjectOutputStream stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
         throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
        maxIntegerDigits = (maximumIntegerDigits > Byte.MAX_VALUE) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                           Byte.MAX_VALUE : (byte)maximumIntegerDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
        minIntegerDigits = (minimumIntegerDigits > Byte.MAX_VALUE) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                           Byte.MAX_VALUE : (byte)minimumIntegerDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        maxFractionDigits = (maximumFractionDigits > Byte.MAX_VALUE) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
                            Byte.MAX_VALUE : (byte)maximumFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
        minFractionDigits = (minimumFractionDigits > Byte.MAX_VALUE) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
                            Byte.MAX_VALUE : (byte)minimumFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
        stream.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * Cache to hold the NumberPatterns of a Locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     */
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 7668
diff changeset
   847
    private static final Hashtable<Locale, String[]> cachedLocaleData = new Hashtable<>(3);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
    // Constants used by factory methods to specify a style of format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
    private static final int NUMBERSTYLE = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    private static final int CURRENCYSTYLE = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
    private static final int PERCENTSTYLE = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    private static final int SCIENTIFICSTYLE = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    private static final int INTEGERSTYLE = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
     * True if the grouping (i.e. thousands) separator is used when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * formatting and parsing numbers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * @see #isGroupingUsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
    private boolean groupingUsed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     * The maximum number of digits allowed in the integer portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * number.  <code>maxIntegerDigits</code> must be greater than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * <code>minIntegerDigits</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     * <strong>Note:</strong> This field exists only for serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     * compatibility with JDK 1.1.  In Java platform 2 v1.2 and higher, the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * <code>int</code> field <code>maximumIntegerDigits</code> is used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * When writing to a stream, <code>maxIntegerDigits</code> is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * <code>maximumIntegerDigits</code> or <code>Byte.MAX_VALUE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     * whichever is smaller.  When reading from a stream, this field is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * only if <code>serialVersionOnStream</code> is less than 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * @see #getMaximumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    private byte    maxIntegerDigits = 40;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * The minimum number of digits allowed in the integer portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * number.  <code>minimumIntegerDigits</code> must be less than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * <code>maximumIntegerDigits</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * <strong>Note:</strong> This field exists only for serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     * compatibility with JDK 1.1.  In Java platform 2 v1.2 and higher, the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * <code>int</code> field <code>minimumIntegerDigits</code> is used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
     * When writing to a stream, <code>minIntegerDigits</code> is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     * <code>minimumIntegerDigits</code> or <code>Byte.MAX_VALUE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
     * whichever is smaller.  When reading from a stream, this field is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
     * only if <code>serialVersionOnStream</code> is less than 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     * @see #getMinimumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
    private byte    minIntegerDigits = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
     * The maximum number of digits allowed in the fractional portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * number.  <code>maximumFractionDigits</code> must be greater than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     * <code>minimumFractionDigits</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * <strong>Note:</strong> This field exists only for serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     * compatibility with JDK 1.1.  In Java platform 2 v1.2 and higher, the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   908
     * <code>int</code> field <code>maximumFractionDigits</code> is used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     * When writing to a stream, <code>maxFractionDigits</code> is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * <code>maximumFractionDigits</code> or <code>Byte.MAX_VALUE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
     * whichever is smaller.  When reading from a stream, this field is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * only if <code>serialVersionOnStream</code> is less than 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   913
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     * @see #getMaximumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
    private byte    maxFractionDigits = 3;    // invariant, >= minFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
     * The minimum number of digits allowed in the fractional portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * number.  <code>minimumFractionDigits</code> must be less than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * <code>maximumFractionDigits</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * <strong>Note:</strong> This field exists only for serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * compatibility with JDK 1.1.  In Java platform 2 v1.2 and higher, the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     * <code>int</code> field <code>minimumFractionDigits</code> is used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
     * When writing to a stream, <code>minFractionDigits</code> is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     * <code>minimumFractionDigits</code> or <code>Byte.MAX_VALUE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
     * whichever is smaller.  When reading from a stream, this field is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * only if <code>serialVersionOnStream</code> is less than 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * @see #getMinimumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
    private byte    minFractionDigits = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * True if this format will parse numbers as integers only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * @see #isParseIntegerOnly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
    private boolean parseIntegerOnly = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
    // new fields for 1.2.  byte is too small for integer digits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * The maximum number of digits allowed in the integer portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * number.  <code>maximumIntegerDigits</code> must be greater than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     * <code>minimumIntegerDigits</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
     * @see #getMaximumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
    private int    maximumIntegerDigits = 40;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
     * The minimum number of digits allowed in the integer portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
     * number.  <code>minimumIntegerDigits</code> must be less than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
     * <code>maximumIntegerDigits</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
     * @see #getMinimumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
    private int    minimumIntegerDigits = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     * The maximum number of digits allowed in the fractional portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     * number.  <code>maximumFractionDigits</code> must be greater than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     * <code>minimumFractionDigits</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     * @see #getMaximumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
    private int    maximumFractionDigits = 3;    // invariant, >= minFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
     * The minimum number of digits allowed in the fractional portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
     * number.  <code>minimumFractionDigits</code> must be less than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
     * <code>maximumFractionDigits</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
     * @see #getMinimumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    private int    minimumFractionDigits = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
    static final int currentSerialVersion = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
     * Describes the version of <code>NumberFormat</code> present on the stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
     * Possible values are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * <li><b>0</b> (or uninitialized): the JDK 1.1 version of the stream format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     *     In this version, the <code>int</code> fields such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     *     <code>maximumIntegerDigits</code> were not present, and the <code>byte</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     *     fields such as <code>maxIntegerDigits</code> are used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * <li><b>1</b>: the 1.2 version of the stream format.  The values of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     *     <code>byte</code> fields such as <code>maxIntegerDigits</code> are ignored,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     *     and the <code>int</code> fields such as <code>maximumIntegerDigits</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     *     are used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
     * When streaming out a <code>NumberFormat</code>, the most recent format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     * (corresponding to the highest allowable <code>serialVersionOnStream</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     * is always written.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
    private int serialVersionOnStream = currentSerialVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
    // Removed "implements Cloneable" clause.  Needs to update serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    // ID for backward compatibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
    static final long serialVersionUID = -2308460125733713944L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
    // class for AttributedCharacterIterator attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
     * Defines constants that are used as attribute keys in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * <code>AttributedCharacterIterator</code> returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * from <code>NumberFormat.formatToCharacterIterator</code> and as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * field identifiers in <code>FieldPosition</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
    public static class Field extends Format.Field {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
        // Proclaim serial compatibility with 1.4 FCS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
        private static final long serialVersionUID = 7494728892700160890L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
        // table of all instances in this class, used by readResolve
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 7668
diff changeset
  1038
        private static final Map<String, Field> instanceMap = new HashMap<>(11);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
         * Creates a Field instance with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
         * name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
         * @param name Name of the attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
        protected Field(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
            super(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            if (this.getClass() == NumberFormat.Field.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                instanceMap.put(name, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
         * Resolves instances being deserialized to the predefined constants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
         * @throws InvalidObjectException if the constant could not be resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
         * @return resolved NumberFormat.Field constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
        protected Object readResolve() throws InvalidObjectException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            if (this.getClass() != NumberFormat.Field.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
                throw new InvalidObjectException("subclass didn't correctly implement readResolve");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
            Object instance = instanceMap.get(getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
            if (instance != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                return instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                throw new InvalidObjectException("unknown attribute name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
         * Constant identifying the integer field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
        public static final Field INTEGER = new Field("integer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
         * Constant identifying the fraction field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
        public static final Field FRACTION = new Field("fraction");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
         * Constant identifying the exponent field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
        public static final Field EXPONENT = new Field("exponent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
         * Constant identifying the decimal separator field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
        public static final Field DECIMAL_SEPARATOR =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
                            new Field("decimal separator");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
         * Constant identifying the sign field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
        public static final Field SIGN = new Field("sign");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
         * Constant identifying the grouping separator field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
        public static final Field GROUPING_SEPARATOR =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                            new Field("grouping separator");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
         * Constant identifying the exponent symbol field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
        public static final Field EXPONENT_SYMBOL = new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                            Field("exponent symbol");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
         * Constant identifying the percent field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
        public static final Field PERCENT = new Field("percent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
         * Constant identifying the permille field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
        public static final Field PERMILLE = new Field("per mille");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
         * Constant identifying the currency field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
        public static final Field CURRENCY = new Field("currency");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
         * Constant identifying the exponent sign field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
        public static final Field EXPONENT_SIGN = new Field("exponent sign");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     * Obtains a NumberFormat instance from a NumberFormatProvider implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
    private static class NumberFormatGetter
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
        implements LocaleServiceProviderPool.LocalizedObjectGetter<NumberFormatProvider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
                                                                   NumberFormat> {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
        private static final NumberFormatGetter INSTANCE = new NumberFormatGetter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
        public NumberFormat getObject(NumberFormatProvider numberFormatProvider,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
                                Locale locale,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                                String key,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
                                Object... params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
            assert params.length == 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
            int choice = (Integer)params[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
            switch (choice) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
            case NUMBERSTYLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
                return numberFormatProvider.getNumberInstance(locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
            case PERCENTSTYLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
                return numberFormatProvider.getPercentInstance(locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
            case CURRENCYSTYLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
                return numberFormatProvider.getCurrencyInstance(locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
            case INTEGERSTYLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
                return numberFormatProvider.getIntegerInstance(locale);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
            default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
                assert false : choice;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
}