src/java.base/share/classes/java/text/NumberFormat.java
author nishjain
Thu, 30 Nov 2017 13:31:30 +0530
changeset 48026 89deac44e515
parent 47216 71c04702a3d5
child 48251 57148c79bd75
permissions -rw-r--r--
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use Reviewed-by: naoto, rriggs Contributed-by: nishit.jain@oracle.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
43011
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
     2
 * Copyright (c) 1996, 2017, 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;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
    57
import sun.util.locale.provider.LocaleProviderAdapter;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
    58
import sun.util.locale.provider.LocaleServiceProviderPool;
2
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>
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    76
 * <pre>{@code
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    77
 * myString = NumberFormat.getInstance().format(myNumber);
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    78
 * }</pre>
2
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>
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    85
 * <pre>{@code
2
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
 * }
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    90
 * }</pre>
2
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>
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    95
 * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * NumberFormat nf = NumberFormat.getInstance(Locale.FRENCH);
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    97
 * }</pre>
2
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>
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   101
 * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * myNumber = nf.parse(myString);
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   103
 * }</pre>
2
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.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   128
 * if true,  "3456.78" &rarr; 3456 (and leaves the parse position just after index 6)
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   129
 * if false, "3456.78" &rarr; 3456.78 (and leaves the parse position just after index 8)
2
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.,
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   137
 * if true,  3456.00 &rarr; "3,456."
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   138
 * if false, 3456.00 &rarr; "3456"
2
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
 *
44844
b2b4d98404ba 8179364: update "<a name=" in java.base module to use id attribute
jjg
parents: 43011
diff changeset
   169
 * <h3><a id="synchronization">Synchronization</a></h3>
2
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
 *
43011
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   177
 * @implSpec The {@link #format(double, StringBuffer, FieldPosition)},
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   178
 * {@link #format(long, StringBuffer, FieldPosition)} and
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   179
 * {@link #parse(String, ParsePosition)} methods may throw
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   180
 * {@code NullPointerException}, if any of their parameter is {@code null}.
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   181
 * The subclass may provide its own implementation and specification about
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   182
 * {@code NullPointerException}.
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   183
 *
47016
49f2da5b2ea3 8186713: Document default rounding mode in NumberFormat
nishjain
parents: 45434
diff changeset
   184
 * <p>
49f2da5b2ea3 8186713: Document default rounding mode in NumberFormat
nishjain
parents: 45434
diff changeset
   185
 * The default implementation provides rounding modes defined
49f2da5b2ea3 8186713: Document default rounding mode in NumberFormat
nishjain
parents: 45434
diff changeset
   186
 * in {@link java.math.RoundingMode} for formatting numbers. It
49f2da5b2ea3 8186713: Document default rounding mode in NumberFormat
nishjain
parents: 45434
diff changeset
   187
 * uses the {@linkplain java.math.RoundingMode#HALF_EVEN
49f2da5b2ea3 8186713: Document default rounding mode in NumberFormat
nishjain
parents: 45434
diff changeset
   188
 * round half-even algorithm}. To change the rounding mode use
49f2da5b2ea3 8186713: Document default rounding mode in NumberFormat
nishjain
parents: 45434
diff changeset
   189
 * {@link #setRoundingMode(java.math.RoundingMode) setRoundingMode}.
49f2da5b2ea3 8186713: Document default rounding mode in NumberFormat
nishjain
parents: 45434
diff changeset
   190
 * The {@code NumberFormat} returned by the static factory methods is
49f2da5b2ea3 8186713: Document default rounding mode in NumberFormat
nishjain
parents: 45434
diff changeset
   191
 * configured to round floating point numbers using half-even
49f2da5b2ea3 8186713: Document default rounding mode in NumberFormat
nishjain
parents: 45434
diff changeset
   192
 * rounding (see {@link java.math.RoundingMode#HALF_EVEN
49f2da5b2ea3 8186713: Document default rounding mode in NumberFormat
nishjain
parents: 45434
diff changeset
   193
 * RoundingMode.HALF_EVEN}) for formatting.
49f2da5b2ea3 8186713: Document default rounding mode in NumberFormat
nishjain
parents: 45434
diff changeset
   194
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
 * @see          DecimalFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
 * @see          ChoiceFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
 * @author       Mark Davis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
 * @author       Helena Shih
45434
4582657c7260 8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents: 44844
diff changeset
   199
 * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
public abstract class NumberFormat extends Format  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * Field constant used to construct a FieldPosition object. Signifies that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * the position of the integer part of a formatted number should be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @see java.text.FieldPosition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public static final int INTEGER_FIELD = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * Field constant used to construct a FieldPosition object. Signifies that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * the position of the fraction part of a formatted number should be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * @see java.text.FieldPosition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    public static final int FRACTION_FIELD = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * Sole constructor.  (For invocation by subclass constructors, typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * implicit.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    protected NumberFormat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Formats a number and appends the resulting text to the given string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * The number can be of any subclass of {@link java.lang.Number}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * This implementation extracts the number's value using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * {@link java.lang.Number#longValue()} for all integral type values that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * can be converted to <code>long</code> without loss of information,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * including <code>BigInteger</code> values with a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * {@link java.math.BigInteger#bitLength() bit length} of less than 64,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * and {@link java.lang.Number#doubleValue()} for all other types. It
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * then calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * {@link #format(long,java.lang.StringBuffer,java.text.FieldPosition)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * or {@link #format(double,java.lang.StringBuffer,java.text.FieldPosition)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * This may result in loss of magnitude information and precision for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * <code>BigInteger</code> and <code>BigDecimal</code> values.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @param number     the number to format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * @param toAppendTo the <code>StringBuffer</code> to which the formatted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *                   text is to be appended
48026
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   243
     * @param pos        keeps track on the position of the field within the
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   244
     *                   returned string. For example, for formatting a number
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   245
     *                   {@code 1234567.89} in {@code Locale.US} locale,
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   246
     *                   if the given {@code fieldPosition} is
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   247
     *                   {@link NumberFormat#INTEGER_FIELD}, the begin index
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   248
     *                   and end index of {@code fieldPosition} will be set
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   249
     *                   to 0 and 9, respectively for the output string
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   250
     *                   {@code 1,234,567.89}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * @return           the value passed in as <code>toAppendTo</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * @exception        IllegalArgumentException if <code>number</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     *                   null or not an instance of <code>Number</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * @exception        NullPointerException if <code>toAppendTo</code> or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *                   <code>pos</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * @exception        ArithmeticException if rounding is needed with rounding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     *                   mode being set to RoundingMode.UNNECESSARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * @see              java.text.FieldPosition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   260
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    public StringBuffer format(Object number,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                               StringBuffer toAppendTo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
                               FieldPosition pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
        if (number instanceof Long || number instanceof Integer ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            number instanceof Short || number instanceof Byte ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            number instanceof AtomicInteger || number instanceof AtomicLong ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            (number instanceof BigInteger &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
             ((BigInteger)number).bitLength() < 64)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            return format(((Number)number).longValue(), toAppendTo, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        } else if (number instanceof Number) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            return format(((Number)number).doubleValue(), toAppendTo, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            throw new IllegalArgumentException("Cannot format given Object as a Number");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * Parses text from a string to produce a <code>Number</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * The method attempts to parse text starting at the index given by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * <code>pos</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * If parsing succeeds, then the index of <code>pos</code> is updated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * to the index after the last character used (parsing does not necessarily
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * use all characters up to the end of the string), and the parsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * number is returned. The updated <code>pos</code> can be used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * indicate the starting point for the next call to this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * If an error occurs, then the index of <code>pos</code> is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * changed, the error index of <code>pos</code> is set to the index of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * the character where the error occurred, and null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * See the {@link #parse(String, ParsePosition)} method for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * on number parsing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * @param source A <code>String</code>, part of which should be parsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @param pos A <code>ParsePosition</code> object with index and error
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     *            index information as described above.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * @return A <code>Number</code> parsed from the string. In case of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     *         error, returns null.
34328
0534cb944d0e 8073211: javadoc of Format parseObject methods should specify NullPointerExceptions
okutsu
parents: 32649
diff changeset
   299
     * @throws NullPointerException if {@code source} or {@code pos} is null.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   301
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
    public final Object parseObject(String source, ParsePosition pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        return parse(source, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * Specialization of format.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   308
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   309
     * @param number the double number to format
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   310
     * @return the formatted String
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * @exception        ArithmeticException if rounding is needed with rounding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     *                   mode being set to RoundingMode.UNNECESSARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * @see java.text.Format#format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
    public final String format(double number) {
14015
f771d5fb3b27 7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents: 13583
diff changeset
   316
        // Use fast-path for double result if that works
f771d5fb3b27 7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents: 13583
diff changeset
   317
        String result = fastFormat(number);
f771d5fb3b27 7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents: 13583
diff changeset
   318
        if (result != null)
f771d5fb3b27 7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents: 13583
diff changeset
   319
            return result;
f771d5fb3b27 7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents: 13583
diff changeset
   320
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        return format(number, new StringBuffer(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                      DontCareFieldPosition.INSTANCE).toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
14015
f771d5fb3b27 7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents: 13583
diff changeset
   325
    /*
f771d5fb3b27 7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents: 13583
diff changeset
   326
     * fastFormat() is supposed to be implemented in concrete subclasses only.
f771d5fb3b27 7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents: 13583
diff changeset
   327
     * Default implem always returns null.
f771d5fb3b27 7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents: 13583
diff changeset
   328
     */
f771d5fb3b27 7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents: 13583
diff changeset
   329
    String fastFormat(double number) { return null; }
f771d5fb3b27 7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents: 13583
diff changeset
   330
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * Specialization of format.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   333
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   334
     * @param number the long number to format
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   335
     * @return the formatted String
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @exception        ArithmeticException if rounding is needed with rounding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *                   mode being set to RoundingMode.UNNECESSARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @see java.text.Format#format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    public final String format(long number) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        return format(number, new StringBuffer(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                      DontCareFieldPosition.INSTANCE).toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * Specialization of format.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   347
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   348
     * @param number     the double number to format
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   349
     * @param toAppendTo the StringBuffer to which the formatted text is to be
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   350
     *                   appended
48026
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   351
     * @param pos        keeps track on the position of the field within the
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   352
     *                   returned string. For example, for formatting a number
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   353
     *                   {@code 1234567.89} in {@code Locale.US} locale,
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   354
     *                   if the given {@code fieldPosition} is
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   355
     *                   {@link NumberFormat#INTEGER_FIELD}, the begin index
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   356
     *                   and end index of {@code fieldPosition} will be set
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   357
     *                   to 0 and 9, respectively for the output string
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   358
     *                   {@code 1,234,567.89}.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   359
     * @return the formatted StringBuffer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * @exception        ArithmeticException if rounding is needed with rounding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
     *                   mode being set to RoundingMode.UNNECESSARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
     * @see java.text.Format#format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    public abstract StringBuffer format(double number,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                                        StringBuffer toAppendTo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                                        FieldPosition pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * Specialization of format.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   370
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   371
     * @param number     the long number to format
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   372
     * @param toAppendTo the StringBuffer to which the formatted text is to be
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   373
     *                   appended
48026
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   374
     * @param pos        keeps track on the position of the field within the
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   375
     *                   returned string. For example, for formatting a number
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   376
     *                   {@code 123456789} in {@code Locale.US} locale,
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   377
     *                   if the given {@code fieldPosition} is
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   378
     *                   {@link NumberFormat#INTEGER_FIELD}, the begin index
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   379
     *                   and end index of {@code fieldPosition} will be set
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   380
     *                   to 0 and 11, respectively for the output string
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   381
     *                   {@code 123,456,789}.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   382
     * @return the formatted StringBuffer
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * @exception        ArithmeticException if rounding is needed with rounding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     *                   mode being set to RoundingMode.UNNECESSARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     * @see java.text.Format#format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    public abstract StringBuffer format(long number,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                                        StringBuffer toAppendTo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                                        FieldPosition pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * Returns a Long if possible (e.g., within the range [Long.MIN_VALUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     * Long.MAX_VALUE] and with no decimals), otherwise a Double.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * If IntegerOnly is set, will stop at a decimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * point (or equivalent; e.g., for rational numbers "1 2/3", will stop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * after the 1).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * Does not throw an exception; if no object can be parsed, index is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * unchanged!
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   399
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   400
     * @param source the String to parse
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   401
     * @param parsePosition the parse position
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   402
     * @return the parsed value
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * @see java.text.NumberFormat#isParseIntegerOnly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * @see java.text.Format#parseObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
    public abstract Number parse(String source, ParsePosition parsePosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * Parses text from the beginning of the given string to produce a number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * The method may not use the entire text of the given string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * See the {@link #parse(String, ParsePosition)} method for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * on number parsing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @param source A <code>String</code> whose beginning should be parsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @return A <code>Number</code> parsed from the string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     * @exception ParseException if the beginning of the specified string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     *            cannot be parsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    public Number parse(String source) throws ParseException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        ParsePosition parsePosition = new ParsePosition(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        Number result = parse(source, parsePosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
        if (parsePosition.index == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
            throw new ParseException("Unparseable number: \"" + source + "\"",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                                     parsePosition.errorIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * Returns true if this format will parse numbers as integers only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * For example in the English locale, with ParseIntegerOnly true, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * string "1234." would be parsed as the integer value 1234 and parsing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * would stop at the "." character.  Of course, the exact format accepted
47020
2c55106dc37b 8186851: fix misspellings of "dependent" and "independent" in the JDK repo
smarks
parents: 47016
diff changeset
   435
     * by the parse operation is locale dependent and determined by sub-classes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * of NumberFormat.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   437
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   438
     * @return {@code true} if numbers should be parsed as integers only;
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   439
     *         {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    public boolean isParseIntegerOnly() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        return parseIntegerOnly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * Sets whether or not numbers should be parsed as integers only.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   447
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   448
     * @param value {@code true} if numbers should be parsed as integers only;
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   449
     *              {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * @see #isParseIntegerOnly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    public void setParseIntegerOnly(boolean value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        parseIntegerOnly = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
    //============== Locale Stuff =====================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    /**
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   459
     * Returns a general-purpose number format for the current default
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   460
     * {@link java.util.Locale.Category#FORMAT FORMAT} locale.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * This is the same as calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * {@link #getNumberInstance() getNumberInstance()}.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   463
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   464
     * @return the {@code NumberFormat} instance for general-purpose number
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   465
     * formatting
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   467
    public static final NumberFormat getInstance() {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   468
        return getInstance(Locale.getDefault(Locale.Category.FORMAT), NUMBERSTYLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * Returns a general-purpose number format for the specified locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * This is the same as calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * {@link #getNumberInstance(java.util.Locale) getNumberInstance(inLocale)}.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   475
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   476
     * @param inLocale the desired locale
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   477
     * @return the {@code NumberFormat} instance for general-purpose number
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   478
     * formatting
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    public static NumberFormat getInstance(Locale inLocale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
        return getInstance(inLocale, NUMBERSTYLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
    /**
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   485
     * Returns a general-purpose number format for the current default
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   486
     * {@link java.util.Locale.Category#FORMAT FORMAT} locale.
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   487
     * <p>This is equivalent to calling
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   488
     * {@link #getNumberInstance(Locale)
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   489
     *     getNumberInstance(Locale.getDefault(Locale.Category.FORMAT))}.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   490
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   491
     * @return the {@code NumberFormat} instance for general-purpose number
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   492
     * formatting
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   493
     * @see java.util.Locale#getDefault(java.util.Locale.Category)
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   494
     * @see java.util.Locale.Category#FORMAT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   496
    public static final NumberFormat getNumberInstance() {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   497
        return getInstance(Locale.getDefault(Locale.Category.FORMAT), NUMBERSTYLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * Returns a general-purpose number format for the specified locale.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   502
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   503
     * @param inLocale the desired locale
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   504
     * @return the {@code NumberFormat} instance for general-purpose number
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   505
     * formatting
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    public static NumberFormat getNumberInstance(Locale inLocale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        return getInstance(inLocale, NUMBERSTYLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    /**
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   512
     * Returns an integer number format for the current default
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   513
     * {@link java.util.Locale.Category#FORMAT FORMAT} locale. The
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * returned number format is configured to round floating point numbers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * to the nearest integer using half-even rounding (see {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * java.math.RoundingMode#HALF_EVEN RoundingMode.HALF_EVEN}) for formatting,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * and to parse only the integer part of an input string (see {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * #isParseIntegerOnly isParseIntegerOnly}).
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   519
     * <p>This is equivalent to calling
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   520
     * {@link #getIntegerInstance(Locale)
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   521
     *     getIntegerInstance(Locale.getDefault(Locale.Category.FORMAT))}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * @see #getRoundingMode()
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   524
     * @see java.util.Locale#getDefault(java.util.Locale.Category)
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   525
     * @see java.util.Locale.Category#FORMAT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * @return a number format for integer values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   529
    public static final NumberFormat getIntegerInstance() {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   530
        return getInstance(Locale.getDefault(Locale.Category.FORMAT), INTEGERSTYLE);
2
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
     * Returns an integer number format for the specified locale. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     * returned number format is configured to round floating point numbers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * to the nearest integer using half-even rounding (see {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * java.math.RoundingMode#HALF_EVEN RoundingMode.HALF_EVEN}) for formatting,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * and to parse only the integer part of an input string (see {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * #isParseIntegerOnly isParseIntegerOnly}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     *
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   541
     * @param inLocale the desired locale
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     * @see #getRoundingMode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * @return a number format for integer values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    public static NumberFormat getIntegerInstance(Locale inLocale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        return getInstance(inLocale, INTEGERSTYLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    /**
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   551
     * Returns a currency format for the current default
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   552
     * {@link java.util.Locale.Category#FORMAT FORMAT} locale.
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   553
     * <p>This is equivalent to calling
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   554
     * {@link #getCurrencyInstance(Locale)
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   555
     *     getCurrencyInstance(Locale.getDefault(Locale.Category.FORMAT))}.
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   556
     *
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   557
     * @return the {@code NumberFormat} instance for currency formatting
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   558
     * @see java.util.Locale#getDefault(java.util.Locale.Category)
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   559
     * @see java.util.Locale.Category#FORMAT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   561
    public static final NumberFormat getCurrencyInstance() {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   562
        return getInstance(Locale.getDefault(Locale.Category.FORMAT), CURRENCYSTYLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
     * Returns a currency format for the specified locale.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   567
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   568
     * @param inLocale the desired locale
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   569
     * @return the {@code NumberFormat} instance for currency formatting
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
    public static NumberFormat getCurrencyInstance(Locale inLocale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        return getInstance(inLocale, CURRENCYSTYLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    /**
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   576
     * Returns a percentage format for the current default
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   577
     * {@link java.util.Locale.Category#FORMAT FORMAT} locale.
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   578
     * <p>This is equivalent to calling
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   579
     * {@link #getPercentInstance(Locale)
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   580
     *     getPercentInstance(Locale.getDefault(Locale.Category.FORMAT))}.
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   581
     *
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   582
     * @return the {@code NumberFormat} instance for percentage formatting
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   583
     * @see java.util.Locale#getDefault(java.util.Locale.Category)
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   584
     * @see java.util.Locale.Category#FORMAT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   586
    public static final NumberFormat getPercentInstance() {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   587
        return getInstance(Locale.getDefault(Locale.Category.FORMAT), PERCENTSTYLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
     * Returns a percentage format for the specified locale.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   592
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   593
     * @param inLocale the desired locale
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   594
     * @return the {@code NumberFormat} instance for percentage formatting
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
    public static NumberFormat getPercentInstance(Locale inLocale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
        return getInstance(inLocale, PERCENTSTYLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
     * Returns a scientific format for the current default locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
    /*public*/ final static NumberFormat getScientificInstance() {
6489
9e7015635425 4700857: RFE: separating user locale and user interface locale
naoto
parents: 5506
diff changeset
   604
        return getInstance(Locale.getDefault(Locale.Category.FORMAT), SCIENTIFICSTYLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
     * Returns a scientific format for the specified locale.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   609
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   610
     * @param inLocale the desired locale
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
    /*public*/ static NumberFormat getScientificInstance(Locale inLocale) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
        return getInstance(inLocale, SCIENTIFICSTYLE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
     * Returns an array of all locales for which the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
     * <code>get*Instance</code> methods of this class can return
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
     * localized instances.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * The returned array represents the union of locales supported by the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     * runtime and by installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
     * {@link java.text.spi.NumberFormatProvider NumberFormatProvider} implementations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
     * It must contain at least a <code>Locale</code> instance equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
     * {@link java.util.Locale#US Locale.US}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
     * @return An array of locales for which localized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     *         <code>NumberFormat</code> instances are available.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    public static Locale[] getAvailableLocales() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        LocaleServiceProviderPool pool =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
            LocaleServiceProviderPool.getPool(NumberFormatProvider.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        return pool.getAvailableLocales();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    /**
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   636
     * Overrides hashCode.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   638
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
        return maximumIntegerDigits * 37 + maxFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
        // just enough fields for a reasonable distribution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
    /**
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   645
     * Overrides equals.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   647
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
        if (obj == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
        if (this == obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
        if (getClass() != obj.getClass()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
        NumberFormat other = (NumberFormat) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
        return (maximumIntegerDigits == other.maximumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            && minimumIntegerDigits == other.minimumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
            && maximumFractionDigits == other.maximumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            && minimumFractionDigits == other.minimumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
            && groupingUsed == other.groupingUsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
            && parseIntegerOnly == other.parseIntegerOnly);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
    /**
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   668
     * Overrides Cloneable.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   670
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
        NumberFormat other = (NumberFormat) super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
        return other;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
     * Returns true if grouping is used in this format. For example, in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
     * English locale, with grouping on, the number 1234567 might be formatted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * as "1,234,567". The grouping separator as well as the size of each group
47020
2c55106dc37b 8186851: fix misspellings of "dependent" and "independent" in the JDK repo
smarks
parents: 47016
diff changeset
   680
     * is locale dependent and is determined by sub-classes of NumberFormat.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   681
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   682
     * @return {@code true} if grouping is used;
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   683
     *         {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * @see #setGroupingUsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
    public boolean isGroupingUsed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
        return groupingUsed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
     * Set whether or not grouping will be used in this format.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   692
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   693
     * @param newValue {@code true} if grouping is used;
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   694
     *                 {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
     * @see #isGroupingUsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    public void setGroupingUsed(boolean newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
        groupingUsed = newValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
     * Returns the maximum number of digits allowed in the integer portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
     * number.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   704
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   705
     * @return the maximum number of digits
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
     * @see #setMaximumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   707
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
    public int getMaximumIntegerDigits() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   709
        return maximumIntegerDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
     * Sets the maximum number of digits allowed in the integer portion of a
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   714
     * number. maximumIntegerDigits must be &ge; minimumIntegerDigits.  If the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
     * new value for maximumIntegerDigits is less than the current value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
     * of minimumIntegerDigits, then minimumIntegerDigits will also be set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
     * the new value.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   718
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
     * @param newValue the maximum number of integer digits to be shown; if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
     * less than zero, then zero is used. The concrete subclass may enforce an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
     * upper limit to this value appropriate to the numeric type being formatted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
     * @see #getMaximumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
    public void setMaximumIntegerDigits(int newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
        maximumIntegerDigits = Math.max(0,newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
        if (minimumIntegerDigits > maximumIntegerDigits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
            minimumIntegerDigits = maximumIntegerDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
     * Returns the minimum number of digits allowed in the integer portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
     * number.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   734
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   735
     * @return the minimum number of digits
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
     * @see #setMinimumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    public int getMinimumIntegerDigits() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        return minimumIntegerDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
90ce3da70b43 Initial load
duke
parents:
diff changeset
   742
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   743
     * Sets the minimum number of digits allowed in the integer portion of a
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   744
     * number. minimumIntegerDigits must be &le; maximumIntegerDigits.  If the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   745
     * new value for minimumIntegerDigits exceeds the current value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * of maximumIntegerDigits, then maximumIntegerDigits will also be set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     * the new value
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   748
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
     * @param newValue the minimum number of integer digits to be shown; if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
     * less than zero, then zero is used. The concrete subclass may enforce an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
     * upper limit to this value appropriate to the numeric type being formatted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
     * @see #getMinimumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
    public void setMinimumIntegerDigits(int newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
        minimumIntegerDigits = Math.max(0,newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
        if (minimumIntegerDigits > maximumIntegerDigits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
            maximumIntegerDigits = minimumIntegerDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
     * Returns the maximum number of digits allowed in the fraction portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
     * number.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   764
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   765
     * @return the maximum number of digits.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   766
     * @see #setMaximumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
    public int getMaximumFractionDigits() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
        return maximumFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
     * Sets the maximum number of digits allowed in the fraction portion of a
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   774
     * number. maximumFractionDigits must be &ge; minimumFractionDigits.  If the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * new value for maximumFractionDigits is less than the current value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
     * of minimumFractionDigits, then minimumFractionDigits will also be set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * the new value.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   778
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * @param newValue the maximum number of fraction digits to be shown; if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
     * less than zero, then zero is used. The concrete subclass may enforce an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * upper limit to this value appropriate to the numeric type being formatted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * @see #getMaximumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    public void setMaximumFractionDigits(int newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
        maximumFractionDigits = Math.max(0,newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
        if (maximumFractionDigits < minimumFractionDigits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            minimumFractionDigits = maximumFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
     * Returns the minimum number of digits allowed in the fraction portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
     * number.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   794
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   795
     * @return the minimum number of digits
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
     * @see #setMinimumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
    public int getMinimumFractionDigits() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
        return minimumFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
     * Sets the minimum number of digits allowed in the fraction portion of a
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   804
     * number. minimumFractionDigits must be &le; maximumFractionDigits.  If the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * new value for minimumFractionDigits exceeds the current value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
     * of maximumFractionDigits, then maximumIntegerDigits will also be set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * the new value
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   808
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * @param newValue the minimum number of fraction digits to be shown; if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
     * less than zero, then zero is used. The concrete subclass may enforce an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * upper limit to this value appropriate to the numeric type being formatted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * @see #getMinimumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
    public void setMinimumFractionDigits(int newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
        minimumFractionDigits = Math.max(0,newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
        if (maximumFractionDigits < minimumFractionDigits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            maximumFractionDigits = minimumFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        }
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
     * Gets the currency used by this number format when formatting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
     * currency values. The initial value is derived in a locale dependent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * way. The returned value may be null if no valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * currency could be determined and no currency has been set using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
     * {@link #setCurrency(java.util.Currency) setCurrency}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * The default implementation throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     * <code>UnsupportedOperationException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
     * @return the currency used by this number format, or <code>null</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
     * @exception UnsupportedOperationException if the number format class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
     * doesn't implement currency formatting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
    public Currency getCurrency() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * Sets the currency used by this number format when formatting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * currency values. This does not update the minimum or maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * number of fraction digits used by the number format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     * The default implementation throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
     * <code>UnsupportedOperationException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
     * @param currency the new currency to be used by this number format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
     * @exception UnsupportedOperationException if the number format class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
     * doesn't implement currency formatting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
     * @exception NullPointerException if <code>currency</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
    public void setCurrency(Currency currency) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     * Gets the {@link java.math.RoundingMode} used in this NumberFormat.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
     * The default implementation of this method in NumberFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
     * always throws {@link java.lang.UnsupportedOperationException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
     * Subclasses which handle different rounding modes should override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
     * this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * @exception UnsupportedOperationException The default implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
     *     always throws this exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * @return The <code>RoundingMode</code> used for this NumberFormat.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * @see #setRoundingMode(RoundingMode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
    public RoundingMode getRoundingMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
     * Sets the {@link java.math.RoundingMode} used in this NumberFormat.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
     * The default implementation of this method in NumberFormat always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
     * throws {@link java.lang.UnsupportedOperationException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
     * Subclasses which handle different rounding modes should override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
     * this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
     * @exception UnsupportedOperationException The default implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
     *     always throws this exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * @exception NullPointerException if <code>roundingMode</code> is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * @param roundingMode The <code>RoundingMode</code> to be used
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * @see #getRoundingMode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
    public void setRoundingMode(RoundingMode roundingMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
    // =======================privates===============================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   894
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
    private static NumberFormat getInstance(Locale desiredLocale,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
                                           int choice) {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   897
        LocaleProviderAdapter adapter;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   898
        adapter = LocaleProviderAdapter.getAdapter(NumberFormatProvider.class,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   899
                                                   desiredLocale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   900
        NumberFormat numberFormat = getInstance(adapter, desiredLocale, choice);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   901
        if (numberFormat == null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   902
            numberFormat = getInstance(LocaleProviderAdapter.forJRE(),
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   903
                                       desiredLocale, choice);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
        }
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   905
        return numberFormat;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   906
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   908
    private static NumberFormat getInstance(LocaleProviderAdapter adapter,
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   909
                                            Locale locale, int choice) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   910
        NumberFormatProvider provider = adapter.getNumberFormatProvider();
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   911
        NumberFormat numberFormat = null;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   912
        switch (choice) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   913
        case NUMBERSTYLE:
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   914
            numberFormat = provider.getNumberInstance(locale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   915
            break;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   916
        case PERCENTSTYLE:
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   917
            numberFormat = provider.getPercentInstance(locale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   918
            break;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   919
        case CURRENCYSTYLE:
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   920
            numberFormat = provider.getCurrencyInstance(locale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   921
            break;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   922
        case INTEGERSTYLE:
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   923
            numberFormat = provider.getIntegerInstance(locale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   924
            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
        }
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   926
        return numberFormat;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   927
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * First, read in the default serializable data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     * Then, if <code>serialVersionOnStream</code> is less than 1, indicating that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
     * the stream was written by JDK 1.1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
     * set the <code>int</code> fields such as <code>maximumIntegerDigits</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
     * to be equal to the <code>byte</code> fields such as <code>maxIntegerDigits</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
     * since the <code>int</code> fields were not present in JDK 1.1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
     * Finally, set serialVersionOnStream back to the maximum allowed value so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * default serialization will work properly if this object is streamed out again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     * <p>If <code>minimumIntegerDigits</code> is greater than
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * <code>maximumIntegerDigits</code> or <code>minimumFractionDigits</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * is greater than <code>maximumFractionDigits</code>, then the stream data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     * is invalid and this method throws an <code>InvalidObjectException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
     * In addition, if any of these values is negative, then this method throws
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     * an <code>InvalidObjectException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
    private void readObject(ObjectInputStream stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
         throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        stream.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
        if (serialVersionOnStream < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
            // Didn't have additional int fields, reassign to use them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
            maximumIntegerDigits = maxIntegerDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            minimumIntegerDigits = minIntegerDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
            maximumFractionDigits = maxFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
            minimumFractionDigits = minFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
        if (minimumIntegerDigits > maximumIntegerDigits ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   961
            minimumFractionDigits > maximumFractionDigits ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            minimumIntegerDigits < 0 || minimumFractionDigits < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            throw new InvalidObjectException("Digit count range invalid");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
        serialVersionOnStream = currentSerialVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
     * Write out the default serializable data, after first setting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
     * the <code>byte</code> fields such as <code>maxIntegerDigits</code> to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
     * equal to the <code>int</code> fields such as <code>maximumIntegerDigits</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
     * (or to <code>Byte.MAX_VALUE</code>, whichever is smaller), for compatibility
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
     * with the JDK 1.1 version of the stream format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   975
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   976
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   977
    private void writeObject(ObjectOutputStream stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
         throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
        maxIntegerDigits = (maximumIntegerDigits > Byte.MAX_VALUE) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   981
                           Byte.MAX_VALUE : (byte)maximumIntegerDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   982
        minIntegerDigits = (minimumIntegerDigits > Byte.MAX_VALUE) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
                           Byte.MAX_VALUE : (byte)minimumIntegerDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
        maxFractionDigits = (maximumFractionDigits > Byte.MAX_VALUE) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   985
                            Byte.MAX_VALUE : (byte)maximumFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
        minFractionDigits = (minimumFractionDigits > Byte.MAX_VALUE) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
                            Byte.MAX_VALUE : (byte)minimumFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
        stream.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   989
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   990
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
    // Constants used by factory methods to specify a style of format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
    private static final int NUMBERSTYLE = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
    private static final int CURRENCYSTYLE = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
    private static final int PERCENTSTYLE = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
    private static final int SCIENTIFICSTYLE = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
    private static final int INTEGERSTYLE = 4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
     * True if the grouping (i.e. thousands) separator is used when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * formatting and parsing numbers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
     * @see #isGroupingUsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
    private boolean groupingUsed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1008
     * The maximum number of digits allowed in the integer portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1009
     * number.  <code>maxIntegerDigits</code> must be greater than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1010
     * <code>minIntegerDigits</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
     * <strong>Note:</strong> This field exists only for serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     * compatibility with JDK 1.1.  In Java platform 2 v1.2 and higher, the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     * <code>int</code> field <code>maximumIntegerDigits</code> is used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     * When writing to a stream, <code>maxIntegerDigits</code> is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1016
     * <code>maximumIntegerDigits</code> or <code>Byte.MAX_VALUE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
     * whichever is smaller.  When reading from a stream, this field is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
     * only if <code>serialVersionOnStream</code> is less than 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
     * @see #getMaximumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
    private byte    maxIntegerDigits = 40;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
     * The minimum number of digits allowed in the integer portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
     * number.  <code>minimumIntegerDigits</code> must be less than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
     * <code>maximumIntegerDigits</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
     * <strong>Note:</strong> This field exists only for serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
     * compatibility with JDK 1.1.  In Java platform 2 v1.2 and higher, the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
     * <code>int</code> field <code>minimumIntegerDigits</code> is used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
     * When writing to a stream, <code>minIntegerDigits</code> is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
     * <code>minimumIntegerDigits</code> or <code>Byte.MAX_VALUE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
     * whichever is smaller.  When reading from a stream, this field is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
     * only if <code>serialVersionOnStream</code> is less than 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
     * @see #getMinimumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
    private byte    minIntegerDigits = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     * The maximum number of digits allowed in the fractional portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
     * number.  <code>maximumFractionDigits</code> must be greater than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
     * <code>minimumFractionDigits</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
     * <strong>Note:</strong> This field exists only for serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
     * compatibility with JDK 1.1.  In Java platform 2 v1.2 and higher, the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
     * <code>int</code> field <code>maximumFractionDigits</code> is used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
     * When writing to a stream, <code>maxFractionDigits</code> is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
     * <code>maximumFractionDigits</code> or <code>Byte.MAX_VALUE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
     * whichever is smaller.  When reading from a stream, this field is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
     * only if <code>serialVersionOnStream</code> is less than 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
     * @see #getMaximumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
    private byte    maxFractionDigits = 3;    // invariant, >= minFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
     * The minimum number of digits allowed in the fractional portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
     * number.  <code>minimumFractionDigits</code> must be less than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
     * <code>maximumFractionDigits</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
     * <strong>Note:</strong> This field exists only for serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
     * compatibility with JDK 1.1.  In Java platform 2 v1.2 and higher, the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
     * <code>int</code> field <code>minimumFractionDigits</code> is used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     * When writing to a stream, <code>minFractionDigits</code> is set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     * <code>minimumFractionDigits</code> or <code>Byte.MAX_VALUE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     * whichever is smaller.  When reading from a stream, this field is used
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     * only if <code>serialVersionOnStream</code> is less than 1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
     * @see #getMinimumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
    private byte    minFractionDigits = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
     * True if this format will parse numbers as integers only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
     * @see #isParseIntegerOnly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
    private boolean parseIntegerOnly = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
    // new fields for 1.2.  byte is too small for integer digits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     * The maximum number of digits allowed in the integer portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
     * number.  <code>maximumIntegerDigits</code> must be greater than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     * <code>minimumIntegerDigits</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
     * @see #getMaximumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1098
    private int    maximumIntegerDigits = 40;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     * The minimum number of digits allowed in the integer portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
     * number.  <code>minimumIntegerDigits</code> must be less than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1103
     * <code>maximumIntegerDigits</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
     * @see #getMinimumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
    private int    minimumIntegerDigits = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
     * The maximum number of digits allowed in the fractional portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
     * number.  <code>maximumFractionDigits</code> must be greater than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     * <code>minimumFractionDigits</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     * @see #getMaximumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
    private int    maximumFractionDigits = 3;    // invariant, >= minFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1121
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
     * The minimum number of digits allowed in the fractional portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
     * number.  <code>minimumFractionDigits</code> must be less than or equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
     * <code>maximumFractionDigits</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
     * @see #getMinimumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
    private int    minimumFractionDigits = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
    static final int currentSerialVersion = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     * Describes the version of <code>NumberFormat</code> present on the stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     * Possible values are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1138
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1139
     * <li><b>0</b> (or uninitialized): the JDK 1.1 version of the stream format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
     *     In this version, the <code>int</code> fields such as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     *     <code>maximumIntegerDigits</code> were not present, and the <code>byte</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
     *     fields such as <code>maxIntegerDigits</code> are used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     * <li><b>1</b>: the 1.2 version of the stream format.  The values of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     *     <code>byte</code> fields such as <code>maxIntegerDigits</code> are ignored,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     *     and the <code>int</code> fields such as <code>maximumIntegerDigits</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
     *     are used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
     * When streaming out a <code>NumberFormat</code>, the most recent format
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     * (corresponding to the highest allowable <code>serialVersionOnStream</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     * is always written.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
    private int serialVersionOnStream = currentSerialVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
    // Removed "implements Cloneable" clause.  Needs to update serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
    // ID for backward compatibility.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
    static final long serialVersionUID = -2308460125733713944L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1161
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1162
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
    // class for AttributedCharacterIterator attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     * Defines constants that are used as attribute keys in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
     * <code>AttributedCharacterIterator</code> returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
     * from <code>NumberFormat.formatToCharacterIterator</code> and as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
     * field identifiers in <code>FieldPosition</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1173
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
    public static class Field extends Format.Field {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
        // Proclaim serial compatibility with 1.4 FCS
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
        private static final long serialVersionUID = 7494728892700160890L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
        // table of all instances in this class, used by readResolve
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 7668
diff changeset
  1180
        private static final Map<String, Field> instanceMap = new HashMap<>(11);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1183
         * Creates a Field instance with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
         * name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
         * @param name Name of the attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
        protected Field(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
            super(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
            if (this.getClass() == NumberFormat.Field.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
                instanceMap.put(name, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
         * Resolves instances being deserialized to the predefined constants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
         * @throws InvalidObjectException if the constant could not be resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
         * @return resolved NumberFormat.Field constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
         */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
  1201
        @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
        protected Object readResolve() throws InvalidObjectException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
            if (this.getClass() != NumberFormat.Field.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
                throw new InvalidObjectException("subclass didn't correctly implement readResolve");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
            Object instance = instanceMap.get(getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
            if (instance != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
                return instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1210
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1211
                throw new InvalidObjectException("unknown attribute name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1212
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
         * Constant identifying the integer field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
        public static final Field INTEGER = new Field("integer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
         * Constant identifying the fraction field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
        public static final Field FRACTION = new Field("fraction");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
         * Constant identifying the exponent field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
        public static final Field EXPONENT = new Field("exponent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
         * Constant identifying the decimal separator field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
        public static final Field DECIMAL_SEPARATOR =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
                            new Field("decimal separator");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
         * Constant identifying the sign field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
        public static final Field SIGN = new Field("sign");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1241
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
         * Constant identifying the grouping separator field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
        public static final Field GROUPING_SEPARATOR =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
                            new Field("grouping separator");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
         * Constant identifying the exponent symbol field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
        public static final Field EXPONENT_SYMBOL = new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
                            Field("exponent symbol");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1252
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
         * Constant identifying the percent field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
        public static final Field PERCENT = new Field("percent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
         * Constant identifying the permille field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
        public static final Field PERMILLE = new Field("per mille");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
         * Constant identifying the currency field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
        public static final Field CURRENCY = new Field("currency");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
         * Constant identifying the exponent sign field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
        public static final Field EXPONENT_SIGN = new Field("exponent sign");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
}