src/java.base/share/classes/java/text/NumberFormat.java
author jboes
Tue, 24 Sep 2019 09:43:43 +0100
changeset 58288 48e480e56aad
parent 58242 94bb65cb37d3
child 58679 9c3209ff7550
permissions -rw-r--r--
8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base Summary: Minor coding style update of javadoc tag in any file in java.base Reviewed-by: bchristi, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
54206
003cc64366da 8220249: fix headings in java.compiler
jjg
parents: 52869
diff changeset
     2
 * Copyright (c) 1996, 2019, 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.Locale;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.util.Map;
52869
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
    52
import java.util.Objects;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.util.concurrent.atomic.AtomicInteger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.util.concurrent.atomic.AtomicLong;
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
    55
import sun.util.locale.provider.LocaleProviderAdapter;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
    56
import sun.util.locale.provider.LocaleServiceProviderPool;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
/**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    59
 * {@code NumberFormat} is the abstract base class for all number
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * formats. This class provides the interface for formatting and parsing
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    61
 * numbers. {@code NumberFormat} also provides methods for determining
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * which locales have number formats, and what their names are.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <p>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    65
 * {@code NumberFormat} helps you to format and parse numbers for any locale.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * Your code can be completely independent of the locale conventions for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * decimal points, thousands-separators, or even the particular decimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * digits used, or whether the number format is even decimal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * To format a number for the current Locale, use one of the factory
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * class methods:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <blockquote>
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    74
 * <pre>{@code
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    75
 * myString = NumberFormat.getInstance().format(myNumber);
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    76
 * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * If you are formatting multiple numbers, it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * more efficient to get the format and use it multiple times so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * the system doesn't have to fetch the information about the local
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * language and country conventions multiple times.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <blockquote>
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    83
 * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * NumberFormat nf = NumberFormat.getInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * for (int i = 0; i < myNumber.length; ++i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *     output.println(nf.format(myNumber[i]) + "; ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * }
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    88
 * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 * </blockquote>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * To format a number for a different Locale, specify it in the
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
    91
 * call to {@code getInstance}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * <blockquote>
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    93
 * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * NumberFormat nf = NumberFormat.getInstance(Locale.FRENCH);
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
    95
 * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * </blockquote>
48251
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 48026
diff changeset
    97
 *
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 48026
diff changeset
    98
 * <p>If the locale contains "nu" (numbers) and/or "rg" (region override)
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 48026
diff changeset
    99
 * <a href="../util/Locale.html#def_locale_extension">Unicode extensions</a>,
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 48026
diff changeset
   100
 * the decimal digits, and/or the country used for formatting are overridden.
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 48026
diff changeset
   101
 * If both "nu" and "rg" are specified, the decimal digits from the "nu"
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 48026
diff changeset
   102
 * extension supersedes the implicit one from the "rg" extension.
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 48026
diff changeset
   103
 *
57148c79bd75 8176841: Additional Unicode Language-Tag Extensions
naoto
parents: 48026
diff changeset
   104
 * <p>You can also use a {@code NumberFormat} to parse numbers:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * <blockquote>
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   106
 * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 * myNumber = nf.parse(myString);
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   108
 * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 * </blockquote>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   110
 * Use {@code getInstance} or {@code getNumberInstance} to get the
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   111
 * normal number format. Use {@code getIntegerInstance} to get an
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   112
 * integer number format. Use {@code getCurrencyInstance} to get the
52869
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   113
 * currency number format. Use {@code getCompactNumberInstance} to get the
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   114
 * compact number format to format a number in shorter form. For example,
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   115
 * {@code 2000} can be formatted as {@code "2K"} in
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   116
 * {@link java.util.Locale#US US locale}. Use {@code getPercentInstance}
52869
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   117
 * to get a format for displaying percentages. With this format, a fraction
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   118
 * like 0.53 is displayed as 53%.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * You can also control the display of numbers with such methods as
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   122
 * {@code setMinimumFractionDigits}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * If you want even more control over the format or parsing,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 * or want to give your users more control,
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   125
 * you can try casting the {@code NumberFormat} you get from the factory methods
52869
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   126
 * to a {@code DecimalFormat} or {@code CompactNumberFormat} depending on
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   127
 * the factory method used. This will work for the vast majority of locales;
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   128
 * just remember to put it in a {@code try} block in case you encounter
52869
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   129
 * an unusual one.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
 * NumberFormat and DecimalFormat are designed such that some controls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
 * work for formatting and others work for parsing.  The following is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
 * the detailed description for each these control methods,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
 * setParseIntegerOnly : only affects parsing, e.g.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   137
 * 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
   138
 * if false, "3456.78" &rarr; 3456.78 (and leaves the parse position just after index 8)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
 * This is independent of formatting.  If you want to not show a decimal point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
 * where there might be no digits after the decimal point, use
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
 * setDecimalSeparatorAlwaysShown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
 * setDecimalSeparatorAlwaysShown : only affects formatting, and only where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
 * there might be no digits after the decimal point, such as with a pattern
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
 * like "#,##0.##", e.g.,
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   146
 * if true,  3456.00 &rarr; "3,456."
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   147
 * if false, 3456.00 &rarr; "3456"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
 * This is independent of parsing.  If you want parsing to stop at the decimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
 * point, use setParseIntegerOnly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
 * <p>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   152
 * You can also use forms of the {@code parse} and {@code format}
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   153
 * methods with {@code ParsePosition} and {@code FieldPosition} to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
 * allow you to:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
 * <li> progressively parse through pieces of a string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
 * <li> align the decimal point and other areas
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
 * For example, you can align numbers in two ways:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
 * <ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
 * <li> If you are using a monospaced font with spacing for alignment,
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   162
 *      you can pass the {@code FieldPosition} in your format call, with
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   163
 *      {@code field} = {@code INTEGER_FIELD}. On output,
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   164
 *      {@code getEndIndex} will be set to the offset between the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
 *      last character of the integer and the decimal. Add
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
 *      (desiredSpaceCount - getEndIndex) spaces at the front of the string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
 * <li> If you are using proportional fonts,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
 *      instead of padding with spaces, measure the width
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   170
 *      of the string in pixels from the start to {@code getEndIndex}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
 *      Then move the pen by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
 *      (desiredPixelWidth - widthToAlignmentPoint) before drawing the text.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
 *      It also works where there is no decimal, but possibly additional
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
 *      characters at the end, e.g., with parentheses in negative
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
 *      numbers: "(12)" for -12.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
 * </ol>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
 *
54206
003cc64366da 8220249: fix headings in java.compiler
jjg
parents: 52869
diff changeset
   178
 * <h2><a id="synchronization">Synchronization</a></h2>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
 * Number formats are generally not synchronized.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
 * It is recommended to create separate format instances for each thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
 * If multiple threads access a format concurrently, it must be synchronized
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
 * externally.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
 *
43011
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   186
 * @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
   187
 * {@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
   188
 * {@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
   189
 * {@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
   190
 * 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
   191
 * {@code NullPointerException}.
36edf207e84c 8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents: 34328
diff changeset
   192
 *
47016
49f2da5b2ea3 8186713: Document default rounding mode in NumberFormat
nishjain
parents: 45434
diff changeset
   193
 * <p>
49f2da5b2ea3 8186713: Document default rounding mode in NumberFormat
nishjain
parents: 45434
diff changeset
   194
 * The default implementation provides rounding modes defined
49f2da5b2ea3 8186713: Document default rounding mode in NumberFormat
nishjain
parents: 45434
diff changeset
   195
 * in {@link java.math.RoundingMode} for formatting numbers. It
49f2da5b2ea3 8186713: Document default rounding mode in NumberFormat
nishjain
parents: 45434
diff changeset
   196
 * uses the {@linkplain java.math.RoundingMode#HALF_EVEN
49f2da5b2ea3 8186713: Document default rounding mode in NumberFormat
nishjain
parents: 45434
diff changeset
   197
 * round half-even algorithm}. To change the rounding mode use
49f2da5b2ea3 8186713: Document default rounding mode in NumberFormat
nishjain
parents: 45434
diff changeset
   198
 * {@link #setRoundingMode(java.math.RoundingMode) setRoundingMode}.
49f2da5b2ea3 8186713: Document default rounding mode in NumberFormat
nishjain
parents: 45434
diff changeset
   199
 * The {@code NumberFormat} returned by the static factory methods is
49f2da5b2ea3 8186713: Document default rounding mode in NumberFormat
nishjain
parents: 45434
diff changeset
   200
 * configured to round floating point numbers using half-even
49f2da5b2ea3 8186713: Document default rounding mode in NumberFormat
nishjain
parents: 45434
diff changeset
   201
 * rounding (see {@link java.math.RoundingMode#HALF_EVEN
49f2da5b2ea3 8186713: Document default rounding mode in NumberFormat
nishjain
parents: 45434
diff changeset
   202
 * RoundingMode.HALF_EVEN}) for formatting.
49f2da5b2ea3 8186713: Document default rounding mode in NumberFormat
nishjain
parents: 45434
diff changeset
   203
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
 * @see          DecimalFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
 * @see          ChoiceFormat
52869
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   206
 * @see          CompactNumberFormat
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
 * @author       Mark Davis
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
 * @author       Helena Shih
45434
4582657c7260 8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents: 44844
diff changeset
   209
 * @since 1.1
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
public abstract class NumberFormat extends Format  {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * Field constant used to construct a FieldPosition object. Signifies that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * the position of the integer part of a formatted number should be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * @see java.text.FieldPosition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    public static final int INTEGER_FIELD = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * Field constant used to construct a FieldPosition object. Signifies that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * the position of the fraction part of a formatted number should be returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @see java.text.FieldPosition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    public static final int FRACTION_FIELD = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * Sole constructor.  (For invocation by subclass constructors, typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * implicit.)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    protected NumberFormat() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * Formats a number and appends the resulting text to the given string
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * The number can be of any subclass of {@link java.lang.Number}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * This implementation extracts the number's value using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * {@link java.lang.Number#longValue()} for all integral type values that
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   241
     * can be converted to {@code long} without loss of information,
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   242
     * including {@code BigInteger} values with a
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * {@link java.math.BigInteger#bitLength() bit length} of less than 64,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * and {@link java.lang.Number#doubleValue()} for all other types. It
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * then calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * {@link #format(long,java.lang.StringBuffer,java.text.FieldPosition)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * or {@link #format(double,java.lang.StringBuffer,java.text.FieldPosition)}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * This may result in loss of magnitude information and precision for
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   249
     * {@code BigInteger} and {@code BigDecimal} values.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     * @param number     the number to format
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   251
     * @param toAppendTo the {@code StringBuffer} to which the formatted
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *                   text is to be appended
48026
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   253
     * @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
   254
     *                   returned string. For example, for formatting a number
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   255
     *                   {@code 1234567.89} in {@code Locale.US} locale,
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   256
     *                   if the given {@code fieldPosition} is
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   257
     *                   {@link NumberFormat#INTEGER_FIELD}, the begin index
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   258
     *                   and end index of {@code fieldPosition} will be set
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   259
     *                   to 0 and 9, respectively for the output string
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   260
     *                   {@code 1,234,567.89}.
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   261
     * @return           the value passed in as {@code toAppendTo}
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   262
     * @throws           IllegalArgumentException if {@code number} is
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   263
     *                   null or not an instance of {@code Number}.
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   264
     * @throws           NullPointerException if {@code toAppendTo} or
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   265
     *                   {@code pos} is null
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   266
     * @throws           ArithmeticException if rounding is needed with rounding
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *                   mode being set to RoundingMode.UNNECESSARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @see              java.text.FieldPosition
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   270
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    public StringBuffer format(Object number,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                               StringBuffer toAppendTo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                               FieldPosition pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        if (number instanceof Long || number instanceof Integer ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            number instanceof Short || number instanceof Byte ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            number instanceof AtomicInteger || number instanceof AtomicLong ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            (number instanceof BigInteger &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
             ((BigInteger)number).bitLength() < 64)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            return format(((Number)number).longValue(), toAppendTo, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        } else if (number instanceof Number) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            return format(((Number)number).doubleValue(), toAppendTo, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            throw new IllegalArgumentException("Cannot format given Object as a Number");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    /**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   288
     * Parses text from a string to produce a {@code Number}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * The method attempts to parse text starting at the index given by
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   291
     * {@code pos}.
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   292
     * If parsing succeeds, then the index of {@code pos} is updated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * to the index after the last character used (parsing does not necessarily
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * use all characters up to the end of the string), and the parsed
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   295
     * number is returned. The updated {@code pos} can be used to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * indicate the starting point for the next call to this method.
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   297
     * If an error occurs, then the index of {@code pos} is not
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   298
     * changed, the error index of {@code pos} is set to the index of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * the character where the error occurred, and null is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * See the {@link #parse(String, ParsePosition)} method for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * on number parsing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   304
     * @param source A {@code String}, part of which should be parsed.
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   305
     * @param pos A {@code ParsePosition} object with index and error
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     *            index information as described above.
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   307
     * @return A {@code Number} parsed from the string. In case of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *         error, returns null.
34328
0534cb944d0e 8073211: javadoc of Format parseObject methods should specify NullPointerExceptions
okutsu
parents: 32649
diff changeset
   309
     * @throws NullPointerException if {@code source} or {@code pos} is null.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   311
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    public final Object parseObject(String source, ParsePosition pos) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        return parse(source, pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * Specialization of format.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   318
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   319
     * @param number the double number to format
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   320
     * @return the formatted String
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   321
     * @throws           ArithmeticException if rounding is needed with rounding
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *                   mode being set to RoundingMode.UNNECESSARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @see java.text.Format#format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    public final String format(double number) {
14015
f771d5fb3b27 7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents: 13583
diff changeset
   326
        // 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
   327
        String result = fastFormat(number);
f771d5fb3b27 7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents: 13583
diff changeset
   328
        if (result != null)
f771d5fb3b27 7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents: 13583
diff changeset
   329
            return result;
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
        return format(number, new StringBuffer(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                      DontCareFieldPosition.INSTANCE).toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
14015
f771d5fb3b27 7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents: 13583
diff changeset
   335
    /*
f771d5fb3b27 7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents: 13583
diff changeset
   336
     * 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
   337
     * Default implem always returns null.
f771d5fb3b27 7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents: 13583
diff changeset
   338
     */
f771d5fb3b27 7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents: 13583
diff changeset
   339
    String fastFormat(double number) { return null; }
f771d5fb3b27 7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents: 13583
diff changeset
   340
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * Specialization of format.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   343
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   344
     * @param number the long number to format
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   345
     * @return the formatted String
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   346
     * @throws           ArithmeticException if rounding is needed with rounding
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     *                   mode being set to RoundingMode.UNNECESSARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * @see java.text.Format#format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
    public final String format(long number) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
        return format(number, new StringBuffer(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                      DontCareFieldPosition.INSTANCE).toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * Specialization of format.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   357
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   358
     * @param number     the double number to format
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   359
     * @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
   360
     *                   appended
48026
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   361
     * @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
   362
     *                   returned string. For example, for formatting a number
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   363
     *                   {@code 1234567.89} in {@code Locale.US} locale,
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   364
     *                   if the given {@code fieldPosition} is
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   365
     *                   {@link NumberFormat#INTEGER_FIELD}, the begin index
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   366
     *                   and end index of {@code fieldPosition} will be set
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   367
     *                   to 0 and 9, respectively for the output string
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   368
     *                   {@code 1,234,567.89}.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   369
     * @return the formatted StringBuffer
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   370
     * @throws           ArithmeticException if rounding is needed with rounding
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *                   mode being set to RoundingMode.UNNECESSARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @see java.text.Format#format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    public abstract StringBuffer format(double number,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                                        StringBuffer toAppendTo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                                        FieldPosition pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * Specialization of format.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   380
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   381
     * @param number     the long number to format
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   382
     * @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
   383
     *                   appended
48026
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   384
     * @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
   385
     *                   returned string. For example, for formatting a number
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   386
     *                   {@code 123456789} in {@code Locale.US} locale,
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   387
     *                   if the given {@code fieldPosition} is
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   388
     *                   {@link NumberFormat#INTEGER_FIELD}, the begin index
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   389
     *                   and end index of {@code fieldPosition} will be set
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   390
     *                   to 0 and 11, respectively for the output string
89deac44e515 6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents: 47216
diff changeset
   391
     *                   {@code 123,456,789}.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   392
     * @return the formatted StringBuffer
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   393
     * @throws           ArithmeticException if rounding is needed with rounding
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     *                   mode being set to RoundingMode.UNNECESSARY
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @see java.text.Format#format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    public abstract StringBuffer format(long number,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                                        StringBuffer toAppendTo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                                        FieldPosition pos);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
   /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
     * Returns a Long if possible (e.g., within the range [Long.MIN_VALUE,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
     * Long.MAX_VALUE] and with no decimals), otherwise a Double.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * If IntegerOnly is set, will stop at a decimal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * point (or equivalent; e.g., for rational numbers "1 2/3", will stop
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * after the 1).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * Does not throw an exception; if no object can be parsed, index is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * unchanged!
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   409
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   410
     * @param source the String to parse
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   411
     * @param parsePosition the parse position
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   412
     * @return the parsed value
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @see java.text.NumberFormat#isParseIntegerOnly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * @see java.text.Format#parseObject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    public abstract Number parse(String source, ParsePosition parsePosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * Parses text from the beginning of the given string to produce a number.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * The method may not use the entire text of the given string.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * See the {@link #parse(String, ParsePosition)} method for more information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * on number parsing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     *
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   425
     * @param source A {@code String} whose beginning should be parsed.
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   426
     * @return A {@code Number} parsed from the string.
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   427
     * @throws    ParseException if the beginning of the specified string
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *            cannot be parsed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    public Number parse(String source) throws ParseException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        ParsePosition parsePosition = new ParsePosition(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        Number result = parse(source, parsePosition);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
        if (parsePosition.index == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
            throw new ParseException("Unparseable number: \"" + source + "\"",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                                     parsePosition.errorIndex);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * Returns true if this format will parse numbers as integers only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * For example in the English locale, with ParseIntegerOnly true, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * string "1234." would be parsed as the integer value 1234 and parsing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * 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
   445
     * by the parse operation is locale dependent and determined by sub-classes
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * of NumberFormat.
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
     * @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
   449
     *         {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    public boolean isParseIntegerOnly() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        return parseIntegerOnly;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * 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
   457
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   458
     * @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
   459
     *              {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * @see #isParseIntegerOnly
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    public void setParseIntegerOnly(boolean value) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        parseIntegerOnly = value;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    //============== Locale Stuff =====================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    /**
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   469
     * 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
   470
     * {@link java.util.Locale.Category#FORMAT FORMAT} locale.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * This is the same as calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * {@link #getNumberInstance() getNumberInstance()}.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   473
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   474
     * @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
   475
     * formatting
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   477
    public static final NumberFormat getInstance() {
52869
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   478
        return getInstance(Locale.getDefault(Locale.Category.FORMAT), null, NUMBERSTYLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * Returns a general-purpose number format for the specified locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * This is the same as calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * {@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
   485
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   486
     * @param inLocale the desired locale
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   487
     * @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
   488
     * formatting
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
    public static NumberFormat getInstance(Locale inLocale) {
52869
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   491
        return getInstance(inLocale, null, NUMBERSTYLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    /**
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   495
     * 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
   496
     * {@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
   497
     * <p>This is equivalent to calling
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   498
     * {@link #getNumberInstance(Locale)
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   499
     *     getNumberInstance(Locale.getDefault(Locale.Category.FORMAT))}.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   500
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   501
     * @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
   502
     * formatting
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   503
     * @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
   504
     * @see java.util.Locale.Category#FORMAT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   506
    public static final NumberFormat getNumberInstance() {
52869
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   507
        return getInstance(Locale.getDefault(Locale.Category.FORMAT), null, NUMBERSTYLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * 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
   512
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   513
     * @param inLocale the desired locale
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   514
     * @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
   515
     * formatting
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    public static NumberFormat getNumberInstance(Locale inLocale) {
52869
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   518
        return getInstance(inLocale, null, NUMBERSTYLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    /**
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   522
     * 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
   523
     * {@link java.util.Locale.Category#FORMAT FORMAT} locale. The
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * returned number format is configured to round floating point numbers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * to the nearest integer using half-even rounding (see {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     * java.math.RoundingMode#HALF_EVEN RoundingMode.HALF_EVEN}) for formatting,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * and to parse only the integer part of an input string (see {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * #isParseIntegerOnly isParseIntegerOnly}).
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   529
     * <p>This is equivalent to calling
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   530
     * {@link #getIntegerInstance(Locale)
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   531
     *     getIntegerInstance(Locale.getDefault(Locale.Category.FORMAT))}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * @see #getRoundingMode()
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   534
     * @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
   535
     * @see java.util.Locale.Category#FORMAT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * @return a number format for integer values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   539
    public static final NumberFormat getIntegerInstance() {
52869
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   540
        return getInstance(Locale.getDefault(Locale.Category.FORMAT), null, INTEGERSTYLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * Returns an integer number format for the specified locale. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * returned number format is configured to round floating point numbers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     * to the nearest integer using half-even rounding (see {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
     * java.math.RoundingMode#HALF_EVEN RoundingMode.HALF_EVEN}) for formatting,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     * and to parse only the integer part of an input string (see {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
     * #isParseIntegerOnly isParseIntegerOnly}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
     *
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   551
     * @param inLocale the desired locale
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
     * @see #getRoundingMode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
     * @return a number format for integer values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    public static NumberFormat getIntegerInstance(Locale inLocale) {
52869
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   557
        return getInstance(inLocale, null, INTEGERSTYLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
    /**
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   561
     * 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
   562
     * {@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
   563
     * <p>This is equivalent to calling
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   564
     * {@link #getCurrencyInstance(Locale)
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   565
     *     getCurrencyInstance(Locale.getDefault(Locale.Category.FORMAT))}.
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   566
     *
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   567
     * @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
   568
     * @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
   569
     * @see java.util.Locale.Category#FORMAT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   571
    public static final NumberFormat getCurrencyInstance() {
52869
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   572
        return getInstance(Locale.getDefault(Locale.Category.FORMAT), null, CURRENCYSTYLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
     * 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
   577
     *
57679
314e62bbdb16 8215181: Accounting currency format support
naoto
parents: 54206
diff changeset
   578
     * <p>If the specified locale contains the "{@code cf}" (
314e62bbdb16 8215181: Accounting currency format support
naoto
parents: 54206
diff changeset
   579
     * <a href="https://www.unicode.org/reports/tr35/tr35.html#UnicodeCurrencyFormatIdentifier">
314e62bbdb16 8215181: Accounting currency format support
naoto
parents: 54206
diff changeset
   580
     * currency format style</a>)
314e62bbdb16 8215181: Accounting currency format support
naoto
parents: 54206
diff changeset
   581
     * <a href="../util/Locale.html#def_locale_extension">Unicode extension</a>,
314e62bbdb16 8215181: Accounting currency format support
naoto
parents: 54206
diff changeset
   582
     * the returned currency format uses the style if it is available.
314e62bbdb16 8215181: Accounting currency format support
naoto
parents: 54206
diff changeset
   583
     * Otherwise, the style uses the default "{@code standard}" currency format.
314e62bbdb16 8215181: Accounting currency format support
naoto
parents: 54206
diff changeset
   584
     * For example, if the style designates "{@code account}", negative
314e62bbdb16 8215181: Accounting currency format support
naoto
parents: 54206
diff changeset
   585
     * currency amounts use a pair of parentheses in some locales.
314e62bbdb16 8215181: Accounting currency format support
naoto
parents: 54206
diff changeset
   586
     *
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   587
     * @param inLocale the desired locale
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   588
     * @return the {@code NumberFormat} instance for currency formatting
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
    public static NumberFormat getCurrencyInstance(Locale inLocale) {
52869
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   591
        return getInstance(inLocale, null, CURRENCYSTYLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
    /**
16010
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   595
     * 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
   596
     * {@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
   597
     * <p>This is equivalent to calling
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   598
     * {@link #getPercentInstance(Locale)
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   599
     *     getPercentInstance(Locale.getDefault(Locale.Category.FORMAT))}.
2727163b5df5 7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents: 15260
diff changeset
   600
     *
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   601
     * @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
   602
     * @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
   603
     * @see java.util.Locale.Category#FORMAT
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 25859
diff changeset
   605
    public static final NumberFormat getPercentInstance() {
52869
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   606
        return getInstance(Locale.getDefault(Locale.Category.FORMAT), null, PERCENTSTYLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
     * 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
   611
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   612
     * @param inLocale the desired locale
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   613
     * @return the {@code NumberFormat} instance for percentage formatting
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    public static NumberFormat getPercentInstance(Locale inLocale) {
52869
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   616
        return getInstance(inLocale, null, PERCENTSTYLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
     * Returns a scientific format for the current default locale.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    /*public*/ final static NumberFormat getScientificInstance() {
52869
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   623
        return getInstance(Locale.getDefault(Locale.Category.FORMAT), null, SCIENTIFICSTYLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
     * 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
   628
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   629
     * @param inLocale the desired locale
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    /*public*/ static NumberFormat getScientificInstance(Locale inLocale) {
52869
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   632
        return getInstance(inLocale, null, SCIENTIFICSTYLE);
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   633
    }
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   634
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   635
    /**
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   636
     * Returns a compact number format for the default
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   637
     * {@link java.util.Locale.Category#FORMAT FORMAT} locale with
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   638
     * {@link NumberFormat.Style#SHORT "SHORT"} format style.
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   639
     *
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   640
     * @return A {@code NumberFormat} instance for compact number
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   641
     *         formatting
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   642
     *
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   643
     * @see CompactNumberFormat
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   644
     * @see NumberFormat.Style
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   645
     * @see java.util.Locale#getDefault(java.util.Locale.Category)
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   646
     * @see java.util.Locale.Category#FORMAT
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   647
     * @since 12
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   648
     */
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   649
    public static NumberFormat getCompactNumberInstance() {
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   650
        return getInstance(Locale.getDefault(
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   651
                Locale.Category.FORMAT), NumberFormat.Style.SHORT, COMPACTSTYLE);
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   652
    }
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   653
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   654
    /**
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   655
     * Returns a compact number format for the specified {@link java.util.Locale locale}
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   656
     * and {@link NumberFormat.Style formatStyle}.
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   657
     *
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   658
     * @param locale the desired locale
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   659
     * @param formatStyle the style for formatting a number
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   660
     * @return A {@code NumberFormat} instance for compact number
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   661
     *         formatting
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   662
     * @throws NullPointerException if {@code locale} or {@code formatStyle}
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   663
     *                              is {@code null}
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   664
     *
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   665
     * @see CompactNumberFormat
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   666
     * @see NumberFormat.Style
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   667
     * @see java.util.Locale
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   668
     * @since 12
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   669
     */
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   670
    public static NumberFormat getCompactNumberInstance(Locale locale,
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   671
            NumberFormat.Style formatStyle) {
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   672
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   673
        Objects.requireNonNull(locale);
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   674
        Objects.requireNonNull(formatStyle);
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   675
        return getInstance(locale, formatStyle, COMPACTSTYLE);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
     * Returns an array of all locales for which the
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   680
     * {@code get*Instance} methods of this class can return
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
     * localized instances.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
     * The returned array represents the union of locales supported by the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
     * runtime and by installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
     * {@link java.text.spi.NumberFormatProvider NumberFormatProvider} implementations.
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   685
     * It must contain at least a {@code Locale} instance equal to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
     * {@link java.util.Locale#US Locale.US}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
     * @return An array of locales for which localized
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   689
     *         {@code NumberFormat} instances are available.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
    public static Locale[] getAvailableLocales() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
        LocaleServiceProviderPool pool =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   693
            LocaleServiceProviderPool.getPool(NumberFormatProvider.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   694
        return pool.getAvailableLocales();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   695
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
    /**
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   698
     * Overrides hashCode.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   700
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
    public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        return maximumIntegerDigits * 37 + maxFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   703
        // just enough fields for a reasonable distribution
90ce3da70b43 Initial load
duke
parents:
diff changeset
   704
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   705
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
    /**
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   707
     * Overrides equals.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   708
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   709
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   710
    public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   711
        if (obj == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   713
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   714
        if (this == obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   715
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   716
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   717
        if (getClass() != obj.getClass()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
        NumberFormat other = (NumberFormat) obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
        return (maximumIntegerDigits == other.maximumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            && minimumIntegerDigits == other.minimumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
            && maximumFractionDigits == other.maximumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   724
            && minimumFractionDigits == other.minimumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   725
            && groupingUsed == other.groupingUsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   726
            && parseIntegerOnly == other.parseIntegerOnly);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   727
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
    /**
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   730
     * Overrides Cloneable.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
     */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   732
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   733
    public Object clone() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   734
        NumberFormat other = (NumberFormat) super.clone();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   735
        return other;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
     * Returns true if grouping is used in this format. For example, in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
     * English locale, with grouping on, the number 1234567 might be formatted
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
     * 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
   742
     * 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
   743
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   744
     * @return {@code true} if grouping is used;
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   745
     *         {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
     * @see #setGroupingUsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   747
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   748
    public boolean isGroupingUsed() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   749
        return groupingUsed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   750
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   751
90ce3da70b43 Initial load
duke
parents:
diff changeset
   752
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
     * 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
   754
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   755
     * @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
   756
     *                 {@code false} otherwise
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
     * @see #isGroupingUsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    public void setGroupingUsed(boolean newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        groupingUsed = newValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
     * Returns the maximum number of digits allowed in the integer portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
     * number.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   766
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   767
     * @return the maximum number of digits
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * @see #setMaximumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
    public int getMaximumIntegerDigits() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
        return maximumIntegerDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
     * 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
   776
     * number. maximumIntegerDigits must be &ge; minimumIntegerDigits.  If the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
     * new value for maximumIntegerDigits is less than the current value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
     * of minimumIntegerDigits, then minimumIntegerDigits will also be set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
     * the new value.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   780
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
     * @param newValue the maximum number of integer digits to be shown; if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
     * less than zero, then zero is used. The concrete subclass may enforce an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
     * upper limit to this value appropriate to the numeric type being formatted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
     * @see #getMaximumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    public void setMaximumIntegerDigits(int newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
        maximumIntegerDigits = Math.max(0,newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
        if (minimumIntegerDigits > maximumIntegerDigits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
            minimumIntegerDigits = maximumIntegerDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
     * Returns the minimum number of digits allowed in the integer portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
     * number.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   796
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   797
     * @return the minimum number of digits
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
     * @see #setMinimumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
    public int getMinimumIntegerDigits() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
        return minimumIntegerDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   803
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
     * 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
   806
     * number. minimumIntegerDigits must be &le; maximumIntegerDigits.  If the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
     * new value for minimumIntegerDigits exceeds the current value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
     * of maximumIntegerDigits, then maximumIntegerDigits will also be set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
     * the new value
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   810
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
     * @param newValue the minimum number of integer digits to be shown; if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
     * less than zero, then zero is used. The concrete subclass may enforce an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
     * upper limit to this value appropriate to the numeric type being formatted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
     * @see #getMinimumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
    public void setMinimumIntegerDigits(int newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
        minimumIntegerDigits = Math.max(0,newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        if (minimumIntegerDigits > maximumIntegerDigits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
            maximumIntegerDigits = minimumIntegerDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   821
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   822
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
     * Returns the maximum number of digits allowed in the fraction portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
     * number.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   826
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   827
     * @return the maximum number of digits.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
     * @see #setMaximumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
    public int getMaximumFractionDigits() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
        return maximumFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
     * 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
   836
     * number. maximumFractionDigits must be &ge; minimumFractionDigits.  If the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
     * new value for maximumFractionDigits is less than the current value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
     * of minimumFractionDigits, then minimumFractionDigits will also be set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
     * the new value.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   840
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   841
     * @param newValue the maximum number of fraction digits to be shown; if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
     * less than zero, then zero is used. The concrete subclass may enforce an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
     * upper limit to this value appropriate to the numeric type being formatted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   844
     * @see #getMaximumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
    public void setMaximumFractionDigits(int newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
        maximumFractionDigits = Math.max(0,newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
        if (maximumFractionDigits < minimumFractionDigits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            minimumFractionDigits = maximumFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
     * Returns the minimum number of digits allowed in the fraction portion of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
     * number.
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   856
     *
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   857
     * @return the minimum number of digits
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
     * @see #setMinimumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
    public int getMinimumFractionDigits() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   861
        return minimumFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
     * 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
   866
     * number. minimumFractionDigits must be &le; maximumFractionDigits.  If the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
     * new value for minimumFractionDigits exceeds the current value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
     * of maximumFractionDigits, then maximumIntegerDigits will also be set to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
     * the new value
19054
a64012cb49d6 8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents: 16010
diff changeset
   870
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
     * @param newValue the minimum number of fraction digits to be shown; if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
     * less than zero, then zero is used. The concrete subclass may enforce an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
     * upper limit to this value appropriate to the numeric type being formatted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
     * @see #getMinimumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
    public void setMinimumFractionDigits(int newValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        minimumFractionDigits = Math.max(0,newValue);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   878
        if (maximumFractionDigits < minimumFractionDigits) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            maximumFractionDigits = minimumFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
     * Gets the currency used by this number format when formatting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
     * currency values. The initial value is derived in a locale dependent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
     * way. The returned value may be null if no valid
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
     * currency could be determined and no currency has been set using
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
     * {@link #setCurrency(java.util.Currency) setCurrency}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
     * The default implementation throws
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   891
     * {@code UnsupportedOperationException}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
     *
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   893
     * @return the currency used by this number format, or {@code null}
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   894
     * @throws    UnsupportedOperationException if the number format class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
     * doesn't implement currency formatting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
    public Currency getCurrency() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   899
        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   901
90ce3da70b43 Initial load
duke
parents:
diff changeset
   902
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
     * Sets the currency used by this number format when formatting
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
     * currency values. This does not update the minimum or maximum
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
     * number of fraction digits used by the number format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   907
     * The default implementation throws
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   908
     * {@code UnsupportedOperationException}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
     * @param currency the new currency to be used by this number format
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   911
     * @throws    UnsupportedOperationException if the number format class
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
     * doesn't implement currency formatting
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   913
     * @throws    NullPointerException if {@code currency} is null
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   914
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
    public void setCurrency(Currency currency) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   921
     * Gets the {@link java.math.RoundingMode} used in this NumberFormat.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
     * The default implementation of this method in NumberFormat
90ce3da70b43 Initial load
duke
parents:
diff changeset
   923
     * always throws {@link java.lang.UnsupportedOperationException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   924
     * Subclasses which handle different rounding modes should override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
     * this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   926
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   927
     * @throws    UnsupportedOperationException The default implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
     *     always throws this exception
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   929
     * @return The {@code RoundingMode} used for this NumberFormat.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
     * @see #setRoundingMode(RoundingMode)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   932
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   933
    public RoundingMode getRoundingMode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
     * Sets the {@link java.math.RoundingMode} used in this NumberFormat.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   939
     * The default implementation of this method in NumberFormat always
90ce3da70b43 Initial load
duke
parents:
diff changeset
   940
     * throws {@link java.lang.UnsupportedOperationException}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
     * Subclasses which handle different rounding modes should override
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
     * this method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 57956
diff changeset
   944
     * @throws    UnsupportedOperationException The default implementation
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
     *     always throws this exception
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   946
     * @throws    NullPointerException if {@code roundingMode} is null
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   947
     * @param roundingMode The {@code RoundingMode} to be used
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   948
     * @see #getRoundingMode()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   949
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   950
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   951
    public void setRoundingMode(RoundingMode roundingMode) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   952
        throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   953
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
    // =======================privates===============================
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
    private static NumberFormat getInstance(Locale desiredLocale,
52869
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   958
                                            Style formatStyle, int choice) {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   959
        LocaleProviderAdapter adapter;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   960
        adapter = LocaleProviderAdapter.getAdapter(NumberFormatProvider.class,
52869
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   961
                desiredLocale);
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   962
        NumberFormat numberFormat = getInstance(adapter, desiredLocale,
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   963
                formatStyle, choice);
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   964
        if (numberFormat == null) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   965
            numberFormat = getInstance(LocaleProviderAdapter.forJRE(),
52869
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   966
                    desiredLocale, formatStyle, choice);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
        }
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   968
        return numberFormat;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   969
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   971
    private static NumberFormat getInstance(LocaleProviderAdapter adapter,
52869
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   972
                                            Locale locale, Style formatStyle,
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   973
                                            int choice) {
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   974
        NumberFormatProvider provider = adapter.getNumberFormatProvider();
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   975
        NumberFormat numberFormat = null;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   976
        switch (choice) {
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   977
        case NUMBERSTYLE:
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   978
            numberFormat = provider.getNumberInstance(locale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   979
            break;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   980
        case PERCENTSTYLE:
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   981
            numberFormat = provider.getPercentInstance(locale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   982
            break;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   983
        case CURRENCYSTYLE:
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   984
            numberFormat = provider.getCurrencyInstance(locale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   985
            break;
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   986
        case INTEGERSTYLE:
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   987
            numberFormat = provider.getIntegerInstance(locale);
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   988
            break;
52869
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   989
        case COMPACTSTYLE:
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   990
            numberFormat = provider.getCompactNumberInstance(locale, formatStyle);
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
   991
            break;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
        }
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
   993
        return numberFormat;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   995
90ce3da70b43 Initial load
duke
parents:
diff changeset
   996
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
     * First, read in the default serializable data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
     *
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
   999
     * Then, if {@code serialVersionOnStream} is less than 1, indicating that
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
     * the stream was written by JDK 1.1,
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1001
     * set the {@code int} fields such as {@code maximumIntegerDigits}
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1002
     * to be equal to the {@code byte} fields such as {@code maxIntegerDigits},
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1003
     * since the {@code int} fields were not present in JDK 1.1.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1004
     * Finally, set serialVersionOnStream back to the maximum allowed value so that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1005
     * default serialization will work properly if this object is streamed out again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1006
     *
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1007
     * <p>If {@code minimumIntegerDigits} is greater than
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1008
     * {@code maximumIntegerDigits} or {@code minimumFractionDigits}
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1009
     * is greater than {@code maximumFractionDigits}, then the stream data
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1010
     * is invalid and this method throws an {@code InvalidObjectException}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
     * In addition, if any of these values is negative, then this method throws
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1012
     * an {@code InvalidObjectException}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1013
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1014
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1015
     */
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 57679
diff changeset
  1016
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
    private void readObject(ObjectInputStream stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
         throws IOException, ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
        stream.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
        if (serialVersionOnStream < 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
            // Didn't have additional int fields, reassign to use them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1023
            maximumIntegerDigits = maxIntegerDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1024
            minimumIntegerDigits = minIntegerDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1025
            maximumFractionDigits = maxFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1026
            minimumFractionDigits = minFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
        if (minimumIntegerDigits > maximumIntegerDigits ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
            minimumFractionDigits > maximumFractionDigits ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
            minimumIntegerDigits < 0 || minimumFractionDigits < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1031
            throw new InvalidObjectException("Digit count range invalid");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1032
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1033
        serialVersionOnStream = currentSerialVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1034
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
     * Write out the default serializable data, after first setting
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1038
     * the {@code byte} fields such as {@code maxIntegerDigits} to be
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1039
     * equal to the {@code int} fields such as {@code maximumIntegerDigits}
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1040
     * (or to {@code Byte.MAX_VALUE}, whichever is smaller), for compatibility
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
     * with the JDK 1.1 version of the stream format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1042
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
     */
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 57679
diff changeset
  1045
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
    private void writeObject(ObjectOutputStream stream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
         throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
        maxIntegerDigits = (maximumIntegerDigits > Byte.MAX_VALUE) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
                           Byte.MAX_VALUE : (byte)maximumIntegerDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
        minIntegerDigits = (minimumIntegerDigits > Byte.MAX_VALUE) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
                           Byte.MAX_VALUE : (byte)minimumIntegerDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
        maxFractionDigits = (maximumFractionDigits > Byte.MAX_VALUE) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
                            Byte.MAX_VALUE : (byte)maximumFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        minFractionDigits = (minimumFractionDigits > Byte.MAX_VALUE) ?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
                            Byte.MAX_VALUE : (byte)minimumFractionDigits;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        stream.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
    // Constants used by factory methods to specify a style of format.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
    private static final int NUMBERSTYLE = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
    private static final int CURRENCYSTYLE = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
    private static final int PERCENTSTYLE = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
    private static final int SCIENTIFICSTYLE = 3;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
    private static final int INTEGERSTYLE = 4;
52869
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1066
    private static final int COMPACTSTYLE = 5;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
     * True if the grouping (i.e. thousands) separator is used when
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
     * formatting and parsing numbers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1073
     * @see #isGroupingUsed
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1075
    private boolean groupingUsed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1076
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
     * The maximum number of digits allowed in the integer portion of a
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1079
     * number.  {@code maxIntegerDigits} must be greater than or equal to
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1080
     * {@code minIntegerDigits}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
     * <strong>Note:</strong> This field exists only for serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
     * compatibility with JDK 1.1.  In Java platform 2 v1.2 and higher, the new
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1084
     * {@code int} field {@code maximumIntegerDigits} is used instead.
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1085
     * When writing to a stream, {@code maxIntegerDigits} is set to
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1086
     * {@code maximumIntegerDigits} or {@code Byte.MAX_VALUE},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
     * whichever is smaller.  When reading from a stream, this field is used
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1088
     * only if {@code serialVersionOnStream} is less than 1.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
     * @see #getMaximumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1093
    private byte    maxIntegerDigits = 40;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1095
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
     * The minimum number of digits allowed in the integer portion of a
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1097
     * number.  {@code minimumIntegerDigits} must be less than or equal to
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1098
     * {@code maximumIntegerDigits}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
     * <strong>Note:</strong> This field exists only for serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
     * compatibility with JDK 1.1.  In Java platform 2 v1.2 and higher, the new
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1102
     * {@code int} field {@code minimumIntegerDigits} is used instead.
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1103
     * When writing to a stream, {@code minIntegerDigits} is set to
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1104
     * {@code minimumIntegerDigits} or {@code Byte.MAX_VALUE},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
     * whichever is smaller.  When reading from a stream, this field is used
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1106
     * only if {@code serialVersionOnStream} is less than 1.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1109
     * @see #getMinimumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
    private byte    minIntegerDigits = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
     * The maximum number of digits allowed in the fractional portion of a
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1115
     * number.  {@code maximumFractionDigits} must be greater than or equal to
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1116
     * {@code minimumFractionDigits}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1117
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1118
     * <strong>Note:</strong> This field exists only for serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1119
     * compatibility with JDK 1.1.  In Java platform 2 v1.2 and higher, the new
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1120
     * {@code int} field {@code maximumFractionDigits} is used instead.
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1121
     * When writing to a stream, {@code maxFractionDigits} is set to
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1122
     * {@code maximumFractionDigits} or {@code Byte.MAX_VALUE},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
     * whichever is smaller.  When reading from a stream, this field is used
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1124
     * only if {@code serialVersionOnStream} is less than 1.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1125
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1126
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1127
     * @see #getMaximumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
    private byte    maxFractionDigits = 3;    // invariant, >= minFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
     * The minimum number of digits allowed in the fractional portion of a
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1133
     * number.  {@code minimumFractionDigits} must be less than or equal to
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1134
     * {@code maximumFractionDigits}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1136
     * <strong>Note:</strong> This field exists only for serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1137
     * compatibility with JDK 1.1.  In Java platform 2 v1.2 and higher, the new
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1138
     * {@code int} field {@code minimumFractionDigits} is used instead.
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1139
     * When writing to a stream, {@code minFractionDigits} is set to
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1140
     * {@code minimumFractionDigits} or {@code Byte.MAX_VALUE},
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
     * whichever is smaller.  When reading from a stream, this field is used
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1142
     * only if {@code serialVersionOnStream} is less than 1.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1144
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1145
     * @see #getMinimumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1146
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1147
    private byte    minFractionDigits = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
     * True if this format will parse numbers as integers only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
     * @see #isParseIntegerOnly
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1154
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
    private boolean parseIntegerOnly = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1156
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1157
    // new fields for 1.2.  byte is too small for integer digits.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1160
     * The maximum number of digits allowed in the integer portion of a
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1161
     * number.  {@code maximumIntegerDigits} must be greater than or equal to
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1162
     * {@code minimumIntegerDigits}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
     * @see #getMaximumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1167
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1168
    private int    maximumIntegerDigits = 40;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
     * The minimum number of digits allowed in the integer portion of a
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1172
     * number.  {@code minimumIntegerDigits} must be less than or equal to
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1173
     * {@code maximumIntegerDigits}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1174
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
     * @see #getMinimumIntegerDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
    private int    minimumIntegerDigits = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1181
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1182
     * The maximum number of digits allowed in the fractional portion of a
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1183
     * number.  {@code maximumFractionDigits} must be greater than or equal to
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1184
     * {@code minimumFractionDigits}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1186
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
     * @see #getMaximumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1189
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1190
    private int    maximumFractionDigits = 3;    // invariant, >= minFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1191
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1193
     * The minimum number of digits allowed in the fractional portion of a
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1194
     * number.  {@code minimumFractionDigits} must be less than or equal to
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1195
     * {@code maximumFractionDigits}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
     * @see #getMinimumFractionDigits
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
    private int    minimumFractionDigits = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1202
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1203
    static final int currentSerialVersion = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1204
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1205
    /**
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1206
     * Describes the version of {@code NumberFormat} present on the stream.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
     * Possible values are:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
     * <li><b>0</b> (or uninitialized): the JDK 1.1 version of the stream format.
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1210
     *     In this version, the {@code int} fields such as
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1211
     *     {@code maximumIntegerDigits} were not present, and the {@code byte}
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1212
     *     fields such as {@code maxIntegerDigits} are used instead.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1213
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
     * <li><b>1</b>: the 1.2 version of the stream format.  The values of the
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1215
     *     {@code byte} fields such as {@code maxIntegerDigits} are ignored,
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1216
     *     and the {@code int} fields such as {@code maximumIntegerDigits}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
     *     are used instead.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
     * </ul>
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1219
     * When streaming out a {@code NumberFormat}, the most recent format
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1220
     * (corresponding to the highest allowable {@code serialVersionOnStream})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
     * is always written.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1222
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1223
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1224
     * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1226
    private int serialVersionOnStream = currentSerialVersion;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
    // Removed "implements Cloneable" clause.  Needs to update serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1229
    // ID for backward compatibility.
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 57679
diff changeset
  1230
    @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
    static final long serialVersionUID = -2308460125733713944L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1232
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1233
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1234
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1235
    // class for AttributedCharacterIterator attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1236
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1237
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
     * Defines constants that are used as attribute keys in the
58288
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1239
     * {@code AttributedCharacterIterator} returned
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1240
     * from {@code NumberFormat.formatToCharacterIterator} and as
48e480e56aad 8231186: Replace html tag <code>foo</code> with javadoc tag {@code foo} in java.base
jboes
parents: 58242
diff changeset
  1241
     * field identifiers in {@code FieldPosition}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1242
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1244
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1245
    public static class Field extends Format.Field {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
        // Proclaim serial compatibility with 1.4 FCS
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 57679
diff changeset
  1248
        @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1249
        private static final long serialVersionUID = 7494728892700160890L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1251
        // table of all instances in this class, used by readResolve
12848
da701d422d2c 7117230: clean up warnings in java.text
dbhole
parents: 7668
diff changeset
  1252
        private static final Map<String, Field> instanceMap = new HashMap<>(11);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1253
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
         * Creates a Field instance with the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
         * name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1257
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1258
         * @param name Name of the attribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1259
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
        protected Field(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
            super(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1262
            if (this.getClass() == NumberFormat.Field.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
                instanceMap.put(name, this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
         * Resolves instances being deserialized to the predefined constants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
         * @throws InvalidObjectException if the constant could not be resolved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1271
         * @return resolved NumberFormat.Field constant
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1272
         */
13583
dc0017b1a452 6336885: RFE: Locale Data Deployment Enhancements
naoto
parents: 12848
diff changeset
  1273
        @Override
57956
e0b8b019d2f5 8229997: Apply java.io.Serial annotations in java.base
darcy
parents: 57679
diff changeset
  1274
        @java.io.Serial
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
        protected Object readResolve() throws InvalidObjectException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
            if (this.getClass() != NumberFormat.Field.class) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1277
                throw new InvalidObjectException("subclass didn't correctly implement readResolve");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1278
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
            Object instance = instanceMap.get(getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
            if (instance != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
                return instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
                throw new InvalidObjectException("unknown attribute name");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1286
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1287
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1288
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1289
         * Constant identifying the integer field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1290
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1291
        public static final Field INTEGER = new Field("integer");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
         * Constant identifying the fraction field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1296
        public static final Field FRACTION = new Field("fraction");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1297
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1298
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1299
         * Constant identifying the exponent field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1300
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1301
        public static final Field EXPONENT = new Field("exponent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1304
         * Constant identifying the decimal separator field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1305
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
        public static final Field DECIMAL_SEPARATOR =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
                            new Field("decimal separator");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1308
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
         * Constant identifying the sign field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
        public static final Field SIGN = new Field("sign");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1313
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1314
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
         * Constant identifying the grouping separator field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
        public static final Field GROUPING_SEPARATOR =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
                            new Field("grouping separator");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1319
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1320
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
         * Constant identifying the exponent symbol field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
        public static final Field EXPONENT_SYMBOL = new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
                            Field("exponent symbol");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
         * Constant identifying the percent field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
        public static final Field PERCENT = new Field("percent");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1330
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
         * Constant identifying the permille field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        public static final Field PERMILLE = new Field("per mille");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1335
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1336
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
         * Constant identifying the currency field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1339
        public static final Field CURRENCY = new Field("currency");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1341
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
         * Constant identifying the exponent sign field.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1344
        public static final Field EXPONENT_SIGN = new Field("exponent sign");
52869
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1345
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1346
        /**
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1347
         * Constant identifying the prefix field.
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1348
         *
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1349
         * @since 12
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1350
         */
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1351
        public static final Field PREFIX = new Field("prefix");
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1352
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1353
        /**
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1354
         * Constant identifying the suffix field.
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1355
         *
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1356
         * @since 12
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1357
         */
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1358
        public static final Field SUFFIX = new Field("suffix");
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1359
    }
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1360
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1361
    /**
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1362
     * A number format style.
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1363
     * <p>
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1364
     * {@code Style} is an enum which represents the style for formatting
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1365
     * a number within a given {@code NumberFormat} instance.
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1366
     *
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1367
     * @see CompactNumberFormat
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1368
     * @see NumberFormat#getCompactNumberInstance(Locale, Style)
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1369
     * @since 12
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1370
     */
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1371
    public enum Style {
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1372
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1373
        /**
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1374
         * The {@code SHORT} number format style.
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1375
         */
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1376
        SHORT,
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1377
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1378
        /**
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1379
         * The {@code LONG} number format style.
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1380
         */
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1381
        LONG
c5c0db0b7c2f 8177552: Compact Number Formatting support
nishjain
parents: 48251
diff changeset
  1382
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1383
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1384
}