author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58603 | 2312d1a04c49 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
54206 | 2 |
* Copyright (c) 1996, 2019, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
/* |
|
27 |
* (C) Copyright Taligent, Inc. 1996, 1997 - All Rights Reserved |
|
28 |
* (C) Copyright IBM Corp. 1996 - 1998 - All Rights Reserved |
|
29 |
* |
|
30 |
* The original version of this source code and documentation is copyrighted |
|
31 |
* and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These |
|
32 |
* materials are provided under terms of a License Agreement between Taligent |
|
33 |
* and Sun. This technology is protected by multiple US and International |
|
34 |
* patents. This notice and attribution to Taligent may not be removed. |
|
35 |
* Taligent is a registered trademark of Taligent, Inc. |
|
36 |
* |
|
37 |
*/ |
|
38 |
||
39 |
package java.text; |
|
40 |
||
13583 | 41 |
import java.io.IOException; |
2 | 42 |
import java.io.InvalidObjectException; |
43 |
import java.io.ObjectInputStream; |
|
44 |
import java.math.BigDecimal; |
|
45 |
import java.math.BigInteger; |
|
46 |
import java.math.RoundingMode; |
|
13583 | 47 |
import java.text.spi.NumberFormatProvider; |
2 | 48 |
import java.util.ArrayList; |
49 |
import java.util.Currency; |
|
50 |
import java.util.Locale; |
|
51 |
import java.util.concurrent.atomic.AtomicInteger; |
|
52 |
import java.util.concurrent.atomic.AtomicLong; |
|
13583 | 53 |
import sun.util.locale.provider.LocaleProviderAdapter; |
15260 | 54 |
import sun.util.locale.provider.ResourceBundleBasedAdapter; |
2 | 55 |
|
56 |
/** |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
57 |
* {@code DecimalFormat} is a concrete subclass of |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
58 |
* {@code NumberFormat} that formats decimal numbers. It has a variety of |
2 | 59 |
* features designed to make it possible to parse and format numbers in any |
60 |
* locale, including support for Western, Arabic, and Indic digits. It also |
|
61 |
* supports different kinds of numbers, including integers (123), fixed-point |
|
62 |
* numbers (123.4), scientific notation (1.23E4), percentages (12%), and |
|
63 |
* currency amounts ($123). All of these can be localized. |
|
64 |
* |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
65 |
* <p>To obtain a {@code NumberFormat} for a specific locale, including the |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
66 |
* default locale, call one of {@code NumberFormat}'s factory methods, such |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
67 |
* as {@code getInstance()}. In general, do not call the |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
68 |
* {@code DecimalFormat} constructors directly, since the |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
69 |
* {@code NumberFormat} factory methods may return subclasses other than |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
70 |
* {@code DecimalFormat}. If you need to customize the format object, do |
2 | 71 |
* something like this: |
72 |
* |
|
73 |
* <blockquote><pre> |
|
74 |
* NumberFormat f = NumberFormat.getInstance(loc); |
|
75 |
* if (f instanceof DecimalFormat) { |
|
76 |
* ((DecimalFormat) f).setDecimalSeparatorAlwaysShown(true); |
|
77 |
* } |
|
78 |
* </pre></blockquote> |
|
79 |
* |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
80 |
* <p>A {@code DecimalFormat} comprises a <em>pattern</em> and a set of |
2 | 81 |
* <em>symbols</em>. The pattern may be set directly using |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
82 |
* {@code applyPattern()}, or indirectly using the API methods. The |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
83 |
* symbols are stored in a {@code DecimalFormatSymbols} object. When using |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
84 |
* the {@code NumberFormat} factory methods, the pattern and symbols are |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
85 |
* read from localized {@code ResourceBundle}s. |
2 | 86 |
* |
54206 | 87 |
* <h2>Patterns</h2> |
2 | 88 |
* |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
89 |
* {@code DecimalFormat} patterns have the following syntax: |
2 | 90 |
* <blockquote><pre> |
91 |
* <i>Pattern:</i> |
|
92 |
* <i>PositivePattern</i> |
|
93 |
* <i>PositivePattern</i> ; <i>NegativePattern</i> |
|
94 |
* <i>PositivePattern:</i> |
|
95 |
* <i>Prefix<sub>opt</sub></i> <i>Number</i> <i>Suffix<sub>opt</sub></i> |
|
96 |
* <i>NegativePattern:</i> |
|
97 |
* <i>Prefix<sub>opt</sub></i> <i>Number</i> <i>Suffix<sub>opt</sub></i> |
|
98 |
* <i>Prefix:</i> |
|
99 |
* any Unicode characters except \uFFFE, \uFFFF, and special characters |
|
100 |
* <i>Suffix:</i> |
|
101 |
* any Unicode characters except \uFFFE, \uFFFF, and special characters |
|
102 |
* <i>Number:</i> |
|
103 |
* <i>Integer</i> <i>Exponent<sub>opt</sub></i> |
|
104 |
* <i>Integer</i> . <i>Fraction</i> <i>Exponent<sub>opt</sub></i> |
|
105 |
* <i>Integer:</i> |
|
106 |
* <i>MinimumInteger</i> |
|
107 |
* # |
|
108 |
* # <i>Integer</i> |
|
109 |
* # , <i>Integer</i> |
|
110 |
* <i>MinimumInteger:</i> |
|
111 |
* 0 |
|
112 |
* 0 <i>MinimumInteger</i> |
|
113 |
* 0 , <i>MinimumInteger</i> |
|
114 |
* <i>Fraction:</i> |
|
115 |
* <i>MinimumFraction<sub>opt</sub></i> <i>OptionalFraction<sub>opt</sub></i> |
|
116 |
* <i>MinimumFraction:</i> |
|
117 |
* 0 <i>MinimumFraction<sub>opt</sub></i> |
|
118 |
* <i>OptionalFraction:</i> |
|
119 |
* # <i>OptionalFraction<sub>opt</sub></i> |
|
120 |
* <i>Exponent:</i> |
|
121 |
* E <i>MinimumExponent</i> |
|
122 |
* <i>MinimumExponent:</i> |
|
123 |
* 0 <i>MinimumExponent<sub>opt</sub></i> |
|
124 |
* </pre></blockquote> |
|
125 |
* |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
126 |
* <p>A {@code DecimalFormat} pattern contains a positive and negative |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
127 |
* subpattern, for example, {@code "#,##0.00;(#,##0.00)"}. Each |
2 | 128 |
* subpattern has a prefix, numeric part, and suffix. The negative subpattern |
129 |
* is optional; if absent, then the positive subpattern prefixed with the |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
130 |
* localized minus sign ({@code '-'} in most locales) is used as the |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
131 |
* negative subpattern. That is, {@code "0.00"} alone is equivalent to |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
132 |
* {@code "0.00;-0.00"}. If there is an explicit negative subpattern, it |
2 | 133 |
* serves only to specify the negative prefix and suffix; the number of digits, |
134 |
* minimal digits, and other characteristics are all the same as the positive |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
135 |
* pattern. That means that {@code "#,##0.0#;(#)"} produces precisely |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
136 |
* the same behavior as {@code "#,##0.0#;(#,##0.0#)"}. |
2 | 137 |
* |
138 |
* <p>The prefixes, suffixes, and various symbols used for infinity, digits, |
|
139 |
* thousands separators, decimal separators, etc. may be set to arbitrary |
|
140 |
* values, and they will appear properly during formatting. However, care must |
|
141 |
* be taken that the symbols and strings do not conflict, or parsing will be |
|
142 |
* unreliable. For example, either the positive and negative prefixes or the |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
143 |
* suffixes must be distinct for {@code DecimalFormat.parse()} to be able |
2 | 144 |
* to distinguish positive from negative values. (If they are identical, then |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
145 |
* {@code DecimalFormat} will behave as if no negative subpattern was |
2 | 146 |
* specified.) Another example is that the decimal separator and thousands |
147 |
* separator should be distinct characters, or parsing will be impossible. |
|
148 |
* |
|
149 |
* <p>The grouping separator is commonly used for thousands, but in some |
|
150 |
* countries it separates ten-thousands. The grouping size is a constant number |
|
151 |
* of digits between the grouping characters, such as 3 for 100,000,000 or 4 for |
|
152 |
* 1,0000,0000. If you supply a pattern with multiple grouping characters, the |
|
153 |
* interval between the last one and the end of the integer is the one that is |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
154 |
* used. So {@code "#,##,###,####"} == {@code "######,####"} == |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
155 |
* {@code "##,####,####"}. |
2 | 156 |
* |
54206 | 157 |
* <h3><a id="special_pattern_character">Special Pattern Characters</a></h3> |
2 | 158 |
* |
159 |
* <p>Many characters in a pattern are taken literally; they are matched during |
|
160 |
* parsing and output unchanged during formatting. Special characters, on the |
|
161 |
* other hand, stand for other characters, strings, or classes of characters. |
|
162 |
* They must be quoted, unless noted otherwise, if they are to appear in the |
|
163 |
* prefix or suffix as literals. |
|
164 |
* |
|
165 |
* <p>The characters listed here are used in non-localized patterns. Localized |
|
166 |
* patterns use the corresponding characters taken from this formatter's |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
167 |
* {@code DecimalFormatSymbols} object instead, and these characters lose |
2 | 168 |
* their special status. Two exceptions are the currency sign and quote, which |
169 |
* are not localized. |
|
170 |
* |
|
171 |
* <blockquote> |
|
45124
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
44846
diff
changeset
|
172 |
* <table class="striped"> |
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
44846
diff
changeset
|
173 |
* <caption style="display:none">Chart showing symbol, location, localized, and meaning.</caption> |
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
44846
diff
changeset
|
174 |
* <thead> |
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
44846
diff
changeset
|
175 |
* <tr> |
45881
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45474
diff
changeset
|
176 |
* <th scope="col" style="text-align:left">Symbol |
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45474
diff
changeset
|
177 |
* <th scope="col" style="text-align:left">Location |
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45474
diff
changeset
|
178 |
* <th scope="col" style="text-align:left">Localized? |
aaec0fbe17ae
8184208: update class="striped" tables for accessibility
jjg
parents:
45474
diff
changeset
|
179 |
* <th scope="col" style="text-align:left">Meaning |
45124
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
44846
diff
changeset
|
180 |
* </thead> |
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
44846
diff
changeset
|
181 |
* <tbody> |
44846
b3f9f5bf40b2
8179367: update use of align, valign attributes in java.base to use style attribute
jjg
parents:
44844
diff
changeset
|
182 |
* <tr style="vertical-align:top"> |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
183 |
* <th scope="row">{@code 0} |
2 | 184 |
* <td>Number |
185 |
* <td>Yes |
|
186 |
* <td>Digit |
|
45124
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
44846
diff
changeset
|
187 |
* <tr style="vertical-align: top"> |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
188 |
* <th scope="row">{@code #} |
2 | 189 |
* <td>Number |
190 |
* <td>Yes |
|
191 |
* <td>Digit, zero shows as absent |
|
44846
b3f9f5bf40b2
8179367: update use of align, valign attributes in java.base to use style attribute
jjg
parents:
44844
diff
changeset
|
192 |
* <tr style="vertical-align:top"> |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
193 |
* <th scope="row">{@code .} |
2 | 194 |
* <td>Number |
195 |
* <td>Yes |
|
196 |
* <td>Decimal separator or monetary decimal separator |
|
45124
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
44846
diff
changeset
|
197 |
* <tr style="vertical-align: top"> |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
198 |
* <th scope="row">{@code -} |
2 | 199 |
* <td>Number |
200 |
* <td>Yes |
|
201 |
* <td>Minus sign |
|
44846
b3f9f5bf40b2
8179367: update use of align, valign attributes in java.base to use style attribute
jjg
parents:
44844
diff
changeset
|
202 |
* <tr style="vertical-align:top"> |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
203 |
* <th scope="row">{@code ,} |
2 | 204 |
* <td>Number |
205 |
* <td>Yes |
|
206 |
* <td>Grouping separator |
|
45124
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
44846
diff
changeset
|
207 |
* <tr style="vertical-align: top"> |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
208 |
* <th scope="row">{@code E} |
2 | 209 |
* <td>Number |
210 |
* <td>Yes |
|
211 |
* <td>Separates mantissa and exponent in scientific notation. |
|
212 |
* <em>Need not be quoted in prefix or suffix.</em> |
|
44846
b3f9f5bf40b2
8179367: update use of align, valign attributes in java.base to use style attribute
jjg
parents:
44844
diff
changeset
|
213 |
* <tr style="vertical-align:top"> |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
214 |
* <th scope="row">{@code ;} |
2 | 215 |
* <td>Subpattern boundary |
216 |
* <td>Yes |
|
217 |
* <td>Separates positive and negative subpatterns |
|
45124
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
44846
diff
changeset
|
218 |
* <tr style="vertical-align: top"> |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
219 |
* <th scope="row">{@code %} |
2 | 220 |
* <td>Prefix or suffix |
221 |
* <td>Yes |
|
222 |
* <td>Multiply by 100 and show as percentage |
|
44846
b3f9f5bf40b2
8179367: update use of align, valign attributes in java.base to use style attribute
jjg
parents:
44844
diff
changeset
|
223 |
* <tr style="vertical-align:top"> |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
224 |
* <th scope="row">{@code \u2030} |
2 | 225 |
* <td>Prefix or suffix |
226 |
* <td>Yes |
|
227 |
* <td>Multiply by 1000 and show as per mille value |
|
45124
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
44846
diff
changeset
|
228 |
* <tr style="vertical-align: top"> |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
229 |
* <th scope="row">{@code ¤} ({@code \u00A4}) |
2 | 230 |
* <td>Prefix or suffix |
231 |
* <td>No |
|
232 |
* <td>Currency sign, replaced by currency symbol. If |
|
233 |
* doubled, replaced by international currency symbol. |
|
234 |
* If present in a pattern, the monetary decimal separator |
|
235 |
* is used instead of the decimal separator. |
|
44846
b3f9f5bf40b2
8179367: update use of align, valign attributes in java.base to use style attribute
jjg
parents:
44844
diff
changeset
|
236 |
* <tr style="vertical-align:top"> |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
237 |
* <th scope="row">{@code '} |
2 | 238 |
* <td>Prefix or suffix |
239 |
* <td>No |
|
240 |
* <td>Used to quote special characters in a prefix or suffix, |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
241 |
* for example, {@code "'#'#"} formats 123 to |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
242 |
* {@code "#123"}. To create a single quote |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
243 |
* itself, use two in a row: {@code "# o''clock"}. |
45124
144479e89cdb
8179592: Update tables in java.base to be HTML 5-friendly.
jjg
parents:
44846
diff
changeset
|
244 |
* </tbody> |
2 | 245 |
* </table> |
246 |
* </blockquote> |
|
247 |
* |
|
54206 | 248 |
* <h3>Scientific Notation</h3> |
2 | 249 |
* |
250 |
* <p>Numbers in scientific notation are expressed as the product of a mantissa |
|
251 |
* and a power of ten, for example, 1234 can be expressed as 1.234 x 10^3. The |
|
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
252 |
* mantissa is often in the range 1.0 ≤ x {@literal <} 10.0, but it need not |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
253 |
* be. |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
254 |
* {@code DecimalFormat} can be instructed to format and parse scientific |
2 | 255 |
* notation <em>only via a pattern</em>; there is currently no factory method |
256 |
* that creates a scientific notation format. In a pattern, the exponent |
|
257 |
* character immediately followed by one or more digit characters indicates |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
258 |
* scientific notation. Example: {@code "0.###E0"} formats the number |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
259 |
* 1234 as {@code "1.234E3"}. |
2 | 260 |
* |
261 |
* <ul> |
|
262 |
* <li>The number of digit characters after the exponent character gives the |
|
263 |
* minimum exponent digit count. There is no maximum. Negative exponents are |
|
264 |
* formatted using the localized minus sign, <em>not</em> the prefix and suffix |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
265 |
* from the pattern. This allows patterns such as {@code "0.###E0 m/s"}. |
2 | 266 |
* |
267 |
* <li>The minimum and maximum number of integer digits are interpreted |
|
268 |
* together: |
|
269 |
* |
|
270 |
* <ul> |
|
271 |
* <li>If the maximum number of integer digits is greater than their minimum number |
|
272 |
* and greater than 1, it forces the exponent to be a multiple of the maximum |
|
273 |
* number of integer digits, and the minimum number of integer digits to be |
|
274 |
* interpreted as 1. The most common use of this is to generate |
|
275 |
* <em>engineering notation</em>, in which the exponent is a multiple of three, |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
276 |
* e.g., {@code "##0.#####E0"}. Using this pattern, the number 12345 |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
277 |
* formats to {@code "12.345E3"}, and 123456 formats to |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
278 |
* {@code "123.456E3"}. |
2 | 279 |
* |
280 |
* <li>Otherwise, the minimum number of integer digits is achieved by adjusting the |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
281 |
* exponent. Example: 0.00123 formatted with {@code "00.###E0"} yields |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
282 |
* {@code "12.3E-4"}. |
2 | 283 |
* </ul> |
284 |
* |
|
285 |
* <li>The number of significant digits in the mantissa is the sum of the |
|
286 |
* <em>minimum integer</em> and <em>maximum fraction</em> digits, and is |
|
287 |
* unaffected by the maximum integer digits. For example, 12345 formatted with |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
288 |
* {@code "##0.##E0"} is {@code "12.3E3"}. To show all digits, set |
2 | 289 |
* the significant digits count to zero. The number of significant digits |
290 |
* does not affect parsing. |
|
291 |
* |
|
292 |
* <li>Exponential patterns may not contain grouping separators. |
|
293 |
* </ul> |
|
294 |
* |
|
54206 | 295 |
* <h3>Rounding</h3> |
2 | 296 |
* |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
297 |
* {@code DecimalFormat} provides rounding modes defined in |
2 | 298 |
* {@link java.math.RoundingMode} for formatting. By default, it uses |
299 |
* {@link java.math.RoundingMode#HALF_EVEN RoundingMode.HALF_EVEN}. |
|
300 |
* |
|
54206 | 301 |
* <h3>Digits</h3> |
2 | 302 |
* |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
303 |
* For formatting, {@code DecimalFormat} uses the ten consecutive |
2 | 304 |
* characters starting with the localized zero digit defined in the |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
305 |
* {@code DecimalFormatSymbols} object as digits. For parsing, these |
2 | 306 |
* digits as well as all Unicode decimal digits, as defined by |
307 |
* {@link Character#digit Character.digit}, are recognized. |
|
308 |
* |
|
309 |
* <h4>Special Values</h4> |
|
310 |
* |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
311 |
* <p>{@code NaN} is formatted as a string, which typically has a single character |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
312 |
* {@code \uFFFD}. This string is determined by the |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
313 |
* {@code DecimalFormatSymbols} object. This is the only value for which |
2 | 314 |
* the prefixes and suffixes are not used. |
315 |
* |
|
316 |
* <p>Infinity is formatted as a string, which typically has a single character |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
317 |
* {@code \u221E}, with the positive or negative prefixes and suffixes |
2 | 318 |
* applied. The infinity string is determined by the |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
319 |
* {@code DecimalFormatSymbols} object. |
2 | 320 |
* |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
321 |
* <p>Negative zero ({@code "-0"}) parses to |
2 | 322 |
* <ul> |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
323 |
* <li>{@code BigDecimal(0)} if {@code isParseBigDecimal()} is |
2 | 324 |
* true, |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
325 |
* <li>{@code Long(0)} if {@code isParseBigDecimal()} is false |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
326 |
* and {@code isParseIntegerOnly()} is true, |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
327 |
* <li>{@code Double(-0.0)} if both {@code isParseBigDecimal()} |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
328 |
* and {@code isParseIntegerOnly()} are false. |
2 | 329 |
* </ul> |
330 |
* |
|
54206 | 331 |
* <h3><a id="synchronization">Synchronization</a></h3> |
2 | 332 |
* |
333 |
* <p> |
|
334 |
* Decimal formats are generally not synchronized. |
|
335 |
* It is recommended to create separate format instances for each thread. |
|
336 |
* If multiple threads access a format concurrently, it must be synchronized |
|
337 |
* externally. |
|
338 |
* |
|
54206 | 339 |
* <h3>Example</h3> |
2 | 340 |
* |
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
341 |
* <blockquote><pre>{@code |
2 | 342 |
* <strong>// Print out a number using the localized number, integer, currency, |
343 |
* // and percent format for each locale</strong> |
|
344 |
* Locale[] locales = NumberFormat.getAvailableLocales(); |
|
345 |
* double myNumber = -1234.56; |
|
346 |
* NumberFormat form; |
|
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
347 |
* for (int j = 0; j < 4; ++j) { |
2 | 348 |
* System.out.println("FORMAT"); |
349 |
* for (int i = 0; i < locales.length; ++i) { |
|
350 |
* if (locales[i].getCountry().length() == 0) { |
|
351 |
* continue; // Skip language-only locales |
|
352 |
* } |
|
353 |
* System.out.print(locales[i].getDisplayName()); |
|
354 |
* switch (j) { |
|
355 |
* case 0: |
|
356 |
* form = NumberFormat.getInstance(locales[i]); break; |
|
357 |
* case 1: |
|
358 |
* form = NumberFormat.getIntegerInstance(locales[i]); break; |
|
359 |
* case 2: |
|
360 |
* form = NumberFormat.getCurrencyInstance(locales[i]); break; |
|
361 |
* default: |
|
362 |
* form = NumberFormat.getPercentInstance(locales[i]); break; |
|
363 |
* } |
|
364 |
* if (form instanceof DecimalFormat) { |
|
365 |
* System.out.print(": " + ((DecimalFormat) form).toPattern()); |
|
366 |
* } |
|
367 |
* System.out.print(" -> " + form.format(myNumber)); |
|
368 |
* try { |
|
369 |
* System.out.println(" -> " + form.parse(form.format(myNumber))); |
|
370 |
* } catch (ParseException e) {} |
|
371 |
* } |
|
372 |
* } |
|
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
373 |
* }</pre></blockquote> |
2 | 374 |
* |
20455
f6f9a0c2796b
8020688: Broken links in documentation at http://docs.oracle.com/javase/6/docs/api/index.
mcherkas
parents:
19054
diff
changeset
|
375 |
* @see <a href="http://docs.oracle.com/javase/tutorial/i18n/format/decimalFormat.html">Java Tutorial</a> |
2 | 376 |
* @see NumberFormat |
377 |
* @see DecimalFormatSymbols |
|
378 |
* @see ParsePosition |
|
379 |
* @author Mark Davis |
|
380 |
* @author Alan Liu |
|
45434
4582657c7260
8181082: class-level since tag issues in java.base & java.datatransfer module
mli
parents:
45124
diff
changeset
|
381 |
* @since 1.1 |
2 | 382 |
*/ |
383 |
public class DecimalFormat extends NumberFormat { |
|
384 |
||
385 |
/** |
|
386 |
* Creates a DecimalFormat using the default pattern and symbols |
|
16010
2727163b5df5
7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents:
15260
diff
changeset
|
387 |
* for the default {@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
|
388 |
* This is a convenient way to obtain a |
2 | 389 |
* DecimalFormat when internationalization is not the main concern. |
390 |
* <p> |
|
391 |
* To obtain standard formats for a given locale, use the factory methods |
|
392 |
* on NumberFormat such as getNumberInstance. These factories will |
|
393 |
* return the most appropriate sub-class of NumberFormat for a given |
|
394 |
* locale. |
|
395 |
* |
|
396 |
* @see java.text.NumberFormat#getInstance |
|
397 |
* @see java.text.NumberFormat#getNumberInstance |
|
398 |
* @see java.text.NumberFormat#getCurrencyInstance |
|
399 |
* @see java.text.NumberFormat#getPercentInstance |
|
400 |
*/ |
|
401 |
public DecimalFormat() { |
|
15260 | 402 |
// Get the pattern for the default locale. |
6489
9e7015635425
4700857: RFE: separating user locale and user interface locale
naoto
parents:
5506
diff
changeset
|
403 |
Locale def = Locale.getDefault(Locale.Category.FORMAT); |
15260 | 404 |
LocaleProviderAdapter adapter = LocaleProviderAdapter.getAdapter(NumberFormatProvider.class, def); |
405 |
if (!(adapter instanceof ResourceBundleBasedAdapter)) { |
|
406 |
adapter = LocaleProviderAdapter.getResourceBundleBased(); |
|
2 | 407 |
} |
15260 | 408 |
String[] all = adapter.getLocaleResources(def).getNumberPatterns(); |
2 | 409 |
|
410 |
// Always applyPattern after the symbols are set |
|
13583 | 411 |
this.symbols = DecimalFormatSymbols.getInstance(def); |
15260 | 412 |
applyPattern(all[0], false); |
2 | 413 |
} |
414 |
||
415 |
||
416 |
/** |
|
417 |
* Creates a DecimalFormat using the given pattern and the symbols |
|
16010
2727163b5df5
7092447: Clarify the default locale used in each locale sensitive operation
naoto
parents:
15260
diff
changeset
|
418 |
* for the default {@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
|
419 |
* This is a convenient way to obtain a |
2 | 420 |
* DecimalFormat when internationalization is not the main concern. |
421 |
* <p> |
|
422 |
* To obtain standard formats for a given locale, use the factory methods |
|
423 |
* on NumberFormat such as getNumberInstance. These factories will |
|
424 |
* return the most appropriate sub-class of NumberFormat for a given |
|
425 |
* locale. |
|
426 |
* |
|
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
427 |
* @param pattern a non-localized pattern string. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
428 |
* @throws NullPointerException if {@code pattern} is null |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
429 |
* @throws IllegalArgumentException if the given pattern is invalid. |
2 | 430 |
* @see java.text.NumberFormat#getInstance |
431 |
* @see java.text.NumberFormat#getNumberInstance |
|
432 |
* @see java.text.NumberFormat#getCurrencyInstance |
|
433 |
* @see java.text.NumberFormat#getPercentInstance |
|
434 |
*/ |
|
435 |
public DecimalFormat(String pattern) { |
|
436 |
// Always applyPattern after the symbols are set |
|
13583 | 437 |
this.symbols = DecimalFormatSymbols.getInstance(Locale.getDefault(Locale.Category.FORMAT)); |
2 | 438 |
applyPattern(pattern, false); |
439 |
} |
|
440 |
||
441 |
||
442 |
/** |
|
443 |
* Creates a DecimalFormat using the given pattern and symbols. |
|
444 |
* Use this constructor when you need to completely customize the |
|
445 |
* behavior of the format. |
|
446 |
* <p> |
|
447 |
* To obtain standard formats for a given |
|
448 |
* locale, use the factory methods on NumberFormat such as |
|
449 |
* getInstance or getCurrencyInstance. If you need only minor adjustments |
|
450 |
* to a standard format, you can modify the format returned by |
|
451 |
* a NumberFormat factory method. |
|
452 |
* |
|
453 |
* @param pattern a non-localized pattern string |
|
454 |
* @param symbols the set of symbols to be used |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
455 |
* @throws NullPointerException if any of the given arguments is null |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
456 |
* @throws IllegalArgumentException if the given pattern is invalid |
2 | 457 |
* @see java.text.NumberFormat#getInstance |
458 |
* @see java.text.NumberFormat#getNumberInstance |
|
459 |
* @see java.text.NumberFormat#getCurrencyInstance |
|
460 |
* @see java.text.NumberFormat#getPercentInstance |
|
461 |
* @see java.text.DecimalFormatSymbols |
|
462 |
*/ |
|
463 |
public DecimalFormat (String pattern, DecimalFormatSymbols symbols) { |
|
464 |
// Always applyPattern after the symbols are set |
|
465 |
this.symbols = (DecimalFormatSymbols)symbols.clone(); |
|
466 |
applyPattern(pattern, false); |
|
467 |
} |
|
468 |
||
469 |
||
470 |
// Overrides |
|
471 |
/** |
|
472 |
* Formats a number and appends the resulting text to the given string |
|
473 |
* buffer. |
|
474 |
* The number can be of any subclass of {@link java.lang.Number}. |
|
475 |
* <p> |
|
476 |
* This implementation uses the maximum precision permitted. |
|
477 |
* @param number the number to format |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
478 |
* @param toAppendTo the {@code StringBuffer} to which the formatted |
2 | 479 |
* text is to be appended |
48026
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
480 |
* @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
|
481 |
* returned string. For example, for formatting a number |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
482 |
* {@code 1234567.89} in {@code Locale.US} locale, |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
483 |
* if the given {@code fieldPosition} is |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
484 |
* {@link NumberFormat#INTEGER_FIELD}, the begin index |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
485 |
* and end index of {@code fieldPosition} will be set |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
486 |
* to 0 and 9, respectively for the output string |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
487 |
* {@code 1,234,567.89}. |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
488 |
* @return the value passed in as {@code toAppendTo} |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
489 |
* @throws IllegalArgumentException if {@code number} is |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
490 |
* null or not an instance of {@code Number}. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
491 |
* @throws NullPointerException if {@code toAppendTo} or |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
492 |
* {@code pos} is null |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
493 |
* @throws ArithmeticException if rounding is needed with rounding |
2 | 494 |
* mode being set to RoundingMode.UNNECESSARY |
495 |
* @see java.text.FieldPosition |
|
496 |
*/ |
|
13583 | 497 |
@Override |
2 | 498 |
public final StringBuffer format(Object number, |
499 |
StringBuffer toAppendTo, |
|
500 |
FieldPosition pos) { |
|
501 |
if (number instanceof Long || number instanceof Integer || |
|
502 |
number instanceof Short || number instanceof Byte || |
|
503 |
number instanceof AtomicInteger || |
|
504 |
number instanceof AtomicLong || |
|
505 |
(number instanceof BigInteger && |
|
506 |
((BigInteger)number).bitLength () < 64)) { |
|
507 |
return format(((Number)number).longValue(), toAppendTo, pos); |
|
508 |
} else if (number instanceof BigDecimal) { |
|
509 |
return format((BigDecimal)number, toAppendTo, pos); |
|
510 |
} else if (number instanceof BigInteger) { |
|
511 |
return format((BigInteger)number, toAppendTo, pos); |
|
512 |
} else if (number instanceof Number) { |
|
513 |
return format(((Number)number).doubleValue(), toAppendTo, pos); |
|
514 |
} else { |
|
515 |
throw new IllegalArgumentException("Cannot format given Object as a Number"); |
|
516 |
} |
|
517 |
} |
|
518 |
||
519 |
/** |
|
520 |
* Formats a double to produce a string. |
|
521 |
* @param number The double to format |
|
522 |
* @param result where the text is to be appended |
|
48026
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
523 |
* @param fieldPosition keeps track on the position of the field within |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
524 |
* the returned string. For example, for formatting |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
525 |
* a number {@code 1234567.89} in {@code Locale.US} |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
526 |
* locale, if the given {@code fieldPosition} is |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
527 |
* {@link NumberFormat#INTEGER_FIELD}, the begin index |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
528 |
* and end index of {@code fieldPosition} will be set |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
529 |
* to 0 and 9, respectively for the output string |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
530 |
* {@code 1,234,567.89}. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
531 |
* @throws NullPointerException if {@code result} or |
43011
36edf207e84c
8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents:
41223
diff
changeset
|
532 |
* {@code fieldPosition} is {@code null} |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
533 |
* @throws ArithmeticException if rounding is needed with rounding |
2 | 534 |
* mode being set to RoundingMode.UNNECESSARY |
535 |
* @return The formatted number string |
|
536 |
* @see java.text.FieldPosition |
|
537 |
*/ |
|
13583 | 538 |
@Override |
2 | 539 |
public StringBuffer format(double number, StringBuffer result, |
540 |
FieldPosition fieldPosition) { |
|
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
541 |
// If fieldPosition is a DontCareFieldPosition instance we can |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
542 |
// try to go to fast-path code. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
543 |
boolean tryFastPath = false; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
544 |
if (fieldPosition == DontCareFieldPosition.INSTANCE) |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
545 |
tryFastPath = true; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
546 |
else { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
547 |
fieldPosition.setBeginIndex(0); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
548 |
fieldPosition.setEndIndex(0); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
549 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
550 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
551 |
if (tryFastPath) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
552 |
String tempResult = fastFormat(number); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
553 |
if (tempResult != null) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
554 |
result.append(tempResult); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
555 |
return result; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
556 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
557 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
558 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
559 |
// if fast-path could not work, we fallback to standard code. |
2 | 560 |
return format(number, result, fieldPosition.getFieldDelegate()); |
561 |
} |
|
562 |
||
563 |
/** |
|
564 |
* Formats a double to produce a string. |
|
565 |
* @param number The double to format |
|
566 |
* @param result where the text is to be appended |
|
567 |
* @param delegate notified of locations of sub fields |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
568 |
* @throws ArithmeticException if rounding is needed with rounding |
2 | 569 |
* mode being set to RoundingMode.UNNECESSARY |
570 |
* @return The formatted number string |
|
571 |
*/ |
|
52869 | 572 |
StringBuffer format(double number, StringBuffer result, |
2 | 573 |
FieldDelegate delegate) { |
52869 | 574 |
|
575 |
boolean nanOrInfinity = handleNaN(number, result, delegate); |
|
576 |
if (nanOrInfinity) { |
|
2 | 577 |
return result; |
578 |
} |
|
579 |
||
580 |
/* Detecting whether a double is negative is easy with the exception of |
|
581 |
* the value -0.0. This is a double which has a zero mantissa (and |
|
582 |
* exponent), but a negative sign bit. It is semantically distinct from |
|
583 |
* a zero with a positive sign bit, and this distinction is important |
|
584 |
* to certain kinds of computations. However, it's a little tricky to |
|
585 |
* detect, since (-0.0 == 0.0) and !(-0.0 < 0.0). How then, you may |
|
586 |
* ask, does it behave distinctly from +0.0? Well, 1/(-0.0) == |
|
587 |
* -Infinity. Proper detection of -0.0 is needed to deal with the |
|
588 |
* issues raised by bugs 4106658, 4106667, and 4147706. Liu 7/6/98. |
|
589 |
*/ |
|
590 |
boolean isNegative = ((number < 0.0) || (number == 0.0 && 1/number < 0.0)) ^ (multiplier < 0); |
|
591 |
||
592 |
if (multiplier != 1) { |
|
593 |
number *= multiplier; |
|
594 |
} |
|
595 |
||
52869 | 596 |
nanOrInfinity = handleInfinity(number, result, delegate, isNegative); |
597 |
if (nanOrInfinity) { |
|
598 |
return result; |
|
599 |
} |
|
600 |
||
601 |
if (isNegative) { |
|
602 |
number = -number; |
|
603 |
} |
|
604 |
||
605 |
// at this point we are guaranteed a nonnegative finite number. |
|
606 |
assert (number >= 0 && !Double.isInfinite(number)); |
|
607 |
return doubleSubformat(number, result, delegate, isNegative); |
|
608 |
} |
|
609 |
||
610 |
/** |
|
611 |
* Checks if the given {@code number} is {@code Double.NaN}. if yes; |
|
612 |
* appends the NaN symbol to the result string. The NaN string is |
|
613 |
* determined by the DecimalFormatSymbols object. |
|
614 |
* @param number the double number to format |
|
615 |
* @param result where the text is to be appended |
|
616 |
* @param delegate notified of locations of sub fields |
|
617 |
* @return true, if number is a NaN; false otherwise |
|
618 |
*/ |
|
619 |
boolean handleNaN(double number, StringBuffer result, |
|
620 |
FieldDelegate delegate) { |
|
621 |
if (Double.isNaN(number) |
|
622 |
|| (Double.isInfinite(number) && multiplier == 0)) { |
|
623 |
int iFieldStart = result.length(); |
|
624 |
result.append(symbols.getNaN()); |
|
625 |
delegate.formatted(INTEGER_FIELD, Field.INTEGER, Field.INTEGER, |
|
626 |
iFieldStart, result.length(), result); |
|
627 |
return true; |
|
628 |
} |
|
629 |
return false; |
|
630 |
} |
|
631 |
||
632 |
/** |
|
633 |
* Checks if the given {@code number} is {@code Double.NEGATIVE_INFINITY} |
|
634 |
* or {@code Double.POSITIVE_INFINITY}. if yes; |
|
635 |
* appends the infinity string to the result string. The infinity string is |
|
636 |
* determined by the DecimalFormatSymbols object. |
|
637 |
* @param number the double number to format |
|
638 |
* @param result where the text is to be appended |
|
639 |
* @param delegate notified of locations of sub fields |
|
640 |
* @param isNegative whether the given {@code number} is negative |
|
641 |
* @return true, if number is a {@code Double.NEGATIVE_INFINITY} or |
|
642 |
* {@code Double.POSITIVE_INFINITY}; false otherwise |
|
643 |
*/ |
|
644 |
boolean handleInfinity(double number, StringBuffer result, |
|
645 |
FieldDelegate delegate, boolean isNegative) { |
|
2 | 646 |
if (Double.isInfinite(number)) { |
647 |
if (isNegative) { |
|
648 |
append(result, negativePrefix, delegate, |
|
649 |
getNegativePrefixFieldPositions(), Field.SIGN); |
|
650 |
} else { |
|
651 |
append(result, positivePrefix, delegate, |
|
652 |
getPositivePrefixFieldPositions(), Field.SIGN); |
|
653 |
} |
|
654 |
||
655 |
int iFieldStart = result.length(); |
|
656 |
result.append(symbols.getInfinity()); |
|
657 |
delegate.formatted(INTEGER_FIELD, Field.INTEGER, Field.INTEGER, |
|
658 |
iFieldStart, result.length(), result); |
|
659 |
||
660 |
if (isNegative) { |
|
661 |
append(result, negativeSuffix, delegate, |
|
662 |
getNegativeSuffixFieldPositions(), Field.SIGN); |
|
663 |
} else { |
|
664 |
append(result, positiveSuffix, delegate, |
|
665 |
getPositiveSuffixFieldPositions(), Field.SIGN); |
|
666 |
} |
|
667 |
||
52869 | 668 |
return true; |
2 | 669 |
} |
52869 | 670 |
return false; |
671 |
} |
|
672 |
||
673 |
StringBuffer doubleSubformat(double number, StringBuffer result, |
|
674 |
FieldDelegate delegate, boolean isNegative) { |
|
675 |
synchronized (digitList) { |
|
2 | 676 |
int maxIntDigits = super.getMaximumIntegerDigits(); |
677 |
int minIntDigits = super.getMinimumIntegerDigits(); |
|
678 |
int maxFraDigits = super.getMaximumFractionDigits(); |
|
679 |
int minFraDigits = super.getMinimumFractionDigits(); |
|
680 |
||
52869 | 681 |
digitList.set(isNegative, number, useExponentialNotation |
682 |
? maxIntDigits + maxFraDigits : maxFraDigits, |
|
683 |
!useExponentialNotation); |
|
2 | 684 |
return subformat(result, delegate, isNegative, false, |
52869 | 685 |
maxIntDigits, minIntDigits, maxFraDigits, minFraDigits); |
2 | 686 |
} |
687 |
} |
|
688 |
||
689 |
/** |
|
690 |
* Format a long to produce a string. |
|
691 |
* @param number The long to format |
|
692 |
* @param result where the text is to be appended |
|
48026
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
693 |
* @param fieldPosition keeps track on the position of the field within |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
694 |
* the returned string. For example, for formatting |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
695 |
* a number {@code 123456789} in {@code Locale.US} |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
696 |
* locale, if the given {@code fieldPosition} is |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
697 |
* {@link NumberFormat#INTEGER_FIELD}, the begin index |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
698 |
* and end index of {@code fieldPosition} will be set |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
699 |
* to 0 and 11, respectively for the output string |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
700 |
* {@code 123,456,789}. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
701 |
* @throws NullPointerException if {@code result} or |
43011
36edf207e84c
8169480: Inconsistencies across Format class hierarchy in their API spec and actual implementation of Exceptions
nishjain
parents:
41223
diff
changeset
|
702 |
* {@code fieldPosition} is {@code null} |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
703 |
* @throws ArithmeticException if rounding is needed with rounding |
2 | 704 |
* mode being set to RoundingMode.UNNECESSARY |
705 |
* @return The formatted number string |
|
706 |
* @see java.text.FieldPosition |
|
707 |
*/ |
|
13583 | 708 |
@Override |
2 | 709 |
public StringBuffer format(long number, StringBuffer result, |
710 |
FieldPosition fieldPosition) { |
|
711 |
fieldPosition.setBeginIndex(0); |
|
712 |
fieldPosition.setEndIndex(0); |
|
713 |
||
714 |
return format(number, result, fieldPosition.getFieldDelegate()); |
|
715 |
} |
|
716 |
||
717 |
/** |
|
718 |
* Format a long to produce a string. |
|
719 |
* @param number The long to format |
|
720 |
* @param result where the text is to be appended |
|
721 |
* @param delegate notified of locations of sub fields |
|
722 |
* @return The formatted number string |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
723 |
* @throws ArithmeticException if rounding is needed with rounding |
2 | 724 |
* mode being set to RoundingMode.UNNECESSARY |
725 |
* @see java.text.FieldPosition |
|
726 |
*/ |
|
52869 | 727 |
StringBuffer format(long number, StringBuffer result, |
2 | 728 |
FieldDelegate delegate) { |
729 |
boolean isNegative = (number < 0); |
|
730 |
if (isNegative) { |
|
731 |
number = -number; |
|
732 |
} |
|
733 |
||
734 |
// In general, long values always represent real finite numbers, so |
|
735 |
// we don't have to check for +/- Infinity or NaN. However, there |
|
736 |
// is one case we have to be careful of: The multiplier can push |
|
737 |
// a number near MIN_VALUE or MAX_VALUE outside the legal range. We |
|
738 |
// check for this before multiplying, and if it happens we use |
|
739 |
// BigInteger instead. |
|
740 |
boolean useBigInteger = false; |
|
741 |
if (number < 0) { // This can only happen if number == Long.MIN_VALUE. |
|
742 |
if (multiplier != 0) { |
|
743 |
useBigInteger = true; |
|
744 |
} |
|
745 |
} else if (multiplier != 1 && multiplier != 0) { |
|
746 |
long cutoff = Long.MAX_VALUE / multiplier; |
|
747 |
if (cutoff < 0) { |
|
748 |
cutoff = -cutoff; |
|
749 |
} |
|
750 |
useBigInteger = (number > cutoff); |
|
751 |
} |
|
752 |
||
753 |
if (useBigInteger) { |
|
754 |
if (isNegative) { |
|
755 |
number = -number; |
|
756 |
} |
|
757 |
BigInteger bigIntegerValue = BigInteger.valueOf(number); |
|
758 |
return format(bigIntegerValue, result, delegate, true); |
|
759 |
} |
|
760 |
||
761 |
number *= multiplier; |
|
762 |
if (number == 0) { |
|
763 |
isNegative = false; |
|
764 |
} else { |
|
765 |
if (multiplier < 0) { |
|
766 |
number = -number; |
|
767 |
isNegative = !isNegative; |
|
768 |
} |
|
769 |
} |
|
770 |
||
771 |
synchronized(digitList) { |
|
772 |
int maxIntDigits = super.getMaximumIntegerDigits(); |
|
773 |
int minIntDigits = super.getMinimumIntegerDigits(); |
|
774 |
int maxFraDigits = super.getMaximumFractionDigits(); |
|
775 |
int minFraDigits = super.getMinimumFractionDigits(); |
|
776 |
||
777 |
digitList.set(isNegative, number, |
|
778 |
useExponentialNotation ? maxIntDigits + maxFraDigits : 0); |
|
779 |
||
780 |
return subformat(result, delegate, isNegative, true, |
|
781 |
maxIntDigits, minIntDigits, maxFraDigits, minFraDigits); |
|
782 |
} |
|
783 |
} |
|
784 |
||
785 |
/** |
|
786 |
* Formats a BigDecimal to produce a string. |
|
787 |
* @param number The BigDecimal to format |
|
788 |
* @param result where the text is to be appended |
|
48026
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
789 |
* @param fieldPosition keeps track on the position of the field within |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
790 |
* the returned string. For example, for formatting |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
791 |
* a number {@code 1234567.89} in {@code Locale.US} |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
792 |
* locale, if the given {@code fieldPosition} is |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
793 |
* {@link NumberFormat#INTEGER_FIELD}, the begin index |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
794 |
* and end index of {@code fieldPosition} will be set |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
795 |
* to 0 and 9, respectively for the output string |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
796 |
* {@code 1,234,567.89}. |
2 | 797 |
* @return The formatted number string |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
798 |
* @throws ArithmeticException if rounding is needed with rounding |
2 | 799 |
* mode being set to RoundingMode.UNNECESSARY |
800 |
* @see java.text.FieldPosition |
|
801 |
*/ |
|
802 |
private StringBuffer format(BigDecimal number, StringBuffer result, |
|
803 |
FieldPosition fieldPosition) { |
|
804 |
fieldPosition.setBeginIndex(0); |
|
805 |
fieldPosition.setEndIndex(0); |
|
806 |
return format(number, result, fieldPosition.getFieldDelegate()); |
|
807 |
} |
|
808 |
||
809 |
/** |
|
810 |
* Formats a BigDecimal to produce a string. |
|
811 |
* @param number The BigDecimal to format |
|
812 |
* @param result where the text is to be appended |
|
813 |
* @param delegate notified of locations of sub fields |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
814 |
* @throws ArithmeticException if rounding is needed with rounding |
2 | 815 |
* mode being set to RoundingMode.UNNECESSARY |
816 |
* @return The formatted number string |
|
817 |
*/ |
|
52869 | 818 |
StringBuffer format(BigDecimal number, StringBuffer result, |
2 | 819 |
FieldDelegate delegate) { |
820 |
if (multiplier != 1) { |
|
821 |
number = number.multiply(getBigDecimalMultiplier()); |
|
822 |
} |
|
823 |
boolean isNegative = number.signum() == -1; |
|
824 |
if (isNegative) { |
|
825 |
number = number.negate(); |
|
826 |
} |
|
827 |
||
828 |
synchronized(digitList) { |
|
829 |
int maxIntDigits = getMaximumIntegerDigits(); |
|
830 |
int minIntDigits = getMinimumIntegerDigits(); |
|
831 |
int maxFraDigits = getMaximumFractionDigits(); |
|
832 |
int minFraDigits = getMinimumFractionDigits(); |
|
833 |
int maximumDigits = maxIntDigits + maxFraDigits; |
|
834 |
||
835 |
digitList.set(isNegative, number, useExponentialNotation ? |
|
836 |
((maximumDigits < 0) ? Integer.MAX_VALUE : maximumDigits) : |
|
837 |
maxFraDigits, !useExponentialNotation); |
|
838 |
||
839 |
return subformat(result, delegate, isNegative, false, |
|
840 |
maxIntDigits, minIntDigits, maxFraDigits, minFraDigits); |
|
841 |
} |
|
842 |
} |
|
843 |
||
844 |
/** |
|
845 |
* Format a BigInteger to produce a string. |
|
846 |
* @param number The BigInteger to format |
|
847 |
* @param result where the text is to be appended |
|
48026
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
848 |
* @param fieldPosition keeps track on the position of the field within |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
849 |
* the returned string. For example, for formatting |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
850 |
* a number {@code 123456789} in {@code Locale.US} |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
851 |
* locale, if the given {@code fieldPosition} is |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
852 |
* {@link NumberFormat#INTEGER_FIELD}, the begin index |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
853 |
* and end index of {@code fieldPosition} will be set |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
854 |
* to 0 and 11, respectively for the output string |
89deac44e515
6354947: [Fmt-*] Clarify DecimalFormat description of FieldPosition use
nishjain
parents:
47216
diff
changeset
|
855 |
* {@code 123,456,789}. |
2 | 856 |
* @return The formatted number string |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
857 |
* @throws ArithmeticException if rounding is needed with rounding |
2 | 858 |
* mode being set to RoundingMode.UNNECESSARY |
859 |
* @see java.text.FieldPosition |
|
860 |
*/ |
|
861 |
private StringBuffer format(BigInteger number, StringBuffer result, |
|
862 |
FieldPosition fieldPosition) { |
|
863 |
fieldPosition.setBeginIndex(0); |
|
864 |
fieldPosition.setEndIndex(0); |
|
865 |
||
866 |
return format(number, result, fieldPosition.getFieldDelegate(), false); |
|
867 |
} |
|
868 |
||
869 |
/** |
|
870 |
* Format a BigInteger to produce a string. |
|
871 |
* @param number The BigInteger to format |
|
872 |
* @param result where the text is to be appended |
|
873 |
* @param delegate notified of locations of sub fields |
|
874 |
* @return The formatted number string |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
875 |
* @throws ArithmeticException if rounding is needed with rounding |
2 | 876 |
* mode being set to RoundingMode.UNNECESSARY |
877 |
* @see java.text.FieldPosition |
|
878 |
*/ |
|
52869 | 879 |
StringBuffer format(BigInteger number, StringBuffer result, |
2 | 880 |
FieldDelegate delegate, boolean formatLong) { |
881 |
if (multiplier != 1) { |
|
882 |
number = number.multiply(getBigIntegerMultiplier()); |
|
883 |
} |
|
884 |
boolean isNegative = number.signum() == -1; |
|
885 |
if (isNegative) { |
|
886 |
number = number.negate(); |
|
887 |
} |
|
888 |
||
889 |
synchronized(digitList) { |
|
890 |
int maxIntDigits, minIntDigits, maxFraDigits, minFraDigits, maximumDigits; |
|
891 |
if (formatLong) { |
|
892 |
maxIntDigits = super.getMaximumIntegerDigits(); |
|
893 |
minIntDigits = super.getMinimumIntegerDigits(); |
|
894 |
maxFraDigits = super.getMaximumFractionDigits(); |
|
895 |
minFraDigits = super.getMinimumFractionDigits(); |
|
896 |
maximumDigits = maxIntDigits + maxFraDigits; |
|
897 |
} else { |
|
898 |
maxIntDigits = getMaximumIntegerDigits(); |
|
899 |
minIntDigits = getMinimumIntegerDigits(); |
|
900 |
maxFraDigits = getMaximumFractionDigits(); |
|
901 |
minFraDigits = getMinimumFractionDigits(); |
|
902 |
maximumDigits = maxIntDigits + maxFraDigits; |
|
903 |
if (maximumDigits < 0) { |
|
904 |
maximumDigits = Integer.MAX_VALUE; |
|
905 |
} |
|
906 |
} |
|
907 |
||
908 |
digitList.set(isNegative, number, |
|
909 |
useExponentialNotation ? maximumDigits : 0); |
|
910 |
||
911 |
return subformat(result, delegate, isNegative, true, |
|
912 |
maxIntDigits, minIntDigits, maxFraDigits, minFraDigits); |
|
913 |
} |
|
914 |
} |
|
915 |
||
916 |
/** |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
917 |
* Formats an Object producing an {@code AttributedCharacterIterator}. |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
918 |
* You can use the returned {@code AttributedCharacterIterator} |
2 | 919 |
* to build the resulting String, as well as to determine information |
920 |
* about the resulting String. |
|
921 |
* <p> |
|
922 |
* Each attribute key of the AttributedCharacterIterator will be of type |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
923 |
* {@code NumberFormat.Field}, with the attribute value being the |
2 | 924 |
* same as the attribute key. |
925 |
* |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
926 |
* @throws NullPointerException if obj is null. |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
927 |
* @throws IllegalArgumentException when the Format cannot format the |
2 | 928 |
* given object. |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
929 |
* @throws ArithmeticException if rounding is needed with rounding |
2 | 930 |
* mode being set to RoundingMode.UNNECESSARY |
931 |
* @param obj The object to format |
|
932 |
* @return AttributedCharacterIterator describing the formatted value. |
|
933 |
* @since 1.4 |
|
934 |
*/ |
|
13583 | 935 |
@Override |
2 | 936 |
public AttributedCharacterIterator formatToCharacterIterator(Object obj) { |
937 |
CharacterIteratorFieldDelegate delegate = |
|
938 |
new CharacterIteratorFieldDelegate(); |
|
939 |
StringBuffer sb = new StringBuffer(); |
|
940 |
||
941 |
if (obj instanceof Double || obj instanceof Float) { |
|
942 |
format(((Number)obj).doubleValue(), sb, delegate); |
|
943 |
} else if (obj instanceof Long || obj instanceof Integer || |
|
944 |
obj instanceof Short || obj instanceof Byte || |
|
945 |
obj instanceof AtomicInteger || obj instanceof AtomicLong) { |
|
946 |
format(((Number)obj).longValue(), sb, delegate); |
|
947 |
} else if (obj instanceof BigDecimal) { |
|
948 |
format((BigDecimal)obj, sb, delegate); |
|
949 |
} else if (obj instanceof BigInteger) { |
|
950 |
format((BigInteger)obj, sb, delegate, false); |
|
951 |
} else if (obj == null) { |
|
952 |
throw new NullPointerException( |
|
953 |
"formatToCharacterIterator must be passed non-null object"); |
|
954 |
} else { |
|
955 |
throw new IllegalArgumentException( |
|
956 |
"Cannot format given Object as a Number"); |
|
957 |
} |
|
958 |
return delegate.getIterator(sb.toString()); |
|
959 |
} |
|
960 |
||
52869 | 961 |
// ==== Begin fast-path formatting logic for double ========================= |
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
962 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
963 |
/* Fast-path formatting will be used for format(double ...) methods iff a |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
964 |
* number of conditions are met (see checkAndSetFastPathStatus()): |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
965 |
* - Only if instance properties meet the right predefined conditions. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
966 |
* - The abs value of the double to format is <= Integer.MAX_VALUE. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
967 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
968 |
* The basic approach is to split the binary to decimal conversion of a |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
969 |
* double value into two phases: |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
970 |
* * The conversion of the integer portion of the double. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
971 |
* * The conversion of the fractional portion of the double |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
972 |
* (limited to two or three digits). |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
973 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
974 |
* The isolation and conversion of the integer portion of the double is |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
975 |
* straightforward. The conversion of the fraction is more subtle and relies |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
976 |
* on some rounding properties of double to the decimal precisions in |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
977 |
* question. Using the terminology of BigDecimal, this fast-path algorithm |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
978 |
* is applied when a double value has a magnitude less than Integer.MAX_VALUE |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
979 |
* and rounding is to nearest even and the destination format has two or |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
980 |
* three digits of *scale* (digits after the decimal point). |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
981 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
982 |
* Under a rounding to nearest even policy, the returned result is a digit |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
983 |
* string of a number in the (in this case decimal) destination format |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
984 |
* closest to the exact numerical value of the (in this case binary) input |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
985 |
* value. If two destination format numbers are equally distant, the one |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
986 |
* with the last digit even is returned. To compute such a correctly rounded |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
987 |
* value, some information about digits beyond the smallest returned digit |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
988 |
* position needs to be consulted. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
989 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
990 |
* In general, a guard digit, a round digit, and a sticky *bit* are needed |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
991 |
* beyond the returned digit position. If the discarded portion of the input |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
992 |
* is sufficiently large, the returned digit string is incremented. In round |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
993 |
* to nearest even, this threshold to increment occurs near the half-way |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
994 |
* point between digits. The sticky bit records if there are any remaining |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
995 |
* trailing digits of the exact input value in the new format; the sticky bit |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
996 |
* is consulted only in close to half-way rounding cases. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
997 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
998 |
* Given the computation of the digit and bit values, rounding is then |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
999 |
* reduced to a table lookup problem. For decimal, the even/odd cases look |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1000 |
* like this: |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1001 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1002 |
* Last Round Sticky |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1003 |
* 6 5 0 => 6 // exactly halfway, return even digit. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1004 |
* 6 5 1 => 7 // a little bit more than halfway, round up. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1005 |
* 7 5 0 => 8 // exactly halfway, round up to even. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1006 |
* 7 5 1 => 8 // a little bit more than halfway, round up. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1007 |
* With analogous entries for other even and odd last-returned digits. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1008 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1009 |
* However, decimal negative powers of 5 smaller than 0.5 are *not* exactly |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1010 |
* representable as binary fraction. In particular, 0.005 (the round limit |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1011 |
* for a two-digit scale) and 0.0005 (the round limit for a three-digit |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1012 |
* scale) are not representable. Therefore, for input values near these cases |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1013 |
* the sticky bit is known to be set which reduces the rounding logic to: |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1014 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1015 |
* Last Round Sticky |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1016 |
* 6 5 1 => 7 // a little bit more than halfway, round up. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1017 |
* 7 5 1 => 8 // a little bit more than halfway, round up. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1018 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1019 |
* In other words, if the round digit is 5, the sticky bit is known to be |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1020 |
* set. If the round digit is something other than 5, the sticky bit is not |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1021 |
* relevant. Therefore, some of the logic about whether or not to increment |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1022 |
* the destination *decimal* value can occur based on tests of *binary* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1023 |
* computations of the binary input number. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1024 |
*/ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1025 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1026 |
/** |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1027 |
* Check validity of using fast-path for this instance. If fast-path is valid |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1028 |
* for this instance, sets fast-path state as true and initializes fast-path |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1029 |
* utility fields as needed. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1030 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1031 |
* This method is supposed to be called rarely, otherwise that will break the |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1032 |
* fast-path performance. That means avoiding frequent changes of the |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1033 |
* properties of the instance, since for most properties, each time a change |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1034 |
* happens, a call to this method is needed at the next format call. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1035 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1036 |
* FAST-PATH RULES: |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1037 |
* Similar to the default DecimalFormat instantiation case. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1038 |
* More precisely: |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1039 |
* - HALF_EVEN rounding mode, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1040 |
* - isGroupingUsed() is true, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1041 |
* - groupingSize of 3, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1042 |
* - multiplier is 1, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1043 |
* - Decimal separator not mandatory, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1044 |
* - No use of exponential notation, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1045 |
* - minimumIntegerDigits is exactly 1 and maximumIntegerDigits at least 10 |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1046 |
* - For number of fractional digits, the exact values found in the default case: |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1047 |
* Currency : min = max = 2. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1048 |
* Decimal : min = 0. max = 3. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1049 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1050 |
*/ |
41223
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1051 |
private boolean checkAndSetFastPathStatus() { |
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1052 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1053 |
boolean fastPathWasOn = isFastPath; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1054 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1055 |
if ((roundingMode == RoundingMode.HALF_EVEN) && |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1056 |
(isGroupingUsed()) && |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1057 |
(groupingSize == 3) && |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1058 |
(multiplier == 1) && |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1059 |
(!decimalSeparatorAlwaysShown) && |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1060 |
(!useExponentialNotation)) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1061 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1062 |
// The fast-path algorithm is semi-hardcoded against |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1063 |
// minimumIntegerDigits and maximumIntegerDigits. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1064 |
isFastPath = ((minimumIntegerDigits == 1) && |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1065 |
(maximumIntegerDigits >= 10)); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1066 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1067 |
// The fast-path algorithm is hardcoded against |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1068 |
// minimumFractionDigits and maximumFractionDigits. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1069 |
if (isFastPath) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1070 |
if (isCurrencyFormat) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1071 |
if ((minimumFractionDigits != 2) || |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1072 |
(maximumFractionDigits != 2)) |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1073 |
isFastPath = false; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1074 |
} else if ((minimumFractionDigits != 0) || |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1075 |
(maximumFractionDigits != 3)) |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1076 |
isFastPath = false; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1077 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1078 |
} else |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1079 |
isFastPath = false; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1080 |
|
41223
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1081 |
resetFastPathData(fastPathWasOn); |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1082 |
fastPathCheckNeeded = false; |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1083 |
|
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1084 |
/* |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1085 |
* Returns true after successfully checking the fast path condition and |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1086 |
* setting the fast path data. The return value is used by the |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1087 |
* fastFormat() method to decide whether to call the resetFastPathData |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1088 |
* method to reinitialize fast path data or is it already initialized |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1089 |
* in this method. |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1090 |
*/ |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1091 |
return true; |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1092 |
} |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1093 |
|
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1094 |
private void resetFastPathData(boolean fastPathWasOn) { |
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1095 |
// Since some instance properties may have changed while still falling |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1096 |
// in the fast-path case, we need to reinitialize fastPathData anyway. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1097 |
if (isFastPath) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1098 |
// We need to instantiate fastPathData if not already done. |
41223
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1099 |
if (fastPathData == null) { |
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1100 |
fastPathData = new FastPathData(); |
41223
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1101 |
} |
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1102 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1103 |
// Sets up the locale specific constants used when formatting. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1104 |
// '0' is our default representation of zero. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1105 |
fastPathData.zeroDelta = symbols.getZeroDigit() - '0'; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1106 |
fastPathData.groupingChar = symbols.getGroupingSeparator(); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1107 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1108 |
// Sets up fractional constants related to currency/decimal pattern. |
41223
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1109 |
fastPathData.fractionalMaxIntBound = (isCurrencyFormat) |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1110 |
? 99 : 999; |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1111 |
fastPathData.fractionalScaleFactor = (isCurrencyFormat) |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1112 |
? 100.0d : 1000.0d; |
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1113 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1114 |
// Records the need for adding prefix or suffix |
41223
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1115 |
fastPathData.positiveAffixesRequired |
53018
8bf9268df0e2
8215281: Use String.isEmpty() when applicable in java.base
redestad
parents:
52869
diff
changeset
|
1116 |
= !positivePrefix.isEmpty() || !positiveSuffix.isEmpty(); |
41223
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1117 |
fastPathData.negativeAffixesRequired |
53018
8bf9268df0e2
8215281: Use String.isEmpty() when applicable in java.base
redestad
parents:
52869
diff
changeset
|
1118 |
= !negativePrefix.isEmpty() || !negativeSuffix.isEmpty(); |
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1119 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1120 |
// Creates a cached char container for result, with max possible size. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1121 |
int maxNbIntegralDigits = 10; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1122 |
int maxNbGroups = 3; |
41223
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1123 |
int containerSize |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1124 |
= Math.max(positivePrefix.length(), negativePrefix.length()) |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1125 |
+ maxNbIntegralDigits + maxNbGroups + 1 |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1126 |
+ maximumFractionDigits |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1127 |
+ Math.max(positiveSuffix.length(), negativeSuffix.length()); |
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1128 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1129 |
fastPathData.fastPathContainer = new char[containerSize]; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1130 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1131 |
// Sets up prefix and suffix char arrays constants. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1132 |
fastPathData.charsPositiveSuffix = positiveSuffix.toCharArray(); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1133 |
fastPathData.charsNegativeSuffix = negativeSuffix.toCharArray(); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1134 |
fastPathData.charsPositivePrefix = positivePrefix.toCharArray(); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1135 |
fastPathData.charsNegativePrefix = negativePrefix.toCharArray(); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1136 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1137 |
// Sets up fixed index positions for integral and fractional digits. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1138 |
// Sets up decimal point in cached result container. |
41223
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1139 |
int longestPrefixLength |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1140 |
= Math.max(positivePrefix.length(), |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1141 |
negativePrefix.length()); |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1142 |
int decimalPointIndex |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1143 |
= maxNbIntegralDigits + maxNbGroups + longestPrefixLength; |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1144 |
|
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1145 |
fastPathData.integralLastIndex = decimalPointIndex - 1; |
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1146 |
fastPathData.fractionalFirstIndex = decimalPointIndex + 1; |
41223
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1147 |
fastPathData.fastPathContainer[decimalPointIndex] |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1148 |
= isCurrencyFormat |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1149 |
? symbols.getMonetaryDecimalSeparator() |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1150 |
: symbols.getDecimalSeparator(); |
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1151 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1152 |
} else if (fastPathWasOn) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1153 |
// Previous state was fast-path and is no more. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1154 |
// Resets cached array constants. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1155 |
fastPathData.fastPathContainer = null; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1156 |
fastPathData.charsPositiveSuffix = null; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1157 |
fastPathData.charsNegativeSuffix = null; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1158 |
fastPathData.charsPositivePrefix = null; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1159 |
fastPathData.charsNegativePrefix = null; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1160 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1161 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1162 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1163 |
/** |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1164 |
* Returns true if rounding-up must be done on {@code scaledFractionalPartAsInt}, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1165 |
* false otherwise. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1166 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1167 |
* This is a utility method that takes correct half-even rounding decision on |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1168 |
* passed fractional value at the scaled decimal point (2 digits for currency |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1169 |
* case and 3 for decimal case), when the approximated fractional part after |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1170 |
* scaled decimal point is exactly 0.5d. This is done by means of exact |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1171 |
* calculations on the {@code fractionalPart} floating-point value. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1172 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1173 |
* This method is supposed to be called by private {@code fastDoubleFormat} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1174 |
* method only. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1175 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1176 |
* The algorithms used for the exact calculations are : |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1177 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1178 |
* The <b><i>FastTwoSum</i></b> algorithm, from T.J.Dekker, described in the |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1179 |
* papers "<i>A Floating-Point Technique for Extending the Available |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1180 |
* Precision</i>" by Dekker, and in "<i>Adaptive Precision Floating-Point |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1181 |
* Arithmetic and Fast Robust Geometric Predicates</i>" from J.Shewchuk. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1182 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1183 |
* A modified version of <b><i>Sum2S</i></b> cascaded summation described in |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1184 |
* "<i>Accurate Sum and Dot Product</i>" from Takeshi Ogita and All. As |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1185 |
* Ogita says in this paper this is an equivalent of the Kahan-Babuska's |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1186 |
* summation algorithm because we order the terms by magnitude before summing |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1187 |
* them. For this reason we can use the <i>FastTwoSum</i> algorithm rather |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1188 |
* than the more expensive Knuth's <i>TwoSum</i>. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1189 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1190 |
* We do this to avoid a more expensive exact "<i>TwoProduct</i>" algorithm, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1191 |
* like those described in Shewchuk's paper above. See comments in the code |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1192 |
* below. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1193 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1194 |
* @param fractionalPart The fractional value on which we take rounding |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1195 |
* decision. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1196 |
* @param scaledFractionalPartAsInt The integral part of the scaled |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1197 |
* fractional value. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1198 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1199 |
* @return the decision that must be taken regarding half-even rounding. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1200 |
*/ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1201 |
private boolean exactRoundUp(double fractionalPart, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1202 |
int scaledFractionalPartAsInt) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1203 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1204 |
/* exactRoundUp() method is called by fastDoubleFormat() only. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1205 |
* The precondition expected to be verified by the passed parameters is : |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1206 |
* scaledFractionalPartAsInt == |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1207 |
* (int) (fractionalPart * fastPathData.fractionalScaleFactor). |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1208 |
* This is ensured by fastDoubleFormat() code. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1209 |
*/ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1210 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1211 |
/* We first calculate roundoff error made by fastDoubleFormat() on |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1212 |
* the scaled fractional part. We do this with exact calculation on the |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1213 |
* passed fractionalPart. Rounding decision will then be taken from roundoff. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1214 |
*/ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1215 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1216 |
/* ---- TwoProduct(fractionalPart, scale factor (i.e. 1000.0d or 100.0d)). |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1217 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1218 |
* The below is an optimized exact "TwoProduct" calculation of passed |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1219 |
* fractional part with scale factor, using Ogita's Sum2S cascaded |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1220 |
* summation adapted as Kahan-Babuska equivalent by using FastTwoSum |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1221 |
* (much faster) rather than Knuth's TwoSum. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1222 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1223 |
* We can do this because we order the summation from smallest to |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1224 |
* greatest, so that FastTwoSum can be used without any additional error. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1225 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1226 |
* The "TwoProduct" exact calculation needs 17 flops. We replace this by |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1227 |
* a cascaded summation of FastTwoSum calculations, each involving an |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1228 |
* exact multiply by a power of 2. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1229 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1230 |
* Doing so saves overall 4 multiplications and 1 addition compared to |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1231 |
* using traditional "TwoProduct". |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1232 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1233 |
* The scale factor is either 100 (currency case) or 1000 (decimal case). |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1234 |
* - when 1000, we replace it by (1024 - 16 - 8) = 1000. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1235 |
* - when 100, we replace it by (128 - 32 + 4) = 100. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1236 |
* Every multiplication by a power of 2 (1024, 128, 32, 16, 8, 4) is exact. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1237 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1238 |
*/ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1239 |
double approxMax; // Will always be positive. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1240 |
double approxMedium; // Will always be negative. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1241 |
double approxMin; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1242 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1243 |
double fastTwoSumApproximation = 0.0d; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1244 |
double fastTwoSumRoundOff = 0.0d; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1245 |
double bVirtual = 0.0d; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1246 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1247 |
if (isCurrencyFormat) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1248 |
// Scale is 100 = 128 - 32 + 4. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1249 |
// Multiply by 2**n is a shift. No roundoff. No error. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1250 |
approxMax = fractionalPart * 128.00d; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1251 |
approxMedium = - (fractionalPart * 32.00d); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1252 |
approxMin = fractionalPart * 4.00d; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1253 |
} else { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1254 |
// Scale is 1000 = 1024 - 16 - 8. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1255 |
// Multiply by 2**n is a shift. No roundoff. No error. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1256 |
approxMax = fractionalPart * 1024.00d; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1257 |
approxMedium = - (fractionalPart * 16.00d); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1258 |
approxMin = - (fractionalPart * 8.00d); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1259 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1260 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1261 |
// Shewchuk/Dekker's FastTwoSum(approxMedium, approxMin). |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1262 |
assert(-approxMedium >= Math.abs(approxMin)); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1263 |
fastTwoSumApproximation = approxMedium + approxMin; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1264 |
bVirtual = fastTwoSumApproximation - approxMedium; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1265 |
fastTwoSumRoundOff = approxMin - bVirtual; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1266 |
double approxS1 = fastTwoSumApproximation; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1267 |
double roundoffS1 = fastTwoSumRoundOff; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1268 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1269 |
// Shewchuk/Dekker's FastTwoSum(approxMax, approxS1); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1270 |
assert(approxMax >= Math.abs(approxS1)); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1271 |
fastTwoSumApproximation = approxMax + approxS1; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1272 |
bVirtual = fastTwoSumApproximation - approxMax; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1273 |
fastTwoSumRoundOff = approxS1 - bVirtual; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1274 |
double roundoff1000 = fastTwoSumRoundOff; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1275 |
double approx1000 = fastTwoSumApproximation; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1276 |
double roundoffTotal = roundoffS1 + roundoff1000; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1277 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1278 |
// Shewchuk/Dekker's FastTwoSum(approx1000, roundoffTotal); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1279 |
assert(approx1000 >= Math.abs(roundoffTotal)); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1280 |
fastTwoSumApproximation = approx1000 + roundoffTotal; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1281 |
bVirtual = fastTwoSumApproximation - approx1000; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1282 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1283 |
// Now we have got the roundoff for the scaled fractional |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1284 |
double scaledFractionalRoundoff = roundoffTotal - bVirtual; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1285 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1286 |
// ---- TwoProduct(fractionalPart, scale (i.e. 1000.0d or 100.0d)) end. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1287 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1288 |
/* ---- Taking the rounding decision |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1289 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1290 |
* We take rounding decision based on roundoff and half-even rounding |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1291 |
* rule. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1292 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1293 |
* The above TwoProduct gives us the exact roundoff on the approximated |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1294 |
* scaled fractional, and we know that this approximation is exactly |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1295 |
* 0.5d, since that has already been tested by the caller |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1296 |
* (fastDoubleFormat). |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1297 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1298 |
* Decision comes first from the sign of the calculated exact roundoff. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1299 |
* - Since being exact roundoff, it cannot be positive with a scaled |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1300 |
* fractional less than 0.5d, as well as negative with a scaled |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1301 |
* fractional greater than 0.5d. That leaves us with following 3 cases. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1302 |
* - positive, thus scaled fractional == 0.500....0fff ==> round-up. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1303 |
* - negative, thus scaled fractional == 0.499....9fff ==> don't round-up. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1304 |
* - is zero, thus scaled fractioanl == 0.5 ==> half-even rounding applies : |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1305 |
* we round-up only if the integral part of the scaled fractional is odd. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1306 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1307 |
*/ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1308 |
if (scaledFractionalRoundoff > 0.0) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1309 |
return true; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1310 |
} else if (scaledFractionalRoundoff < 0.0) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1311 |
return false; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1312 |
} else if ((scaledFractionalPartAsInt & 1) != 0) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1313 |
return true; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1314 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1315 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1316 |
return false; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1317 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1318 |
// ---- Taking the rounding decision end |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1319 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1320 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1321 |
/** |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1322 |
* Collects integral digits from passed {@code number}, while setting |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1323 |
* grouping chars as needed. Updates {@code firstUsedIndex} accordingly. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1324 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1325 |
* Loops downward starting from {@code backwardIndex} position (inclusive). |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1326 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1327 |
* @param number The int value from which we collect digits. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1328 |
* @param digitsBuffer The char array container where digits and grouping chars |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1329 |
* are stored. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1330 |
* @param backwardIndex the position from which we start storing digits in |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1331 |
* digitsBuffer. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1332 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1333 |
*/ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1334 |
private void collectIntegralDigits(int number, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1335 |
char[] digitsBuffer, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1336 |
int backwardIndex) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1337 |
int index = backwardIndex; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1338 |
int q; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1339 |
int r; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1340 |
while (number > 999) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1341 |
// Generates 3 digits per iteration. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1342 |
q = number / 1000; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1343 |
r = number - (q << 10) + (q << 4) + (q << 3); // -1024 +16 +8 = 1000. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1344 |
number = q; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1345 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1346 |
digitsBuffer[index--] = DigitArrays.DigitOnes1000[r]; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1347 |
digitsBuffer[index--] = DigitArrays.DigitTens1000[r]; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1348 |
digitsBuffer[index--] = DigitArrays.DigitHundreds1000[r]; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1349 |
digitsBuffer[index--] = fastPathData.groupingChar; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1350 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1351 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1352 |
// Collects last 3 or less digits. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1353 |
digitsBuffer[index] = DigitArrays.DigitOnes1000[number]; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1354 |
if (number > 9) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1355 |
digitsBuffer[--index] = DigitArrays.DigitTens1000[number]; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1356 |
if (number > 99) |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1357 |
digitsBuffer[--index] = DigitArrays.DigitHundreds1000[number]; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1358 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1359 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1360 |
fastPathData.firstUsedIndex = index; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1361 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1362 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1363 |
/** |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1364 |
* Collects the 2 (currency) or 3 (decimal) fractional digits from passed |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1365 |
* {@code number}, starting at {@code startIndex} position |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1366 |
* inclusive. There is no punctuation to set here (no grouping chars). |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1367 |
* Updates {@code fastPathData.lastFreeIndex} accordingly. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1368 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1369 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1370 |
* @param number The int value from which we collect digits. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1371 |
* @param digitsBuffer The char array container where digits are stored. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1372 |
* @param startIndex the position from which we start storing digits in |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1373 |
* digitsBuffer. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1374 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1375 |
*/ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1376 |
private void collectFractionalDigits(int number, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1377 |
char[] digitsBuffer, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1378 |
int startIndex) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1379 |
int index = startIndex; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1380 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1381 |
char digitOnes = DigitArrays.DigitOnes1000[number]; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1382 |
char digitTens = DigitArrays.DigitTens1000[number]; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1383 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1384 |
if (isCurrencyFormat) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1385 |
// Currency case. Always collects fractional digits. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1386 |
digitsBuffer[index++] = digitTens; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1387 |
digitsBuffer[index++] = digitOnes; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1388 |
} else if (number != 0) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1389 |
// Decimal case. Hundreds will always be collected |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1390 |
digitsBuffer[index++] = DigitArrays.DigitHundreds1000[number]; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1391 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1392 |
// Ending zeros won't be collected. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1393 |
if (digitOnes != '0') { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1394 |
digitsBuffer[index++] = digitTens; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1395 |
digitsBuffer[index++] = digitOnes; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1396 |
} else if (digitTens != '0') |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1397 |
digitsBuffer[index++] = digitTens; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1398 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1399 |
} else |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1400 |
// This is decimal pattern and fractional part is zero. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1401 |
// We must remove decimal point from result. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1402 |
index--; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1403 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1404 |
fastPathData.lastFreeIndex = index; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1405 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1406 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1407 |
/** |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1408 |
* Internal utility. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1409 |
* Adds the passed {@code prefix} and {@code suffix} to {@code container}. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1410 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1411 |
* @param container Char array container which to prepend/append the |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1412 |
* prefix/suffix. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1413 |
* @param prefix Char sequence to prepend as a prefix. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1414 |
* @param suffix Char sequence to append as a suffix. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1415 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1416 |
*/ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1417 |
// private void addAffixes(boolean isNegative, char[] container) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1418 |
private void addAffixes(char[] container, char[] prefix, char[] suffix) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1419 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1420 |
// We add affixes only if needed (affix length > 0). |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1421 |
int pl = prefix.length; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1422 |
int sl = suffix.length; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1423 |
if (pl != 0) prependPrefix(prefix, pl, container); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1424 |
if (sl != 0) appendSuffix(suffix, sl, container); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1425 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1426 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1427 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1428 |
/** |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1429 |
* Prepends the passed {@code prefix} chars to given result |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1430 |
* {@code container}. Updates {@code fastPathData.firstUsedIndex} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1431 |
* accordingly. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1432 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1433 |
* @param prefix The prefix characters to prepend to result. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1434 |
* @param len The number of chars to prepend. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1435 |
* @param container Char array container which to prepend the prefix |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1436 |
*/ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1437 |
private void prependPrefix(char[] prefix, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1438 |
int len, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1439 |
char[] container) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1440 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1441 |
fastPathData.firstUsedIndex -= len; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1442 |
int startIndex = fastPathData.firstUsedIndex; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1443 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1444 |
// If prefix to prepend is only 1 char long, just assigns this char. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1445 |
// If prefix is less or equal 4, we use a dedicated algorithm that |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1446 |
// has shown to run faster than System.arraycopy. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1447 |
// If more than 4, we use System.arraycopy. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1448 |
if (len == 1) |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1449 |
container[startIndex] = prefix[0]; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1450 |
else if (len <= 4) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1451 |
int dstLower = startIndex; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1452 |
int dstUpper = dstLower + len - 1; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1453 |
int srcUpper = len - 1; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1454 |
container[dstLower] = prefix[0]; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1455 |
container[dstUpper] = prefix[srcUpper]; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1456 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1457 |
if (len > 2) |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1458 |
container[++dstLower] = prefix[1]; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1459 |
if (len == 4) |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1460 |
container[--dstUpper] = prefix[2]; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1461 |
} else |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1462 |
System.arraycopy(prefix, 0, container, startIndex, len); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1463 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1464 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1465 |
/** |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1466 |
* Appends the passed {@code suffix} chars to given result |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1467 |
* {@code container}. Updates {@code fastPathData.lastFreeIndex} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1468 |
* accordingly. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1469 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1470 |
* @param suffix The suffix characters to append to result. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1471 |
* @param len The number of chars to append. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1472 |
* @param container Char array container which to append the suffix |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1473 |
*/ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1474 |
private void appendSuffix(char[] suffix, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1475 |
int len, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1476 |
char[] container) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1477 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1478 |
int startIndex = fastPathData.lastFreeIndex; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1479 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1480 |
// If suffix to append is only 1 char long, just assigns this char. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1481 |
// If suffix is less or equal 4, we use a dedicated algorithm that |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1482 |
// has shown to run faster than System.arraycopy. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1483 |
// If more than 4, we use System.arraycopy. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1484 |
if (len == 1) |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1485 |
container[startIndex] = suffix[0]; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1486 |
else if (len <= 4) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1487 |
int dstLower = startIndex; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1488 |
int dstUpper = dstLower + len - 1; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1489 |
int srcUpper = len - 1; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1490 |
container[dstLower] = suffix[0]; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1491 |
container[dstUpper] = suffix[srcUpper]; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1492 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1493 |
if (len > 2) |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1494 |
container[++dstLower] = suffix[1]; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1495 |
if (len == 4) |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1496 |
container[--dstUpper] = suffix[2]; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1497 |
} else |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1498 |
System.arraycopy(suffix, 0, container, startIndex, len); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1499 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1500 |
fastPathData.lastFreeIndex += len; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1501 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1502 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1503 |
/** |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1504 |
* Converts digit chars from {@code digitsBuffer} to current locale. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1505 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1506 |
* Must be called before adding affixes since we refer to |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1507 |
* {@code fastPathData.firstUsedIndex} and {@code fastPathData.lastFreeIndex}, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1508 |
* and do not support affixes (for speed reason). |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1509 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1510 |
* We loop backward starting from last used index in {@code fastPathData}. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1511 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1512 |
* @param digitsBuffer The char array container where the digits are stored. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1513 |
*/ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1514 |
private void localizeDigits(char[] digitsBuffer) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1515 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1516 |
// We will localize only the digits, using the groupingSize, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1517 |
// and taking into account fractional part. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1518 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1519 |
// First take into account fractional part. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1520 |
int digitsCounter = |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1521 |
fastPathData.lastFreeIndex - fastPathData.fractionalFirstIndex; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1522 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1523 |
// The case when there is no fractional digits. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1524 |
if (digitsCounter < 0) |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1525 |
digitsCounter = groupingSize; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1526 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1527 |
// Only the digits remains to localize. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1528 |
for (int cursor = fastPathData.lastFreeIndex - 1; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1529 |
cursor >= fastPathData.firstUsedIndex; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1530 |
cursor--) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1531 |
if (digitsCounter != 0) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1532 |
// This is a digit char, we must localize it. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1533 |
digitsBuffer[cursor] += fastPathData.zeroDelta; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1534 |
digitsCounter--; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1535 |
} else { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1536 |
// Decimal separator or grouping char. Reinit counter only. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1537 |
digitsCounter = groupingSize; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1538 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1539 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1540 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1541 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1542 |
/** |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1543 |
* This is the main entry point for the fast-path format algorithm. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1544 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1545 |
* At this point we are sure to be in the expected conditions to run it. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1546 |
* This algorithm builds the formatted result and puts it in the dedicated |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1547 |
* {@code fastPathData.fastPathContainer}. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1548 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1549 |
* @param d the double value to be formatted. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1550 |
* @param negative Flag precising if {@code d} is negative. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1551 |
*/ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1552 |
private void fastDoubleFormat(double d, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1553 |
boolean negative) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1554 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1555 |
char[] container = fastPathData.fastPathContainer; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1556 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1557 |
/* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1558 |
* The principle of the algorithm is to : |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1559 |
* - Break the passed double into its integral and fractional parts |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1560 |
* converted into integers. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1561 |
* - Then decide if rounding up must be applied or not by following |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1562 |
* the half-even rounding rule, first using approximated scaled |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1563 |
* fractional part. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1564 |
* - For the difficult cases (approximated scaled fractional part |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1565 |
* being exactly 0.5d), we refine the rounding decision by calling |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1566 |
* exactRoundUp utility method that both calculates the exact roundoff |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1567 |
* on the approximation and takes correct rounding decision. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1568 |
* - We round-up the fractional part if needed, possibly propagating the |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1569 |
* rounding to integral part if we meet a "all-nine" case for the |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1570 |
* scaled fractional part. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1571 |
* - We then collect digits from the resulting integral and fractional |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1572 |
* parts, also setting the required grouping chars on the fly. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1573 |
* - Then we localize the collected digits if needed, and |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1574 |
* - Finally prepend/append prefix/suffix if any is needed. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1575 |
*/ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1576 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1577 |
// Exact integral part of d. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1578 |
int integralPartAsInt = (int) d; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1579 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1580 |
// Exact fractional part of d (since we subtract it's integral part). |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1581 |
double exactFractionalPart = d - (double) integralPartAsInt; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1582 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1583 |
// Approximated scaled fractional part of d (due to multiplication). |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1584 |
double scaledFractional = |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1585 |
exactFractionalPart * fastPathData.fractionalScaleFactor; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1586 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1587 |
// Exact integral part of scaled fractional above. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1588 |
int fractionalPartAsInt = (int) scaledFractional; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1589 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1590 |
// Exact fractional part of scaled fractional above. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1591 |
scaledFractional = scaledFractional - (double) fractionalPartAsInt; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1592 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1593 |
// Only when scaledFractional is exactly 0.5d do we have to do exact |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1594 |
// calculations and take fine-grained rounding decision, since |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1595 |
// approximated results above may lead to incorrect decision. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1596 |
// Otherwise comparing against 0.5d (strictly greater or less) is ok. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1597 |
boolean roundItUp = false; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1598 |
if (scaledFractional >= 0.5d) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1599 |
if (scaledFractional == 0.5d) |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1600 |
// Rounding need fine-grained decision. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1601 |
roundItUp = exactRoundUp(exactFractionalPart, fractionalPartAsInt); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1602 |
else |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1603 |
roundItUp = true; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1604 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1605 |
if (roundItUp) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1606 |
// Rounds up both fractional part (and also integral if needed). |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1607 |
if (fractionalPartAsInt < fastPathData.fractionalMaxIntBound) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1608 |
fractionalPartAsInt++; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1609 |
} else { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1610 |
// Propagates rounding to integral part since "all nines" case. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1611 |
fractionalPartAsInt = 0; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1612 |
integralPartAsInt++; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1613 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1614 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1615 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1616 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1617 |
// Collecting digits. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1618 |
collectFractionalDigits(fractionalPartAsInt, container, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1619 |
fastPathData.fractionalFirstIndex); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1620 |
collectIntegralDigits(integralPartAsInt, container, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1621 |
fastPathData.integralLastIndex); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1622 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1623 |
// Localizing digits. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1624 |
if (fastPathData.zeroDelta != 0) |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1625 |
localizeDigits(container); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1626 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1627 |
// Adding prefix and suffix. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1628 |
if (negative) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1629 |
if (fastPathData.negativeAffixesRequired) |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1630 |
addAffixes(container, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1631 |
fastPathData.charsNegativePrefix, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1632 |
fastPathData.charsNegativeSuffix); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1633 |
} else if (fastPathData.positiveAffixesRequired) |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1634 |
addAffixes(container, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1635 |
fastPathData.charsPositivePrefix, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1636 |
fastPathData.charsPositiveSuffix); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1637 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1638 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1639 |
/** |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1640 |
* A fast-path shortcut of format(double) to be called by NumberFormat, or by |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1641 |
* format(double, ...) public methods. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1642 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1643 |
* If instance can be applied fast-path and passed double is not NaN or |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1644 |
* Infinity, is in the integer range, we call {@code fastDoubleFormat} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1645 |
* after changing {@code d} to its positive value if necessary. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1646 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1647 |
* Otherwise returns null by convention since fast-path can't be exercized. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1648 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1649 |
* @param d The double value to be formatted |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1650 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1651 |
* @return the formatted result for {@code d} as a string. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1652 |
*/ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1653 |
String fastFormat(double d) { |
41223
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1654 |
boolean isDataSet = false; |
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1655 |
// (Re-)Evaluates fast-path status if needed. |
41223
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1656 |
if (fastPathCheckNeeded) { |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1657 |
isDataSet = checkAndSetFastPathStatus(); |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1658 |
} |
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1659 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1660 |
if (!isFastPath ) |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1661 |
// DecimalFormat instance is not in a fast-path state. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1662 |
return null; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1663 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1664 |
if (!Double.isFinite(d)) |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1665 |
// Should not use fast-path for Infinity and NaN. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1666 |
return null; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1667 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1668 |
// Extracts and records sign of double value, possibly changing it |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1669 |
// to a positive one, before calling fastDoubleFormat(). |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1670 |
boolean negative = false; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1671 |
if (d < 0.0d) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1672 |
negative = true; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1673 |
d = -d; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1674 |
} else if (d == 0.0d) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1675 |
negative = (Math.copySign(1.0d, d) == -1.0d); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1676 |
d = +0.0d; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1677 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1678 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1679 |
if (d > MAX_INT_AS_DOUBLE) |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1680 |
// Filters out values that are outside expected fast-path range |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1681 |
return null; |
41223
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1682 |
else { |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1683 |
if (!isDataSet) { |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1684 |
/* |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1685 |
* If the fast path data is not set through |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1686 |
* checkAndSetFastPathStatus() and fulfil the |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1687 |
* fast path conditions then reset the data |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1688 |
* directly through resetFastPathData() |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1689 |
*/ |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1690 |
resetFastPathData(isFastPath); |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1691 |
} |
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1692 |
fastDoubleFormat(d, negative); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1693 |
|
41223
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1694 |
} |
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1695 |
|
843bc8924490
8165466: DecimalFormat percentage format can contain unexpected %
nishjain
parents:
37521
diff
changeset
|
1696 |
|
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1697 |
// Returns a new string from updated fastPathContainer. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1698 |
return new String(fastPathData.fastPathContainer, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1699 |
fastPathData.firstUsedIndex, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1700 |
fastPathData.lastFreeIndex - fastPathData.firstUsedIndex); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1701 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1702 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1703 |
|
52869 | 1704 |
/** |
1705 |
* Sets the {@code DigitList} used by this {@code DecimalFormat} |
|
1706 |
* instance. |
|
1707 |
* @param number the number to format |
|
1708 |
* @param isNegative true, if the number is negative; false otherwise |
|
1709 |
* @param maxDigits the max digits |
|
1710 |
*/ |
|
1711 |
void setDigitList(Number number, boolean isNegative, int maxDigits) { |
|
1712 |
||
1713 |
if (number instanceof Double) { |
|
1714 |
digitList.set(isNegative, (Double) number, maxDigits, true); |
|
1715 |
} else if (number instanceof BigDecimal) { |
|
1716 |
digitList.set(isNegative, (BigDecimal) number, maxDigits, true); |
|
1717 |
} else if (number instanceof Long) { |
|
1718 |
digitList.set(isNegative, (Long) number, maxDigits); |
|
1719 |
} else if (number instanceof BigInteger) { |
|
1720 |
digitList.set(isNegative, (BigInteger) number, maxDigits); |
|
1721 |
} |
|
1722 |
} |
|
1723 |
||
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1724 |
// ======== End fast-path formating logic for double ========================= |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
1725 |
|
2 | 1726 |
/** |
1727 |
* Complete the formatting of a finite number. On entry, the digitList must |
|
1728 |
* be filled in with the correct digits. |
|
1729 |
*/ |
|
1730 |
private StringBuffer subformat(StringBuffer result, FieldDelegate delegate, |
|
52869 | 1731 |
boolean isNegative, boolean isInteger, |
1732 |
int maxIntDigits, int minIntDigits, |
|
1733 |
int maxFraDigits, int minFraDigits) { |
|
1734 |
||
1735 |
// Process prefix |
|
1736 |
if (isNegative) { |
|
1737 |
append(result, negativePrefix, delegate, |
|
1738 |
getNegativePrefixFieldPositions(), Field.SIGN); |
|
1739 |
} else { |
|
1740 |
append(result, positivePrefix, delegate, |
|
1741 |
getPositivePrefixFieldPositions(), Field.SIGN); |
|
1742 |
} |
|
1743 |
||
1744 |
// Process number |
|
1745 |
subformatNumber(result, delegate, isNegative, isInteger, |
|
1746 |
maxIntDigits, minIntDigits, maxFraDigits, minFraDigits); |
|
1747 |
||
1748 |
// Process suffix |
|
1749 |
if (isNegative) { |
|
1750 |
append(result, negativeSuffix, delegate, |
|
1751 |
getNegativeSuffixFieldPositions(), Field.SIGN); |
|
1752 |
} else { |
|
1753 |
append(result, positiveSuffix, delegate, |
|
1754 |
getPositiveSuffixFieldPositions(), Field.SIGN); |
|
1755 |
} |
|
1756 |
||
1757 |
return result; |
|
1758 |
} |
|
1759 |
||
1760 |
/** |
|
1761 |
* Subformats number part using the {@code DigitList} of this |
|
1762 |
* {@code DecimalFormat} instance. |
|
1763 |
* @param result where the text is to be appended |
|
1764 |
* @param delegate notified of the location of sub fields |
|
1765 |
* @param isNegative true, if the number is negative; false otherwise |
|
1766 |
* @param isInteger true, if the number is an integer; false otherwise |
|
1767 |
* @param maxIntDigits maximum integer digits |
|
1768 |
* @param minIntDigits minimum integer digits |
|
1769 |
* @param maxFraDigits maximum fraction digits |
|
1770 |
* @param minFraDigits minimum fraction digits |
|
1771 |
*/ |
|
1772 |
void subformatNumber(StringBuffer result, FieldDelegate delegate, |
|
1773 |
boolean isNegative, boolean isInteger, |
|
1774 |
int maxIntDigits, int minIntDigits, |
|
1775 |
int maxFraDigits, int minFraDigits) { |
|
1776 |
||
1777 |
char grouping = symbols.getGroupingSeparator(); |
|
2 | 1778 |
char zero = symbols.getZeroDigit(); |
1779 |
int zeroDelta = zero - '0'; // '0' is the DigitList representation of zero |
|
52869 | 1780 |
|
2 | 1781 |
char decimal = isCurrencyFormat ? |
52869 | 1782 |
symbols.getMonetaryDecimalSeparator() : |
1783 |
symbols.getDecimalSeparator(); |
|
2 | 1784 |
|
1785 |
/* Per bug 4147706, DecimalFormat must respect the sign of numbers which |
|
1786 |
* format as zero. This allows sensible computations and preserves |
|
1787 |
* relations such as signum(1/x) = signum(x), where x is +Infinity or |
|
1788 |
* -Infinity. Prior to this fix, we always formatted zero values as if |
|
1789 |
* they were positive. Liu 7/6/98. |
|
1790 |
*/ |
|
1791 |
if (digitList.isZero()) { |
|
1792 |
digitList.decimalAt = 0; // Normalize |
|
1793 |
} |
|
1794 |
||
1795 |
if (useExponentialNotation) { |
|
1796 |
int iFieldStart = result.length(); |
|
1797 |
int iFieldEnd = -1; |
|
1798 |
int fFieldStart = -1; |
|
1799 |
||
1800 |
// Minimum integer digits are handled in exponential format by |
|
1801 |
// adjusting the exponent. For example, 0.01234 with 3 minimum |
|
1802 |
// integer digits is "123.4E-4". |
|
1803 |
// Maximum integer digits are interpreted as indicating the |
|
1804 |
// repeating range. This is useful for engineering notation, in |
|
1805 |
// which the exponent is restricted to a multiple of 3. For |
|
1806 |
// example, 0.01234 with 3 maximum integer digits is "12.34e-3". |
|
1807 |
// If maximum integer digits are > 1 and are larger than |
|
1808 |
// minimum integer digits, then minimum integer digits are |
|
1809 |
// ignored. |
|
1810 |
int exponent = digitList.decimalAt; |
|
1811 |
int repeat = maxIntDigits; |
|
1812 |
int minimumIntegerDigits = minIntDigits; |
|
1813 |
if (repeat > 1 && repeat > minIntDigits) { |
|
1814 |
// A repeating range is defined; adjust to it as follows. |
|
1815 |
// If repeat == 3, we have 6,5,4=>3; 3,2,1=>0; 0,-1,-2=>-3; |
|
1816 |
// -3,-4,-5=>-6, etc. This takes into account that the |
|
1817 |
// exponent we have here is off by one from what we expect; |
|
1818 |
// it is for the format 0.MMMMMx10^n. |
|
1819 |
if (exponent >= 1) { |
|
1820 |
exponent = ((exponent - 1) / repeat) * repeat; |
|
1821 |
} else { |
|
1822 |
// integer division rounds towards 0 |
|
1823 |
exponent = ((exponent - repeat) / repeat) * repeat; |
|
1824 |
} |
|
1825 |
minimumIntegerDigits = 1; |
|
1826 |
} else { |
|
1827 |
// No repeating range is defined; use minimum integer digits. |
|
1828 |
exponent -= minimumIntegerDigits; |
|
1829 |
} |
|
1830 |
||
1831 |
// We now output a minimum number of digits, and more if there |
|
1832 |
// are more digits, up to the maximum number of digits. We |
|
1833 |
// place the decimal point after the "integer" digits, which |
|
1834 |
// are the first (decimalAt - exponent) digits. |
|
1835 |
int minimumDigits = minIntDigits + minFraDigits; |
|
1836 |
if (minimumDigits < 0) { // overflow? |
|
1837 |
minimumDigits = Integer.MAX_VALUE; |
|
1838 |
} |
|
1839 |
||
1840 |
// The number of integer digits is handled specially if the number |
|
1841 |
// is zero, since then there may be no digits. |
|
1842 |
int integerDigits = digitList.isZero() ? minimumIntegerDigits : |
|
1843 |
digitList.decimalAt - exponent; |
|
1844 |
if (minimumDigits < integerDigits) { |
|
1845 |
minimumDigits = integerDigits; |
|
1846 |
} |
|
1847 |
int totalDigits = digitList.count; |
|
1848 |
if (minimumDigits > totalDigits) { |
|
1849 |
totalDigits = minimumDigits; |
|
1850 |
} |
|
1851 |
boolean addedDecimalSeparator = false; |
|
1852 |
||
1853 |
for (int i=0; i<totalDigits; ++i) { |
|
1854 |
if (i == integerDigits) { |
|
1855 |
// Record field information for caller. |
|
1856 |
iFieldEnd = result.length(); |
|
1857 |
||
1858 |
result.append(decimal); |
|
1859 |
addedDecimalSeparator = true; |
|
1860 |
||
1861 |
// Record field information for caller. |
|
1862 |
fFieldStart = result.length(); |
|
1863 |
} |
|
1864 |
result.append((i < digitList.count) ? |
|
52869 | 1865 |
(char)(digitList.digits[i] + zeroDelta) : |
1866 |
zero); |
|
2 | 1867 |
} |
1868 |
||
1869 |
if (decimalSeparatorAlwaysShown && totalDigits == integerDigits) { |
|
1870 |
// Record field information for caller. |
|
1871 |
iFieldEnd = result.length(); |
|
1872 |
||
1873 |
result.append(decimal); |
|
1874 |
addedDecimalSeparator = true; |
|
1875 |
||
1876 |
// Record field information for caller. |
|
1877 |
fFieldStart = result.length(); |
|
1878 |
} |
|
1879 |
||
1880 |
// Record field information |
|
1881 |
if (iFieldEnd == -1) { |
|
1882 |
iFieldEnd = result.length(); |
|
1883 |
} |
|
1884 |
delegate.formatted(INTEGER_FIELD, Field.INTEGER, Field.INTEGER, |
|
52869 | 1885 |
iFieldStart, iFieldEnd, result); |
2 | 1886 |
if (addedDecimalSeparator) { |
1887 |
delegate.formatted(Field.DECIMAL_SEPARATOR, |
|
52869 | 1888 |
Field.DECIMAL_SEPARATOR, |
1889 |
iFieldEnd, fFieldStart, result); |
|
2 | 1890 |
} |
1891 |
if (fFieldStart == -1) { |
|
1892 |
fFieldStart = result.length(); |
|
1893 |
} |
|
1894 |
delegate.formatted(FRACTION_FIELD, Field.FRACTION, Field.FRACTION, |
|
52869 | 1895 |
fFieldStart, result.length(), result); |
2 | 1896 |
|
1897 |
// The exponent is output using the pattern-specified minimum |
|
1898 |
// exponent digits. There is no maximum limit to the exponent |
|
1899 |
// digits, since truncating the exponent would result in an |
|
1900 |
// unacceptable inaccuracy. |
|
1901 |
int fieldStart = result.length(); |
|
1902 |
||
1903 |
result.append(symbols.getExponentSeparator()); |
|
1904 |
||
1905 |
delegate.formatted(Field.EXPONENT_SYMBOL, Field.EXPONENT_SYMBOL, |
|
52869 | 1906 |
fieldStart, result.length(), result); |
2 | 1907 |
|
1908 |
// For zero values, we force the exponent to zero. We |
|
1909 |
// must do this here, and not earlier, because the value |
|
1910 |
// is used to determine integer digit count above. |
|
1911 |
if (digitList.isZero()) { |
|
1912 |
exponent = 0; |
|
1913 |
} |
|
1914 |
||
1915 |
boolean negativeExponent = exponent < 0; |
|
1916 |
if (negativeExponent) { |
|
1917 |
exponent = -exponent; |
|
1918 |
fieldStart = result.length(); |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
1919 |
result.append(symbols.getMinusSignText()); |
2 | 1920 |
delegate.formatted(Field.EXPONENT_SIGN, Field.EXPONENT_SIGN, |
52869 | 1921 |
fieldStart, result.length(), result); |
2 | 1922 |
} |
1923 |
digitList.set(negativeExponent, exponent); |
|
1924 |
||
1925 |
int eFieldStart = result.length(); |
|
1926 |
||
1927 |
for (int i=digitList.decimalAt; i<minExponentDigits; ++i) { |
|
1928 |
result.append(zero); |
|
1929 |
} |
|
1930 |
for (int i=0; i<digitList.decimalAt; ++i) { |
|
1931 |
result.append((i < digitList.count) ? |
|
52869 | 1932 |
(char)(digitList.digits[i] + zeroDelta) : zero); |
2 | 1933 |
} |
1934 |
delegate.formatted(Field.EXPONENT, Field.EXPONENT, eFieldStart, |
|
52869 | 1935 |
result.length(), result); |
2 | 1936 |
} else { |
1937 |
int iFieldStart = result.length(); |
|
1938 |
||
1939 |
// Output the integer portion. Here 'count' is the total |
|
1940 |
// number of integer digits we will display, including both |
|
1941 |
// leading zeros required to satisfy getMinimumIntegerDigits, |
|
1942 |
// and actual digits present in the number. |
|
1943 |
int count = minIntDigits; |
|
1944 |
int digitIndex = 0; // Index into digitList.fDigits[] |
|
1945 |
if (digitList.decimalAt > 0 && count < digitList.decimalAt) { |
|
1946 |
count = digitList.decimalAt; |
|
1947 |
} |
|
1948 |
||
1949 |
// Handle the case where getMaximumIntegerDigits() is smaller |
|
1950 |
// than the real number of integer digits. If this is so, we |
|
1951 |
// output the least significant max integer digits. For example, |
|
1952 |
// the value 1997 printed with 2 max integer digits is just "97". |
|
1953 |
if (count > maxIntDigits) { |
|
1954 |
count = maxIntDigits; |
|
1955 |
digitIndex = digitList.decimalAt - count; |
|
1956 |
} |
|
1957 |
||
1958 |
int sizeBeforeIntegerPart = result.length(); |
|
1959 |
for (int i=count-1; i>=0; --i) { |
|
1960 |
if (i < digitList.decimalAt && digitIndex < digitList.count) { |
|
1961 |
// Output a real digit |
|
1962 |
result.append((char)(digitList.digits[digitIndex++] + zeroDelta)); |
|
1963 |
} else { |
|
1964 |
// Output a leading zero |
|
1965 |
result.append(zero); |
|
1966 |
} |
|
1967 |
||
1968 |
// Output grouping separator if necessary. Don't output a |
|
1969 |
// grouping separator if i==0 though; that's at the end of |
|
1970 |
// the integer part. |
|
1971 |
if (isGroupingUsed() && i>0 && (groupingSize != 0) && |
|
52869 | 1972 |
(i % groupingSize == 0)) { |
2 | 1973 |
int gStart = result.length(); |
1974 |
result.append(grouping); |
|
1975 |
delegate.formatted(Field.GROUPING_SEPARATOR, |
|
52869 | 1976 |
Field.GROUPING_SEPARATOR, gStart, |
1977 |
result.length(), result); |
|
2 | 1978 |
} |
1979 |
} |
|
1980 |
||
1981 |
// Determine whether or not there are any printable fractional |
|
1982 |
// digits. If we've used up the digits we know there aren't. |
|
1983 |
boolean fractionPresent = (minFraDigits > 0) || |
|
52869 | 1984 |
(!isInteger && digitIndex < digitList.count); |
2 | 1985 |
|
1986 |
// If there is no fraction present, and we haven't printed any |
|
1987 |
// integer digits, then print a zero. Otherwise we won't print |
|
1988 |
// _any_ digits, and we won't be able to parse this string. |
|
1989 |
if (!fractionPresent && result.length() == sizeBeforeIntegerPart) { |
|
1990 |
result.append(zero); |
|
1991 |
} |
|
1992 |
||
1993 |
delegate.formatted(INTEGER_FIELD, Field.INTEGER, Field.INTEGER, |
|
52869 | 1994 |
iFieldStart, result.length(), result); |
2 | 1995 |
|
1996 |
// Output the decimal separator if we always do so. |
|
1997 |
int sStart = result.length(); |
|
1998 |
if (decimalSeparatorAlwaysShown || fractionPresent) { |
|
1999 |
result.append(decimal); |
|
2000 |
} |
|
2001 |
||
2002 |
if (sStart != result.length()) { |
|
2003 |
delegate.formatted(Field.DECIMAL_SEPARATOR, |
|
52869 | 2004 |
Field.DECIMAL_SEPARATOR, |
2005 |
sStart, result.length(), result); |
|
2 | 2006 |
} |
2007 |
int fFieldStart = result.length(); |
|
2008 |
||
2009 |
for (int i=0; i < maxFraDigits; ++i) { |
|
2010 |
// Here is where we escape from the loop. We escape if we've |
|
2011 |
// output the maximum fraction digits (specified in the for |
|
2012 |
// expression above). |
|
2013 |
// We also stop when we've output the minimum digits and either: |
|
2014 |
// we have an integer, so there is no fractional stuff to |
|
2015 |
// display, or we're out of significant digits. |
|
2016 |
if (i >= minFraDigits && |
|
52869 | 2017 |
(isInteger || digitIndex >= digitList.count)) { |
2 | 2018 |
break; |
2019 |
} |
|
2020 |
||
2021 |
// Output leading fractional zeros. These are zeros that come |
|
2022 |
// after the decimal but before any significant digits. These |
|
2023 |
// are only output if abs(number being formatted) < 1.0. |
|
2024 |
if (-1-i > (digitList.decimalAt-1)) { |
|
2025 |
result.append(zero); |
|
2026 |
continue; |
|
2027 |
} |
|
2028 |
||
2029 |
// Output a digit, if we have any precision left, or a |
|
2030 |
// zero if we don't. We don't want to output noise digits. |
|
2031 |
if (!isInteger && digitIndex < digitList.count) { |
|
2032 |
result.append((char)(digitList.digits[digitIndex++] + zeroDelta)); |
|
2033 |
} else { |
|
2034 |
result.append(zero); |
|
2035 |
} |
|
2036 |
} |
|
2037 |
||
2038 |
// Record field information for caller. |
|
2039 |
delegate.formatted(FRACTION_FIELD, Field.FRACTION, Field.FRACTION, |
|
52869 | 2040 |
fFieldStart, result.length(), result); |
2 | 2041 |
} |
2042 |
} |
|
2043 |
||
2044 |
/** |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2045 |
* Appends the String {@code string} to {@code result}. |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2046 |
* {@code delegate} is notified of all the |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2047 |
* {@code FieldPosition}s in {@code positions}. |
2 | 2048 |
* <p> |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2049 |
* If one of the {@code FieldPosition}s in {@code positions} |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2050 |
* identifies a {@code SIGN} attribute, it is mapped to |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2051 |
* {@code signAttribute}. This is used |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2052 |
* to map the {@code SIGN} attribute to the {@code EXPONENT} |
2 | 2053 |
* attribute as necessary. |
2054 |
* <p> |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2055 |
* This is used by {@code subformat} to add the prefix/suffix. |
2 | 2056 |
*/ |
2057 |
private void append(StringBuffer result, String string, |
|
2058 |
FieldDelegate delegate, |
|
2059 |
FieldPosition[] positions, |
|
2060 |
Format.Field signAttribute) { |
|
2061 |
int start = result.length(); |
|
2062 |
||
53018
8bf9268df0e2
8215281: Use String.isEmpty() when applicable in java.base
redestad
parents:
52869
diff
changeset
|
2063 |
if (!string.isEmpty()) { |
2 | 2064 |
result.append(string); |
2065 |
for (int counter = 0, max = positions.length; counter < max; |
|
2066 |
counter++) { |
|
2067 |
FieldPosition fp = positions[counter]; |
|
2068 |
Format.Field attribute = fp.getFieldAttribute(); |
|
2069 |
||
2070 |
if (attribute == Field.SIGN) { |
|
2071 |
attribute = signAttribute; |
|
2072 |
} |
|
2073 |
delegate.formatted(attribute, attribute, |
|
2074 |
start + fp.getBeginIndex(), |
|
2075 |
start + fp.getEndIndex(), result); |
|
2076 |
} |
|
2077 |
} |
|
2078 |
} |
|
2079 |
||
2080 |
/** |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2081 |
* Parses text from a string to produce a {@code Number}. |
2 | 2082 |
* <p> |
2083 |
* The method attempts to parse text starting at the index given by |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2084 |
* {@code pos}. |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2085 |
* If parsing succeeds, then the index of {@code pos} is updated |
2 | 2086 |
* to the index after the last character used (parsing does not necessarily |
2087 |
* use all characters up to the end of the string), and the parsed |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2088 |
* number is returned. The updated {@code pos} can be used to |
2 | 2089 |
* indicate the starting point for the next call to this method. |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2090 |
* If an error occurs, then the index of {@code pos} is not |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2091 |
* changed, the error index of {@code pos} is set to the index of |
2 | 2092 |
* the character where the error occurred, and null is returned. |
2093 |
* <p> |
|
2094 |
* The subclass returned depends on the value of {@link #isParseBigDecimal} |
|
2095 |
* as well as on the string being parsed. |
|
2096 |
* <ul> |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2097 |
* <li>If {@code isParseBigDecimal()} is false (the default), |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2098 |
* most integer values are returned as {@code Long} |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2099 |
* objects, no matter how they are written: {@code "17"} and |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2100 |
* {@code "17.000"} both parse to {@code Long(17)}. |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2101 |
* Values that cannot fit into a {@code Long} are returned as |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2102 |
* {@code Double}s. This includes values with a fractional part, |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2103 |
* infinite values, {@code NaN}, and the value -0.0. |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2104 |
* {@code DecimalFormat} does <em>not</em> decide whether to |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2105 |
* return a {@code Double} or a {@code Long} based on the |
2 | 2106 |
* presence of a decimal separator in the source string. Doing so |
2107 |
* would prevent integers that overflow the mantissa of a double, |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2108 |
* such as {@code "-9,223,372,036,854,775,808.00"}, from being |
2 | 2109 |
* parsed accurately. |
2110 |
* <p> |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2111 |
* Callers may use the {@code Number} methods |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2112 |
* {@code doubleValue}, {@code longValue}, etc., to obtain |
2 | 2113 |
* the type they want. |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2114 |
* <li>If {@code isParseBigDecimal()} is true, values are returned |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2115 |
* as {@code BigDecimal} objects. The values are the ones |
2 | 2116 |
* constructed by {@link java.math.BigDecimal#BigDecimal(String)} |
2117 |
* for corresponding strings in locale-independent format. The |
|
2118 |
* special cases negative and positive infinity and NaN are returned |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2119 |
* as {@code Double} instances holding the values of the |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2120 |
* corresponding {@code Double} constants. |
2 | 2121 |
* </ul> |
2122 |
* <p> |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2123 |
* {@code DecimalFormat} parses all Unicode characters that represent |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2124 |
* decimal digits, as defined by {@code Character.digit()}. In |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2125 |
* addition, {@code DecimalFormat} also recognizes as digits the ten |
2 | 2126 |
* consecutive characters starting with the localized zero digit defined in |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2127 |
* the {@code DecimalFormatSymbols} object. |
2 | 2128 |
* |
2129 |
* @param text the string to be parsed |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2130 |
* @param pos A {@code ParsePosition} object with index and error |
2 | 2131 |
* index information as described above. |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2132 |
* @return the parsed value, or {@code null} if the parse fails |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
2133 |
* @throws NullPointerException if {@code text} or |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2134 |
* {@code pos} is null. |
2 | 2135 |
*/ |
13583 | 2136 |
@Override |
2 | 2137 |
public Number parse(String text, ParsePosition pos) { |
2138 |
// special case NaN |
|
2139 |
if (text.regionMatches(pos.index, symbols.getNaN(), 0, symbols.getNaN().length())) { |
|
2140 |
pos.index = pos.index + symbols.getNaN().length(); |
|
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
25859
diff
changeset
|
2141 |
return Double.valueOf(Double.NaN); |
2 | 2142 |
} |
2143 |
||
2144 |
boolean[] status = new boolean[STATUS_LENGTH]; |
|
2145 |
if (!subparse(text, pos, positivePrefix, negativePrefix, digitList, false, status)) { |
|
2146 |
return null; |
|
2147 |
} |
|
2148 |
||
2149 |
// special case INFINITY |
|
2150 |
if (status[STATUS_INFINITE]) { |
|
2151 |
if (status[STATUS_POSITIVE] == (multiplier >= 0)) { |
|
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
25859
diff
changeset
|
2152 |
return Double.valueOf(Double.POSITIVE_INFINITY); |
2 | 2153 |
} else { |
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
25859
diff
changeset
|
2154 |
return Double.valueOf(Double.NEGATIVE_INFINITY); |
2 | 2155 |
} |
2156 |
} |
|
2157 |
||
2158 |
if (multiplier == 0) { |
|
2159 |
if (digitList.isZero()) { |
|
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
25859
diff
changeset
|
2160 |
return Double.valueOf(Double.NaN); |
2 | 2161 |
} else if (status[STATUS_POSITIVE]) { |
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
25859
diff
changeset
|
2162 |
return Double.valueOf(Double.POSITIVE_INFINITY); |
2 | 2163 |
} else { |
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
25859
diff
changeset
|
2164 |
return Double.valueOf(Double.NEGATIVE_INFINITY); |
2 | 2165 |
} |
2166 |
} |
|
2167 |
||
2168 |
if (isParseBigDecimal()) { |
|
2169 |
BigDecimal bigDecimalResult = digitList.getBigDecimal(); |
|
2170 |
||
2171 |
if (multiplier != 1) { |
|
2172 |
try { |
|
2173 |
bigDecimalResult = bigDecimalResult.divide(getBigDecimalMultiplier()); |
|
2174 |
} |
|
2175 |
catch (ArithmeticException e) { // non-terminating decimal expansion |
|
2176 |
bigDecimalResult = bigDecimalResult.divide(getBigDecimalMultiplier(), roundingMode); |
|
2177 |
} |
|
2178 |
} |
|
2179 |
||
2180 |
if (!status[STATUS_POSITIVE]) { |
|
2181 |
bigDecimalResult = bigDecimalResult.negate(); |
|
2182 |
} |
|
2183 |
return bigDecimalResult; |
|
2184 |
} else { |
|
2185 |
boolean gotDouble = true; |
|
2186 |
boolean gotLongMinimum = false; |
|
2187 |
double doubleResult = 0.0; |
|
2188 |
long longResult = 0; |
|
2189 |
||
2190 |
// Finally, have DigitList parse the digits into a value. |
|
2191 |
if (digitList.fitsIntoLong(status[STATUS_POSITIVE], isParseIntegerOnly())) { |
|
2192 |
gotDouble = false; |
|
2193 |
longResult = digitList.getLong(); |
|
2194 |
if (longResult < 0) { // got Long.MIN_VALUE |
|
2195 |
gotLongMinimum = true; |
|
2196 |
} |
|
2197 |
} else { |
|
2198 |
doubleResult = digitList.getDouble(); |
|
2199 |
} |
|
2200 |
||
2201 |
// Divide by multiplier. We have to be careful here not to do |
|
2202 |
// unneeded conversions between double and long. |
|
2203 |
if (multiplier != 1) { |
|
2204 |
if (gotDouble) { |
|
2205 |
doubleResult /= multiplier; |
|
2206 |
} else { |
|
2207 |
// Avoid converting to double if we can |
|
2208 |
if (longResult % multiplier == 0) { |
|
2209 |
longResult /= multiplier; |
|
2210 |
} else { |
|
2211 |
doubleResult = ((double)longResult) / multiplier; |
|
2212 |
gotDouble = true; |
|
2213 |
} |
|
2214 |
} |
|
2215 |
} |
|
2216 |
||
2217 |
if (!status[STATUS_POSITIVE] && !gotLongMinimum) { |
|
2218 |
doubleResult = -doubleResult; |
|
2219 |
longResult = -longResult; |
|
2220 |
} |
|
2221 |
||
2222 |
// At this point, if we divided the result by the multiplier, the |
|
2223 |
// result may fit into a long. We check for this case and return |
|
2224 |
// a long if possible. |
|
2225 |
// We must do this AFTER applying the negative (if appropriate) |
|
2226 |
// in order to handle the case of LONG_MIN; otherwise, if we do |
|
2227 |
// this with a positive value -LONG_MIN, the double is > 0, but |
|
2228 |
// the long is < 0. We also must retain a double in the case of |
|
2229 |
// -0.0, which will compare as == to a long 0 cast to a double |
|
2230 |
// (bug 4162852). |
|
2231 |
if (multiplier != 1 && gotDouble) { |
|
2232 |
longResult = (long)doubleResult; |
|
2233 |
gotDouble = ((doubleResult != (double)longResult) || |
|
2234 |
(doubleResult == 0.0 && 1/doubleResult < 0.0)) && |
|
2235 |
!isParseIntegerOnly(); |
|
2236 |
} |
|
2237 |
||
37521
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
25859
diff
changeset
|
2238 |
// cast inside of ?: because of binary numeric promotion, JLS 15.25 |
b6e0f285c998
8145468: update java.lang APIs with new deprecations
smarks
parents:
25859
diff
changeset
|
2239 |
return gotDouble ? (Number)doubleResult : (Number)longResult; |
2 | 2240 |
} |
2241 |
} |
|
2242 |
||
2243 |
/** |
|
2244 |
* Return a BigInteger multiplier. |
|
2245 |
*/ |
|
2246 |
private BigInteger getBigIntegerMultiplier() { |
|
2247 |
if (bigIntegerMultiplier == null) { |
|
2248 |
bigIntegerMultiplier = BigInteger.valueOf(multiplier); |
|
2249 |
} |
|
2250 |
return bigIntegerMultiplier; |
|
2251 |
} |
|
2252 |
private transient BigInteger bigIntegerMultiplier; |
|
2253 |
||
2254 |
/** |
|
2255 |
* Return a BigDecimal multiplier. |
|
2256 |
*/ |
|
2257 |
private BigDecimal getBigDecimalMultiplier() { |
|
2258 |
if (bigDecimalMultiplier == null) { |
|
2259 |
bigDecimalMultiplier = new BigDecimal(multiplier); |
|
2260 |
} |
|
2261 |
return bigDecimalMultiplier; |
|
2262 |
} |
|
2263 |
private transient BigDecimal bigDecimalMultiplier; |
|
2264 |
||
2265 |
private static final int STATUS_INFINITE = 0; |
|
2266 |
private static final int STATUS_POSITIVE = 1; |
|
2267 |
private static final int STATUS_LENGTH = 2; |
|
2268 |
||
2269 |
/** |
|
2270 |
* Parse the given text into a number. The text is parsed beginning at |
|
2271 |
* parsePosition, until an unparseable character is seen. |
|
2272 |
* @param text The string to parse. |
|
2273 |
* @param parsePosition The position at which to being parsing. Upon |
|
2274 |
* return, the first unparseable character. |
|
2275 |
* @param digits The DigitList to set to the parsed value. |
|
2276 |
* @param isExponent If true, parse an exponent. This means no |
|
2277 |
* infinite values and integer only. |
|
2278 |
* @param status Upon return contains boolean status flags indicating |
|
2279 |
* whether the value was infinite and whether it was positive. |
|
2280 |
*/ |
|
2281 |
private final boolean subparse(String text, ParsePosition parsePosition, |
|
52869 | 2282 |
String positivePrefix, String negativePrefix, |
2283 |
DigitList digits, boolean isExponent, |
|
2284 |
boolean status[]) { |
|
2 | 2285 |
int position = parsePosition.index; |
2286 |
int oldStart = parsePosition.index; |
|
2287 |
boolean gotPositive, gotNegative; |
|
2288 |
||
2289 |
// check for positivePrefix; take longest |
|
2290 |
gotPositive = text.regionMatches(position, positivePrefix, 0, |
|
52869 | 2291 |
positivePrefix.length()); |
2 | 2292 |
gotNegative = text.regionMatches(position, negativePrefix, 0, |
52869 | 2293 |
negativePrefix.length()); |
2 | 2294 |
|
2295 |
if (gotPositive && gotNegative) { |
|
2296 |
if (positivePrefix.length() > negativePrefix.length()) { |
|
2297 |
gotNegative = false; |
|
2298 |
} else if (positivePrefix.length() < negativePrefix.length()) { |
|
2299 |
gotPositive = false; |
|
2300 |
} |
|
2301 |
} |
|
2302 |
||
2303 |
if (gotPositive) { |
|
2304 |
position += positivePrefix.length(); |
|
2305 |
} else if (gotNegative) { |
|
2306 |
position += negativePrefix.length(); |
|
2307 |
} else { |
|
2308 |
parsePosition.errorIndex = position; |
|
2309 |
return false; |
|
2310 |
} |
|
2311 |
||
52869 | 2312 |
position = subparseNumber(text, position, digits, true, isExponent, status); |
2313 |
if (position == -1) { |
|
2314 |
parsePosition.index = oldStart; |
|
2315 |
parsePosition.errorIndex = oldStart; |
|
2316 |
return false; |
|
2317 |
} |
|
2318 |
||
2319 |
// Check for suffix |
|
2320 |
if (!isExponent) { |
|
2321 |
if (gotPositive) { |
|
2322 |
gotPositive = text.regionMatches(position,positiveSuffix,0, |
|
2323 |
positiveSuffix.length()); |
|
2324 |
} |
|
2325 |
if (gotNegative) { |
|
2326 |
gotNegative = text.regionMatches(position,negativeSuffix,0, |
|
2327 |
negativeSuffix.length()); |
|
2328 |
} |
|
2329 |
||
2330 |
// If both match, take longest |
|
2331 |
if (gotPositive && gotNegative) { |
|
2332 |
if (positiveSuffix.length() > negativeSuffix.length()) { |
|
2333 |
gotNegative = false; |
|
2334 |
} else if (positiveSuffix.length() < negativeSuffix.length()) { |
|
2335 |
gotPositive = false; |
|
2336 |
} |
|
2337 |
} |
|
2338 |
||
2339 |
// Fail if neither or both |
|
2340 |
if (gotPositive == gotNegative) { |
|
2341 |
parsePosition.errorIndex = position; |
|
2342 |
return false; |
|
2343 |
} |
|
2344 |
||
2345 |
parsePosition.index = position + |
|
2346 |
(gotPositive ? positiveSuffix.length() : negativeSuffix.length()); // mark success! |
|
2347 |
} else { |
|
2348 |
parsePosition.index = position; |
|
2349 |
} |
|
2350 |
||
2351 |
status[STATUS_POSITIVE] = gotPositive; |
|
2352 |
if (parsePosition.index == oldStart) { |
|
2353 |
parsePosition.errorIndex = position; |
|
2354 |
return false; |
|
2355 |
} |
|
2356 |
return true; |
|
2357 |
} |
|
2358 |
||
2359 |
/** |
|
2360 |
* Parses a number from the given {@code text}. The text is parsed |
|
2361 |
* beginning at position, until an unparseable character is seen. |
|
2362 |
* |
|
2363 |
* @param text the string to parse |
|
2364 |
* @param position the position at which parsing begins |
|
2365 |
* @param digits the DigitList to set to the parsed value |
|
2366 |
* @param checkExponent whether to check for exponential number |
|
2367 |
* @param isExponent if the exponential part is encountered |
|
2368 |
* @param status upon return contains boolean status flags indicating |
|
2369 |
* whether the value is infinite and whether it is |
|
2370 |
* positive |
|
2371 |
* @return returns the position of the first unparseable character or |
|
2372 |
* -1 in case of no valid number parsed |
|
2373 |
*/ |
|
2374 |
int subparseNumber(String text, int position, |
|
2375 |
DigitList digits, boolean checkExponent, |
|
2376 |
boolean isExponent, boolean status[]) { |
|
2 | 2377 |
// process digits or Inf, find decimal position |
2378 |
status[STATUS_INFINITE] = false; |
|
2379 |
if (!isExponent && text.regionMatches(position,symbols.getInfinity(),0, |
|
52869 | 2380 |
symbols.getInfinity().length())) { |
2 | 2381 |
position += symbols.getInfinity().length(); |
2382 |
status[STATUS_INFINITE] = true; |
|
2383 |
} else { |
|
2384 |
// We now have a string of digits, possibly with grouping symbols, |
|
2385 |
// and decimal points. We want to process these into a DigitList. |
|
2386 |
// We don't want to put a bunch of leading zeros into the DigitList |
|
2387 |
// though, so we keep track of the location of the decimal point, |
|
2388 |
// put only significant digits into the DigitList, and adjust the |
|
2389 |
// exponent as needed. |
|
2390 |
||
2391 |
digits.decimalAt = digits.count = 0; |
|
2392 |
char zero = symbols.getZeroDigit(); |
|
2393 |
char decimal = isCurrencyFormat ? |
|
52869 | 2394 |
symbols.getMonetaryDecimalSeparator() : |
2395 |
symbols.getDecimalSeparator(); |
|
2 | 2396 |
char grouping = symbols.getGroupingSeparator(); |
2397 |
String exponentString = symbols.getExponentSeparator(); |
|
2398 |
boolean sawDecimal = false; |
|
2399 |
boolean sawExponent = false; |
|
2400 |
boolean sawDigit = false; |
|
2401 |
int exponent = 0; // Set to the exponent value, if any |
|
2402 |
||
2403 |
// We have to track digitCount ourselves, because digits.count will |
|
2404 |
// pin when the maximum allowable digits is reached. |
|
2405 |
int digitCount = 0; |
|
2406 |
||
52869 | 2407 |
int backup = -1; |
2 | 2408 |
for (; position < text.length(); ++position) { |
2409 |
char ch = text.charAt(position); |
|
2410 |
||
2411 |
/* We recognize all digit ranges, not only the Latin digit range |
|
2412 |
* '0'..'9'. We do so by using the Character.digit() method, |
|
2413 |
* which converts a valid Unicode digit to the range 0..9. |
|
2414 |
* |
|
2415 |
* The character 'ch' may be a digit. If so, place its value |
|
2416 |
* from 0 to 9 in 'digit'. First try using the locale digit, |
|
2417 |
* which may or MAY NOT be a standard Unicode digit range. If |
|
2418 |
* this fails, try using the standard Unicode digit ranges by |
|
2419 |
* calling Character.digit(). If this also fails, digit will |
|
2420 |
* have a value outside the range 0..9. |
|
2421 |
*/ |
|
2422 |
int digit = ch - zero; |
|
2423 |
if (digit < 0 || digit > 9) { |
|
2424 |
digit = Character.digit(ch, 10); |
|
2425 |
} |
|
2426 |
||
2427 |
if (digit == 0) { |
|
2428 |
// Cancel out backup setting (see grouping handler below) |
|
2429 |
backup = -1; // Do this BEFORE continue statement below!!! |
|
2430 |
sawDigit = true; |
|
2431 |
||
2432 |
// Handle leading zeros |
|
2433 |
if (digits.count == 0) { |
|
2434 |
// Ignore leading zeros in integer part of number. |
|
2435 |
if (!sawDecimal) { |
|
2436 |
continue; |
|
2437 |
} |
|
2438 |
||
2439 |
// If we have seen the decimal, but no significant |
|
2440 |
// digits yet, then we account for leading zeros by |
|
2441 |
// decrementing the digits.decimalAt into negative |
|
2442 |
// values. |
|
2443 |
--digits.decimalAt; |
|
2444 |
} else { |
|
2445 |
++digitCount; |
|
2446 |
digits.append((char)(digit + '0')); |
|
2447 |
} |
|
2448 |
} else if (digit > 0 && digit <= 9) { // [sic] digit==0 handled above |
|
2449 |
sawDigit = true; |
|
2450 |
++digitCount; |
|
2451 |
digits.append((char)(digit + '0')); |
|
2452 |
||
2453 |
// Cancel out backup setting (see grouping handler below) |
|
2454 |
backup = -1; |
|
2455 |
} else if (!isExponent && ch == decimal) { |
|
2456 |
// If we're only parsing integers, or if we ALREADY saw the |
|
2457 |
// decimal, then don't parse this one. |
|
2458 |
if (isParseIntegerOnly() || sawDecimal) { |
|
2459 |
break; |
|
2460 |
} |
|
2461 |
digits.decimalAt = digitCount; // Not digits.count! |
|
2462 |
sawDecimal = true; |
|
2463 |
} else if (!isExponent && ch == grouping && isGroupingUsed()) { |
|
2464 |
if (sawDecimal) { |
|
2465 |
break; |
|
2466 |
} |
|
2467 |
// Ignore grouping characters, if we are using them, but |
|
2468 |
// require that they be followed by a digit. Otherwise |
|
2469 |
// we backup and reprocess them. |
|
2470 |
backup = position; |
|
52869 | 2471 |
} else if (checkExponent && !isExponent && text.regionMatches(position, exponentString, 0, exponentString.length()) |
2472 |
&& !sawExponent) { |
|
2 | 2473 |
// Process the exponent by recursively calling this method. |
52869 | 2474 |
ParsePosition pos = new ParsePosition(position + exponentString.length()); |
2 | 2475 |
boolean[] stat = new boolean[STATUS_LENGTH]; |
2476 |
DigitList exponentDigits = new DigitList(); |
|
2477 |
||
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2478 |
if (subparse(text, pos, "", symbols.getMinusSignText(), exponentDigits, true, stat) && |
52869 | 2479 |
exponentDigits.fitsIntoLong(stat[STATUS_POSITIVE], true)) { |
2 | 2480 |
position = pos.index; // Advance past the exponent |
2481 |
exponent = (int)exponentDigits.getLong(); |
|
2482 |
if (!stat[STATUS_POSITIVE]) { |
|
2483 |
exponent = -exponent; |
|
2484 |
} |
|
2485 |
sawExponent = true; |
|
2486 |
} |
|
2487 |
break; // Whether we fail or succeed, we exit this loop |
|
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2488 |
} else { |
2 | 2489 |
break; |
2490 |
} |
|
2491 |
} |
|
2492 |
||
2493 |
if (backup != -1) { |
|
2494 |
position = backup; |
|
2495 |
} |
|
2496 |
||
2497 |
// If there was no decimal point we have an integer |
|
2498 |
if (!sawDecimal) { |
|
2499 |
digits.decimalAt = digitCount; // Not digits.count! |
|
2500 |
} |
|
2501 |
||
2502 |
// Adjust for exponent, if any |
|
2503 |
digits.decimalAt += exponent; |
|
2504 |
||
2505 |
// If none of the text string was recognized. For example, parse |
|
2506 |
// "x" with pattern "#0.00" (return index and error index both 0) |
|
2507 |
// parse "$" with pattern "$#0.00". (return index 0 and error |
|
2508 |
// index 1). |
|
2509 |
if (!sawDigit && digitCount == 0) { |
|
52869 | 2510 |
return -1; |
2 | 2511 |
} |
2512 |
} |
|
52869 | 2513 |
return position; |
2514 |
||
2 | 2515 |
} |
2516 |
||
2517 |
/** |
|
2518 |
* Returns a copy of the decimal format symbols, which is generally not |
|
2519 |
* changed by the programmer or user. |
|
2520 |
* @return a copy of the desired DecimalFormatSymbols |
|
2521 |
* @see java.text.DecimalFormatSymbols |
|
2522 |
*/ |
|
2523 |
public DecimalFormatSymbols getDecimalFormatSymbols() { |
|
2524 |
try { |
|
2525 |
// don't allow multiple references |
|
2526 |
return (DecimalFormatSymbols) symbols.clone(); |
|
2527 |
} catch (Exception foo) { |
|
2528 |
return null; // should never happen |
|
2529 |
} |
|
2530 |
} |
|
2531 |
||
2532 |
||
2533 |
/** |
|
2534 |
* Sets the decimal format symbols, which is generally not changed |
|
2535 |
* by the programmer or user. |
|
2536 |
* @param newSymbols desired DecimalFormatSymbols |
|
2537 |
* @see java.text.DecimalFormatSymbols |
|
2538 |
*/ |
|
2539 |
public void setDecimalFormatSymbols(DecimalFormatSymbols newSymbols) { |
|
2540 |
try { |
|
2541 |
// don't allow multiple references |
|
2542 |
symbols = (DecimalFormatSymbols) newSymbols.clone(); |
|
2543 |
expandAffixes(); |
|
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2544 |
fastPathCheckNeeded = true; |
2 | 2545 |
} catch (Exception foo) { |
2546 |
// should never happen |
|
2547 |
} |
|
2548 |
} |
|
2549 |
||
2550 |
/** |
|
2551 |
* Get the positive prefix. |
|
2552 |
* <P>Examples: +123, $123, sFr123 |
|
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2553 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2554 |
* @return the positive prefix |
2 | 2555 |
*/ |
2556 |
public String getPositivePrefix () { |
|
2557 |
return positivePrefix; |
|
2558 |
} |
|
2559 |
||
2560 |
/** |
|
2561 |
* Set the positive prefix. |
|
2562 |
* <P>Examples: +123, $123, sFr123 |
|
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2563 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2564 |
* @param newValue the new positive prefix |
2 | 2565 |
*/ |
2566 |
public void setPositivePrefix (String newValue) { |
|
2567 |
positivePrefix = newValue; |
|
2568 |
posPrefixPattern = null; |
|
2569 |
positivePrefixFieldPositions = null; |
|
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2570 |
fastPathCheckNeeded = true; |
2 | 2571 |
} |
2572 |
||
2573 |
/** |
|
2574 |
* Returns the FieldPositions of the fields in the prefix used for |
|
2575 |
* positive numbers. This is not used if the user has explicitly set |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2576 |
* a positive prefix via {@code setPositivePrefix}. This is |
2 | 2577 |
* lazily created. |
2578 |
* |
|
2579 |
* @return FieldPositions in positive prefix |
|
2580 |
*/ |
|
2581 |
private FieldPosition[] getPositivePrefixFieldPositions() { |
|
2582 |
if (positivePrefixFieldPositions == null) { |
|
2583 |
if (posPrefixPattern != null) { |
|
2584 |
positivePrefixFieldPositions = expandAffix(posPrefixPattern); |
|
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2585 |
} else { |
2 | 2586 |
positivePrefixFieldPositions = EmptyFieldPositionArray; |
2587 |
} |
|
2588 |
} |
|
2589 |
return positivePrefixFieldPositions; |
|
2590 |
} |
|
2591 |
||
2592 |
/** |
|
2593 |
* Get the negative prefix. |
|
2594 |
* <P>Examples: -123, ($123) (with negative suffix), sFr-123 |
|
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2595 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2596 |
* @return the negative prefix |
2 | 2597 |
*/ |
2598 |
public String getNegativePrefix () { |
|
2599 |
return negativePrefix; |
|
2600 |
} |
|
2601 |
||
2602 |
/** |
|
2603 |
* Set the negative prefix. |
|
2604 |
* <P>Examples: -123, ($123) (with negative suffix), sFr-123 |
|
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2605 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2606 |
* @param newValue the new negative prefix |
2 | 2607 |
*/ |
2608 |
public void setNegativePrefix (String newValue) { |
|
2609 |
negativePrefix = newValue; |
|
2610 |
negPrefixPattern = null; |
|
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2611 |
fastPathCheckNeeded = true; |
2 | 2612 |
} |
2613 |
||
2614 |
/** |
|
2615 |
* Returns the FieldPositions of the fields in the prefix used for |
|
2616 |
* negative numbers. This is not used if the user has explicitly set |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2617 |
* a negative prefix via {@code setNegativePrefix}. This is |
2 | 2618 |
* lazily created. |
2619 |
* |
|
2620 |
* @return FieldPositions in positive prefix |
|
2621 |
*/ |
|
2622 |
private FieldPosition[] getNegativePrefixFieldPositions() { |
|
2623 |
if (negativePrefixFieldPositions == null) { |
|
2624 |
if (negPrefixPattern != null) { |
|
2625 |
negativePrefixFieldPositions = expandAffix(negPrefixPattern); |
|
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2626 |
} else { |
2 | 2627 |
negativePrefixFieldPositions = EmptyFieldPositionArray; |
2628 |
} |
|
2629 |
} |
|
2630 |
return negativePrefixFieldPositions; |
|
2631 |
} |
|
2632 |
||
2633 |
/** |
|
2634 |
* Get the positive suffix. |
|
2635 |
* <P>Example: 123% |
|
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2636 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2637 |
* @return the positive suffix |
2 | 2638 |
*/ |
2639 |
public String getPositiveSuffix () { |
|
2640 |
return positiveSuffix; |
|
2641 |
} |
|
2642 |
||
2643 |
/** |
|
2644 |
* Set the positive suffix. |
|
2645 |
* <P>Example: 123% |
|
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2646 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2647 |
* @param newValue the new positive suffix |
2 | 2648 |
*/ |
2649 |
public void setPositiveSuffix (String newValue) { |
|
2650 |
positiveSuffix = newValue; |
|
2651 |
posSuffixPattern = null; |
|
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2652 |
fastPathCheckNeeded = true; |
2 | 2653 |
} |
2654 |
||
2655 |
/** |
|
2656 |
* Returns the FieldPositions of the fields in the suffix used for |
|
2657 |
* positive numbers. This is not used if the user has explicitly set |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2658 |
* a positive suffix via {@code setPositiveSuffix}. This is |
2 | 2659 |
* lazily created. |
2660 |
* |
|
2661 |
* @return FieldPositions in positive prefix |
|
2662 |
*/ |
|
2663 |
private FieldPosition[] getPositiveSuffixFieldPositions() { |
|
2664 |
if (positiveSuffixFieldPositions == null) { |
|
2665 |
if (posSuffixPattern != null) { |
|
2666 |
positiveSuffixFieldPositions = expandAffix(posSuffixPattern); |
|
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2667 |
} else { |
2 | 2668 |
positiveSuffixFieldPositions = EmptyFieldPositionArray; |
2669 |
} |
|
2670 |
} |
|
2671 |
return positiveSuffixFieldPositions; |
|
2672 |
} |
|
2673 |
||
2674 |
/** |
|
2675 |
* Get the negative suffix. |
|
2676 |
* <P>Examples: -123%, ($123) (with positive suffixes) |
|
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2677 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2678 |
* @return the negative suffix |
2 | 2679 |
*/ |
2680 |
public String getNegativeSuffix () { |
|
2681 |
return negativeSuffix; |
|
2682 |
} |
|
2683 |
||
2684 |
/** |
|
2685 |
* Set the negative suffix. |
|
2686 |
* <P>Examples: 123% |
|
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2687 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2688 |
* @param newValue the new negative suffix |
2 | 2689 |
*/ |
2690 |
public void setNegativeSuffix (String newValue) { |
|
2691 |
negativeSuffix = newValue; |
|
2692 |
negSuffixPattern = null; |
|
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2693 |
fastPathCheckNeeded = true; |
2 | 2694 |
} |
2695 |
||
2696 |
/** |
|
2697 |
* Returns the FieldPositions of the fields in the suffix used for |
|
2698 |
* negative numbers. This is not used if the user has explicitly set |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2699 |
* a negative suffix via {@code setNegativeSuffix}. This is |
2 | 2700 |
* lazily created. |
2701 |
* |
|
2702 |
* @return FieldPositions in positive prefix |
|
2703 |
*/ |
|
2704 |
private FieldPosition[] getNegativeSuffixFieldPositions() { |
|
2705 |
if (negativeSuffixFieldPositions == null) { |
|
2706 |
if (negSuffixPattern != null) { |
|
2707 |
negativeSuffixFieldPositions = expandAffix(negSuffixPattern); |
|
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2708 |
} else { |
2 | 2709 |
negativeSuffixFieldPositions = EmptyFieldPositionArray; |
2710 |
} |
|
2711 |
} |
|
2712 |
return negativeSuffixFieldPositions; |
|
2713 |
} |
|
2714 |
||
2715 |
/** |
|
2716 |
* Gets the multiplier for use in percent, per mille, and similar |
|
2717 |
* formats. |
|
2718 |
* |
|
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2719 |
* @return the multiplier |
2 | 2720 |
* @see #setMultiplier(int) |
2721 |
*/ |
|
2722 |
public int getMultiplier () { |
|
2723 |
return multiplier; |
|
2724 |
} |
|
2725 |
||
2726 |
/** |
|
2727 |
* Sets the multiplier for use in percent, per mille, and similar |
|
2728 |
* formats. |
|
2729 |
* For a percent format, set the multiplier to 100 and the suffixes to |
|
2730 |
* have '%' (for Arabic, use the Arabic percent sign). |
|
2731 |
* For a per mille format, set the multiplier to 1000 and the suffixes to |
|
2732 |
* have '\u2030'. |
|
2733 |
* |
|
2734 |
* <P>Example: with multiplier 100, 1.23 is formatted as "123", and |
|
2735 |
* "123" is parsed into 1.23. |
|
2736 |
* |
|
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2737 |
* @param newValue the new multiplier |
2 | 2738 |
* @see #getMultiplier |
2739 |
*/ |
|
2740 |
public void setMultiplier (int newValue) { |
|
2741 |
multiplier = newValue; |
|
2742 |
bigDecimalMultiplier = null; |
|
2743 |
bigIntegerMultiplier = null; |
|
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2744 |
fastPathCheckNeeded = true; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2745 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2746 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2747 |
/** |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2748 |
* {@inheritDoc} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2749 |
*/ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2750 |
@Override |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2751 |
public void setGroupingUsed(boolean newValue) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2752 |
super.setGroupingUsed(newValue); |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2753 |
fastPathCheckNeeded = true; |
2 | 2754 |
} |
2755 |
||
2756 |
/** |
|
2757 |
* Return the grouping size. Grouping size is the number of digits between |
|
2758 |
* grouping separators in the integer portion of a number. For example, |
|
58603
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
2759 |
* in the number "123,456.78", the grouping size is 3. Grouping size of |
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
2760 |
* zero designates that grouping is not used, which provides the same |
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
2761 |
* formatting as if calling {@link #setGroupingUsed(boolean) |
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
2762 |
* setGroupingUsed(false)}. |
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2763 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2764 |
* @return the grouping size |
2 | 2765 |
* @see #setGroupingSize |
2766 |
* @see java.text.NumberFormat#isGroupingUsed |
|
2767 |
* @see java.text.DecimalFormatSymbols#getGroupingSeparator |
|
2768 |
*/ |
|
2769 |
public int getGroupingSize () { |
|
2770 |
return groupingSize; |
|
2771 |
} |
|
2772 |
||
2773 |
/** |
|
2774 |
* Set the grouping size. Grouping size is the number of digits between |
|
2775 |
* grouping separators in the integer portion of a number. For example, |
|
58603
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
2776 |
* in the number "123,456.78", the grouping size is 3. Grouping size of |
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
2777 |
* zero designates that grouping is not used, which provides the same |
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
2778 |
* formatting as if calling {@link #setGroupingUsed(boolean) |
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
2779 |
* setGroupingUsed(false)}. |
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
2780 |
* <p> |
2 | 2781 |
* The value passed in is converted to a byte, which may lose information. |
58603
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
2782 |
* Values that are negative or greater than |
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
2783 |
* {@link java.lang.Byte#MAX_VALUE Byte.MAX_VALUE}, will throw an |
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
2784 |
* {@code IllegalArgumentException}. |
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2785 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2786 |
* @param newValue the new grouping size |
2 | 2787 |
* @see #getGroupingSize |
2788 |
* @see java.text.NumberFormat#setGroupingUsed |
|
2789 |
* @see java.text.DecimalFormatSymbols#setGroupingSeparator |
|
58603
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
2790 |
* @throws IllegalArgumentException if {@code newValue} is negative or |
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
2791 |
* greater than {@link java.lang.Byte#MAX_VALUE Byte.MAX_VALUE} |
2 | 2792 |
*/ |
2793 |
public void setGroupingSize (int newValue) { |
|
58603
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
2794 |
if (newValue < 0 || newValue > Byte.MAX_VALUE) { |
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
2795 |
throw new IllegalArgumentException( |
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
2796 |
"newValue is out of valid range. value: " + newValue); |
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
2797 |
} |
2 | 2798 |
groupingSize = (byte)newValue; |
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2799 |
fastPathCheckNeeded = true; |
2 | 2800 |
} |
2801 |
||
2802 |
/** |
|
2803 |
* Allows you to get the behavior of the decimal separator with integers. |
|
2804 |
* (The decimal separator will always appear with decimals.) |
|
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2805 |
* <P>Example: Decimal ON: 12345 → 12345.; OFF: 12345 → 12345 |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2806 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2807 |
* @return {@code true} if the decimal separator is always shown; |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2808 |
* {@code false} otherwise |
2 | 2809 |
*/ |
2810 |
public boolean isDecimalSeparatorAlwaysShown() { |
|
2811 |
return decimalSeparatorAlwaysShown; |
|
2812 |
} |
|
2813 |
||
2814 |
/** |
|
2815 |
* Allows you to set the behavior of the decimal separator with integers. |
|
2816 |
* (The decimal separator will always appear with decimals.) |
|
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2817 |
* <P>Example: Decimal ON: 12345 → 12345.; OFF: 12345 → 12345 |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2818 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2819 |
* @param newValue {@code true} if the decimal separator is always shown; |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2820 |
* {@code false} otherwise |
2 | 2821 |
*/ |
2822 |
public void setDecimalSeparatorAlwaysShown(boolean newValue) { |
|
2823 |
decimalSeparatorAlwaysShown = newValue; |
|
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2824 |
fastPathCheckNeeded = true; |
2 | 2825 |
} |
2826 |
||
2827 |
/** |
|
2828 |
* Returns whether the {@link #parse(java.lang.String, java.text.ParsePosition)} |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2829 |
* method returns {@code BigDecimal}. The default value is false. |
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2830 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2831 |
* @return {@code true} if the parse method returns BigDecimal; |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2832 |
* {@code false} otherwise |
2 | 2833 |
* @see #setParseBigDecimal |
2834 |
* @since 1.5 |
|
2835 |
*/ |
|
2836 |
public boolean isParseBigDecimal() { |
|
2837 |
return parseBigDecimal; |
|
2838 |
} |
|
2839 |
||
2840 |
/** |
|
2841 |
* Sets whether the {@link #parse(java.lang.String, java.text.ParsePosition)} |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
2842 |
* method returns {@code BigDecimal}. |
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2843 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2844 |
* @param newValue {@code true} if the parse method returns BigDecimal; |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2845 |
* {@code false} otherwise |
2 | 2846 |
* @see #isParseBigDecimal |
2847 |
* @since 1.5 |
|
2848 |
*/ |
|
2849 |
public void setParseBigDecimal(boolean newValue) { |
|
2850 |
parseBigDecimal = newValue; |
|
2851 |
} |
|
2852 |
||
2853 |
/** |
|
2854 |
* Standard override; no change in semantics. |
|
2855 |
*/ |
|
13583 | 2856 |
@Override |
2 | 2857 |
public Object clone() { |
10419
12c063b39232
7084245: Update usages of InternalError to use exception chaining
sherman
parents:
7003
diff
changeset
|
2858 |
DecimalFormat other = (DecimalFormat) super.clone(); |
12c063b39232
7084245: Update usages of InternalError to use exception chaining
sherman
parents:
7003
diff
changeset
|
2859 |
other.symbols = (DecimalFormatSymbols) symbols.clone(); |
12c063b39232
7084245: Update usages of InternalError to use exception chaining
sherman
parents:
7003
diff
changeset
|
2860 |
other.digitList = (DigitList) digitList.clone(); |
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2861 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2862 |
// Fast-path is almost stateless algorithm. The only logical state is the |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2863 |
// isFastPath flag. In addition fastPathCheckNeeded is a sentinel flag |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2864 |
// that forces recalculation of all fast-path fields when set to true. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2865 |
// |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2866 |
// There is thus no need to clone all the fast-path fields. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2867 |
// We just only need to set fastPathCheckNeeded to true when cloning, |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2868 |
// and init fastPathData to null as if it were a truly new instance. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2869 |
// Every fast-path field will be recalculated (only once) at next usage of |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2870 |
// fast-path algorithm. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2871 |
other.fastPathCheckNeeded = true; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2872 |
other.isFastPath = false; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2873 |
other.fastPathData = null; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2874 |
|
10419
12c063b39232
7084245: Update usages of InternalError to use exception chaining
sherman
parents:
7003
diff
changeset
|
2875 |
return other; |
2 | 2876 |
} |
2877 |
||
2878 |
/** |
|
2879 |
* Overrides equals |
|
2880 |
*/ |
|
13583 | 2881 |
@Override |
2 | 2882 |
public boolean equals(Object obj) |
2883 |
{ |
|
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2884 |
if (obj == null) |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2885 |
return false; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2886 |
if (!super.equals(obj)) |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
2887 |
return false; // super does class check |
2 | 2888 |
DecimalFormat other = (DecimalFormat) obj; |
2889 |
return ((posPrefixPattern == other.posPrefixPattern && |
|
2890 |
positivePrefix.equals(other.positivePrefix)) |
|
2891 |
|| (posPrefixPattern != null && |
|
2892 |
posPrefixPattern.equals(other.posPrefixPattern))) |
|
2893 |
&& ((posSuffixPattern == other.posSuffixPattern && |
|
2894 |
positiveSuffix.equals(other.positiveSuffix)) |
|
2895 |
|| (posSuffixPattern != null && |
|
2896 |
posSuffixPattern.equals(other.posSuffixPattern))) |
|
2897 |
&& ((negPrefixPattern == other.negPrefixPattern && |
|
2898 |
negativePrefix.equals(other.negativePrefix)) |
|
2899 |
|| (negPrefixPattern != null && |
|
2900 |
negPrefixPattern.equals(other.negPrefixPattern))) |
|
2901 |
&& ((negSuffixPattern == other.negSuffixPattern && |
|
2902 |
negativeSuffix.equals(other.negativeSuffix)) |
|
2903 |
|| (negSuffixPattern != null && |
|
2904 |
negSuffixPattern.equals(other.negSuffixPattern))) |
|
2905 |
&& multiplier == other.multiplier |
|
2906 |
&& groupingSize == other.groupingSize |
|
2907 |
&& decimalSeparatorAlwaysShown == other.decimalSeparatorAlwaysShown |
|
2908 |
&& parseBigDecimal == other.parseBigDecimal |
|
2909 |
&& useExponentialNotation == other.useExponentialNotation |
|
2910 |
&& (!useExponentialNotation || |
|
2911 |
minExponentDigits == other.minExponentDigits) |
|
2912 |
&& maximumIntegerDigits == other.maximumIntegerDigits |
|
2913 |
&& minimumIntegerDigits == other.minimumIntegerDigits |
|
2914 |
&& maximumFractionDigits == other.maximumFractionDigits |
|
2915 |
&& minimumFractionDigits == other.minimumFractionDigits |
|
2916 |
&& roundingMode == other.roundingMode |
|
2917 |
&& symbols.equals(other.symbols); |
|
2918 |
} |
|
2919 |
||
2920 |
/** |
|
2921 |
* Overrides hashCode |
|
2922 |
*/ |
|
13583 | 2923 |
@Override |
2 | 2924 |
public int hashCode() { |
2925 |
return super.hashCode() * 37 + positivePrefix.hashCode(); |
|
2926 |
// just enough fields for a reasonable distribution |
|
2927 |
} |
|
2928 |
||
2929 |
/** |
|
2930 |
* Synthesizes a pattern string that represents the current state |
|
2931 |
* of this Format object. |
|
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2932 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2933 |
* @return a pattern string |
2 | 2934 |
* @see #applyPattern |
2935 |
*/ |
|
2936 |
public String toPattern() { |
|
2937 |
return toPattern( false ); |
|
2938 |
} |
|
2939 |
||
2940 |
/** |
|
2941 |
* Synthesizes a localized pattern string that represents the current |
|
2942 |
* state of this Format object. |
|
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2943 |
* |
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
2944 |
* @return a localized pattern string |
2 | 2945 |
* @see #applyPattern |
2946 |
*/ |
|
2947 |
public String toLocalizedPattern() { |
|
2948 |
return toPattern( true ); |
|
2949 |
} |
|
2950 |
||
2951 |
/** |
|
2952 |
* Expand the affix pattern strings into the expanded affix strings. If any |
|
2953 |
* affix pattern string is null, do not expand it. This method should be |
|
2954 |
* called any time the symbols or the affix patterns change in order to keep |
|
2955 |
* the expanded affix strings up to date. |
|
2956 |
*/ |
|
2957 |
private void expandAffixes() { |
|
2958 |
// Reuse one StringBuffer for better performance |
|
2959 |
StringBuffer buffer = new StringBuffer(); |
|
2960 |
if (posPrefixPattern != null) { |
|
2961 |
positivePrefix = expandAffix(posPrefixPattern, buffer); |
|
2962 |
positivePrefixFieldPositions = null; |
|
2963 |
} |
|
2964 |
if (posSuffixPattern != null) { |
|
2965 |
positiveSuffix = expandAffix(posSuffixPattern, buffer); |
|
2966 |
positiveSuffixFieldPositions = null; |
|
2967 |
} |
|
2968 |
if (negPrefixPattern != null) { |
|
2969 |
negativePrefix = expandAffix(negPrefixPattern, buffer); |
|
2970 |
negativePrefixFieldPositions = null; |
|
2971 |
} |
|
2972 |
if (negSuffixPattern != null) { |
|
2973 |
negativeSuffix = expandAffix(negSuffixPattern, buffer); |
|
2974 |
negativeSuffixFieldPositions = null; |
|
2975 |
} |
|
2976 |
} |
|
2977 |
||
2978 |
/** |
|
2979 |
* Expand an affix pattern into an affix string. All characters in the |
|
2980 |
* pattern are literal unless prefixed by QUOTE. The following characters |
|
2981 |
* after QUOTE are recognized: PATTERN_PERCENT, PATTERN_PER_MILLE, |
|
2982 |
* PATTERN_MINUS, and CURRENCY_SIGN. If CURRENCY_SIGN is doubled (QUOTE + |
|
2983 |
* CURRENCY_SIGN + CURRENCY_SIGN), it is interpreted as an ISO 4217 |
|
2984 |
* currency code. Any other character after a QUOTE represents itself. |
|
2985 |
* QUOTE must be followed by another character; QUOTE may not occur by |
|
2986 |
* itself at the end of the pattern. |
|
2987 |
* |
|
2988 |
* @param pattern the non-null, possibly empty pattern |
|
2989 |
* @param buffer a scratch StringBuffer; its contents will be lost |
|
2990 |
* @return the expanded equivalent of pattern |
|
2991 |
*/ |
|
2992 |
private String expandAffix(String pattern, StringBuffer buffer) { |
|
2993 |
buffer.setLength(0); |
|
2994 |
for (int i=0; i<pattern.length(); ) { |
|
2995 |
char c = pattern.charAt(i++); |
|
2996 |
if (c == QUOTE) { |
|
2997 |
c = pattern.charAt(i++); |
|
2998 |
switch (c) { |
|
2999 |
case CURRENCY_SIGN: |
|
3000 |
if (i<pattern.length() && |
|
3001 |
pattern.charAt(i) == CURRENCY_SIGN) { |
|
3002 |
++i; |
|
3003 |
buffer.append(symbols.getInternationalCurrencySymbol()); |
|
3004 |
} else { |
|
3005 |
buffer.append(symbols.getCurrencySymbol()); |
|
3006 |
} |
|
3007 |
continue; |
|
3008 |
case PATTERN_PERCENT: |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3009 |
buffer.append(symbols.getPercentText()); |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3010 |
continue; |
2 | 3011 |
case PATTERN_PER_MILLE: |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3012 |
buffer.append(symbols.getPerMillText()); |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3013 |
continue; |
2 | 3014 |
case PATTERN_MINUS: |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3015 |
buffer.append(symbols.getMinusSignText()); |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3016 |
continue; |
2 | 3017 |
} |
3018 |
} |
|
3019 |
buffer.append(c); |
|
3020 |
} |
|
3021 |
return buffer.toString(); |
|
3022 |
} |
|
3023 |
||
3024 |
/** |
|
3025 |
* Expand an affix pattern into an array of FieldPositions describing |
|
3026 |
* how the pattern would be expanded. |
|
3027 |
* All characters in the |
|
3028 |
* pattern are literal unless prefixed by QUOTE. The following characters |
|
3029 |
* after QUOTE are recognized: PATTERN_PERCENT, PATTERN_PER_MILLE, |
|
3030 |
* PATTERN_MINUS, and CURRENCY_SIGN. If CURRENCY_SIGN is doubled (QUOTE + |
|
3031 |
* CURRENCY_SIGN + CURRENCY_SIGN), it is interpreted as an ISO 4217 |
|
3032 |
* currency code. Any other character after a QUOTE represents itself. |
|
3033 |
* QUOTE must be followed by another character; QUOTE may not occur by |
|
3034 |
* itself at the end of the pattern. |
|
3035 |
* |
|
3036 |
* @param pattern the non-null, possibly empty pattern |
|
3037 |
* @return FieldPosition array of the resulting fields. |
|
3038 |
*/ |
|
3039 |
private FieldPosition[] expandAffix(String pattern) { |
|
12848 | 3040 |
ArrayList<FieldPosition> positions = null; |
2 | 3041 |
int stringIndex = 0; |
3042 |
for (int i=0; i<pattern.length(); ) { |
|
3043 |
char c = pattern.charAt(i++); |
|
3044 |
if (c == QUOTE) { |
|
3045 |
Format.Field fieldID = null; |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3046 |
String string = null; |
2 | 3047 |
c = pattern.charAt(i++); |
3048 |
switch (c) { |
|
3049 |
case CURRENCY_SIGN: |
|
3050 |
if (i<pattern.length() && |
|
3051 |
pattern.charAt(i) == CURRENCY_SIGN) { |
|
3052 |
++i; |
|
3053 |
string = symbols.getInternationalCurrencySymbol(); |
|
3054 |
} else { |
|
3055 |
string = symbols.getCurrencySymbol(); |
|
3056 |
} |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3057 |
fieldID = Field.CURRENCY; |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3058 |
break; |
2 | 3059 |
case PATTERN_PERCENT: |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3060 |
string = symbols.getPercentText(); |
2 | 3061 |
fieldID = Field.PERCENT; |
3062 |
break; |
|
3063 |
case PATTERN_PER_MILLE: |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3064 |
string = symbols.getPerMillText(); |
2 | 3065 |
fieldID = Field.PERMILLE; |
3066 |
break; |
|
3067 |
case PATTERN_MINUS: |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3068 |
string = symbols.getMinusSignText(); |
2 | 3069 |
fieldID = Field.SIGN; |
3070 |
break; |
|
3071 |
} |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3072 |
|
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3073 |
if (fieldID != null && !string.isEmpty()) { |
2 | 3074 |
if (positions == null) { |
12848 | 3075 |
positions = new ArrayList<>(2); |
2 | 3076 |
} |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3077 |
FieldPosition fp = new FieldPosition(fieldID); |
2 | 3078 |
fp.setBeginIndex(stringIndex); |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3079 |
fp.setEndIndex(stringIndex + string.length()); |
2 | 3080 |
positions.add(fp); |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3081 |
stringIndex += string.length(); |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3082 |
continue; |
2 | 3083 |
} |
3084 |
} |
|
3085 |
stringIndex++; |
|
3086 |
} |
|
3087 |
if (positions != null) { |
|
12848 | 3088 |
return positions.toArray(EmptyFieldPositionArray); |
2 | 3089 |
} |
3090 |
return EmptyFieldPositionArray; |
|
3091 |
} |
|
3092 |
||
3093 |
/** |
|
3094 |
* Appends an affix pattern to the given StringBuffer, quoting special |
|
3095 |
* characters as needed. Uses the internal affix pattern, if that exists, |
|
3096 |
* or the literal affix, if the internal affix pattern is null. The |
|
3097 |
* appended string will generate the same affix pattern (or literal affix) |
|
3098 |
* when passed to toPattern(). |
|
3099 |
* |
|
3100 |
* @param buffer the affix string is appended to this |
|
3101 |
* @param affixPattern a pattern such as posPrefixPattern; may be null |
|
3102 |
* @param expAffix a corresponding expanded affix, such as positivePrefix. |
|
3103 |
* Ignored unless affixPattern is null. If affixPattern is null, then |
|
3104 |
* expAffix is appended as a literal affix. |
|
3105 |
* @param localized true if the appended pattern should contain localized |
|
3106 |
* pattern characters; otherwise, non-localized pattern chars are appended |
|
3107 |
*/ |
|
3108 |
private void appendAffix(StringBuffer buffer, String affixPattern, |
|
3109 |
String expAffix, boolean localized) { |
|
3110 |
if (affixPattern == null) { |
|
3111 |
appendAffix(buffer, expAffix, localized); |
|
3112 |
} else { |
|
3113 |
int i; |
|
3114 |
for (int pos=0; pos<affixPattern.length(); pos=i) { |
|
3115 |
i = affixPattern.indexOf(QUOTE, pos); |
|
3116 |
if (i < 0) { |
|
3117 |
appendAffix(buffer, affixPattern.substring(pos), localized); |
|
3118 |
break; |
|
3119 |
} |
|
3120 |
if (i > pos) { |
|
3121 |
appendAffix(buffer, affixPattern.substring(pos, i), localized); |
|
3122 |
} |
|
3123 |
char c = affixPattern.charAt(++i); |
|
3124 |
++i; |
|
3125 |
if (c == QUOTE) { |
|
3126 |
buffer.append(c); |
|
3127 |
// Fall through and append another QUOTE below |
|
3128 |
} else if (c == CURRENCY_SIGN && |
|
3129 |
i<affixPattern.length() && |
|
3130 |
affixPattern.charAt(i) == CURRENCY_SIGN) { |
|
3131 |
++i; |
|
3132 |
buffer.append(c); |
|
3133 |
// Fall through and append another CURRENCY_SIGN below |
|
3134 |
} else if (localized) { |
|
3135 |
switch (c) { |
|
3136 |
case PATTERN_PERCENT: |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3137 |
buffer.append(symbols.getPercentText()); |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3138 |
continue; |
2 | 3139 |
case PATTERN_PER_MILLE: |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3140 |
buffer.append(symbols.getPerMillText()); |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3141 |
continue; |
2 | 3142 |
case PATTERN_MINUS: |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3143 |
buffer.append(symbols.getMinusSignText()); |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3144 |
continue; |
2 | 3145 |
} |
3146 |
} |
|
3147 |
buffer.append(c); |
|
3148 |
} |
|
3149 |
} |
|
3150 |
} |
|
3151 |
||
3152 |
/** |
|
3153 |
* Append an affix to the given StringBuffer, using quotes if |
|
3154 |
* there are special characters. Single quotes themselves must be |
|
3155 |
* escaped in either case. |
|
3156 |
*/ |
|
3157 |
private void appendAffix(StringBuffer buffer, String affix, boolean localized) { |
|
3158 |
boolean needQuote; |
|
3159 |
if (localized) { |
|
3160 |
needQuote = affix.indexOf(symbols.getZeroDigit()) >= 0 |
|
3161 |
|| affix.indexOf(symbols.getGroupingSeparator()) >= 0 |
|
3162 |
|| affix.indexOf(symbols.getDecimalSeparator()) >= 0 |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3163 |
|| affix.indexOf(symbols.getPercentText()) >= 0 |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3164 |
|| affix.indexOf(symbols.getPerMillText()) >= 0 |
2 | 3165 |
|| affix.indexOf(symbols.getDigit()) >= 0 |
3166 |
|| affix.indexOf(symbols.getPatternSeparator()) >= 0 |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3167 |
|| affix.indexOf(symbols.getMinusSignText()) >= 0 |
2 | 3168 |
|| affix.indexOf(CURRENCY_SIGN) >= 0; |
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
3169 |
} else { |
2 | 3170 |
needQuote = affix.indexOf(PATTERN_ZERO_DIGIT) >= 0 |
3171 |
|| affix.indexOf(PATTERN_GROUPING_SEPARATOR) >= 0 |
|
3172 |
|| affix.indexOf(PATTERN_DECIMAL_SEPARATOR) >= 0 |
|
3173 |
|| affix.indexOf(PATTERN_PERCENT) >= 0 |
|
3174 |
|| affix.indexOf(PATTERN_PER_MILLE) >= 0 |
|
3175 |
|| affix.indexOf(PATTERN_DIGIT) >= 0 |
|
3176 |
|| affix.indexOf(PATTERN_SEPARATOR) >= 0 |
|
3177 |
|| affix.indexOf(PATTERN_MINUS) >= 0 |
|
3178 |
|| affix.indexOf(CURRENCY_SIGN) >= 0; |
|
3179 |
} |
|
3180 |
if (needQuote) buffer.append('\''); |
|
3181 |
if (affix.indexOf('\'') < 0) buffer.append(affix); |
|
3182 |
else { |
|
3183 |
for (int j=0; j<affix.length(); ++j) { |
|
3184 |
char c = affix.charAt(j); |
|
3185 |
buffer.append(c); |
|
3186 |
if (c == '\'') buffer.append(c); |
|
3187 |
} |
|
3188 |
} |
|
3189 |
if (needQuote) buffer.append('\''); |
|
3190 |
} |
|
3191 |
||
3192 |
/** |
|
3193 |
* Does the real work of generating a pattern. */ |
|
3194 |
private String toPattern(boolean localized) { |
|
3195 |
StringBuffer result = new StringBuffer(); |
|
3196 |
for (int j = 1; j >= 0; --j) { |
|
3197 |
if (j == 1) |
|
3198 |
appendAffix(result, posPrefixPattern, positivePrefix, localized); |
|
3199 |
else appendAffix(result, negPrefixPattern, negativePrefix, localized); |
|
3200 |
int i; |
|
3201 |
int digitCount = useExponentialNotation |
|
3202 |
? getMaximumIntegerDigits() |
|
3203 |
: Math.max(groupingSize, getMinimumIntegerDigits())+1; |
|
3204 |
for (i = digitCount; i > 0; --i) { |
|
3205 |
if (i != digitCount && isGroupingUsed() && groupingSize != 0 && |
|
3206 |
i % groupingSize == 0) { |
|
3207 |
result.append(localized ? symbols.getGroupingSeparator() : |
|
3208 |
PATTERN_GROUPING_SEPARATOR); |
|
3209 |
} |
|
3210 |
result.append(i <= getMinimumIntegerDigits() |
|
3211 |
? (localized ? symbols.getZeroDigit() : PATTERN_ZERO_DIGIT) |
|
3212 |
: (localized ? symbols.getDigit() : PATTERN_DIGIT)); |
|
3213 |
} |
|
3214 |
if (getMaximumFractionDigits() > 0 || decimalSeparatorAlwaysShown) |
|
3215 |
result.append(localized ? symbols.getDecimalSeparator() : |
|
3216 |
PATTERN_DECIMAL_SEPARATOR); |
|
3217 |
for (i = 0; i < getMaximumFractionDigits(); ++i) { |
|
3218 |
if (i < getMinimumFractionDigits()) { |
|
3219 |
result.append(localized ? symbols.getZeroDigit() : |
|
3220 |
PATTERN_ZERO_DIGIT); |
|
3221 |
} else { |
|
3222 |
result.append(localized ? symbols.getDigit() : |
|
3223 |
PATTERN_DIGIT); |
|
3224 |
} |
|
3225 |
} |
|
3226 |
if (useExponentialNotation) |
|
3227 |
{ |
|
3228 |
result.append(localized ? symbols.getExponentSeparator() : |
|
3229 |
PATTERN_EXPONENT); |
|
3230 |
for (i=0; i<minExponentDigits; ++i) |
|
3231 |
result.append(localized ? symbols.getZeroDigit() : |
|
3232 |
PATTERN_ZERO_DIGIT); |
|
3233 |
} |
|
3234 |
if (j == 1) { |
|
3235 |
appendAffix(result, posSuffixPattern, positiveSuffix, localized); |
|
3236 |
if ((negSuffixPattern == posSuffixPattern && // n == p == null |
|
3237 |
negativeSuffix.equals(positiveSuffix)) |
|
3238 |
|| (negSuffixPattern != null && |
|
3239 |
negSuffixPattern.equals(posSuffixPattern))) { |
|
3240 |
if ((negPrefixPattern != null && posPrefixPattern != null && |
|
3241 |
negPrefixPattern.equals("'-" + posPrefixPattern)) || |
|
3242 |
(negPrefixPattern == posPrefixPattern && // n == p == null |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3243 |
negativePrefix.equals(symbols.getMinusSignText() + positivePrefix))) |
2 | 3244 |
break; |
3245 |
} |
|
3246 |
result.append(localized ? symbols.getPatternSeparator() : |
|
3247 |
PATTERN_SEPARATOR); |
|
3248 |
} else appendAffix(result, negSuffixPattern, negativeSuffix, localized); |
|
3249 |
} |
|
3250 |
return result.toString(); |
|
3251 |
} |
|
3252 |
||
3253 |
/** |
|
3254 |
* Apply the given pattern to this Format object. A pattern is a |
|
3255 |
* short-hand specification for the various formatting properties. |
|
3256 |
* These properties can also be changed individually through the |
|
3257 |
* various setter methods. |
|
3258 |
* <p> |
|
3259 |
* There is no limit to integer digits set |
|
3260 |
* by this routine, since that is the typical end-user desire; |
|
3261 |
* use setMaximumInteger if you want to set a real value. |
|
3262 |
* For negative numbers, use a second pattern, separated by a semicolon |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3263 |
* <P>Example {@code "#,#00.0#"} → 1,234.56 |
2 | 3264 |
* <P>This means a minimum of 2 integer digits, 1 fraction digit, and |
3265 |
* a maximum of 2 fraction digits. |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3266 |
* <p>Example: {@code "#,#00.0#;(#,#00.0#)"} for negatives in |
2 | 3267 |
* parentheses. |
3268 |
* <p>In negative patterns, the minimum and maximum counts are ignored; |
|
3269 |
* these are presumed to be set in the positive pattern. |
|
3270 |
* |
|
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
3271 |
* @param pattern a new pattern |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
3272 |
* @throws NullPointerException if {@code pattern} is null |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
3273 |
* @throws IllegalArgumentException if the given pattern is invalid. |
2 | 3274 |
*/ |
3275 |
public void applyPattern(String pattern) { |
|
3276 |
applyPattern(pattern, false); |
|
3277 |
} |
|
3278 |
||
3279 |
/** |
|
3280 |
* Apply the given pattern to this Format object. The pattern |
|
3281 |
* is assumed to be in a localized notation. A pattern is a |
|
3282 |
* short-hand specification for the various formatting properties. |
|
3283 |
* These properties can also be changed individually through the |
|
3284 |
* various setter methods. |
|
3285 |
* <p> |
|
3286 |
* There is no limit to integer digits set |
|
3287 |
* by this routine, since that is the typical end-user desire; |
|
3288 |
* use setMaximumInteger if you want to set a real value. |
|
3289 |
* For negative numbers, use a second pattern, separated by a semicolon |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3290 |
* <P>Example {@code "#,#00.0#"} → 1,234.56 |
2 | 3291 |
* <P>This means a minimum of 2 integer digits, 1 fraction digit, and |
3292 |
* a maximum of 2 fraction digits. |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3293 |
* <p>Example: {@code "#,#00.0#;(#,#00.0#)"} for negatives in |
2 | 3294 |
* parentheses. |
3295 |
* <p>In negative patterns, the minimum and maximum counts are ignored; |
|
3296 |
* these are presumed to be set in the positive pattern. |
|
3297 |
* |
|
19054
a64012cb49d6
8021108: Clean up doclint warnings and errors in java.text package
peytoia
parents:
16010
diff
changeset
|
3298 |
* @param pattern a new pattern |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
3299 |
* @throws NullPointerException if {@code pattern} is null |
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
3300 |
* @throws IllegalArgumentException if the given pattern is invalid. |
2 | 3301 |
*/ |
3302 |
public void applyLocalizedPattern(String pattern) { |
|
3303 |
applyPattern(pattern, true); |
|
3304 |
} |
|
3305 |
||
3306 |
/** |
|
3307 |
* Does the real work of applying a pattern. |
|
3308 |
*/ |
|
3309 |
private void applyPattern(String pattern, boolean localized) { |
|
3310 |
char zeroDigit = PATTERN_ZERO_DIGIT; |
|
3311 |
char groupingSeparator = PATTERN_GROUPING_SEPARATOR; |
|
3312 |
char decimalSeparator = PATTERN_DECIMAL_SEPARATOR; |
|
3313 |
char percent = PATTERN_PERCENT; |
|
3314 |
char perMill = PATTERN_PER_MILLE; |
|
3315 |
char digit = PATTERN_DIGIT; |
|
3316 |
char separator = PATTERN_SEPARATOR; |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3317 |
String exponent = PATTERN_EXPONENT; |
2 | 3318 |
char minus = PATTERN_MINUS; |
3319 |
if (localized) { |
|
3320 |
zeroDigit = symbols.getZeroDigit(); |
|
3321 |
groupingSeparator = symbols.getGroupingSeparator(); |
|
3322 |
decimalSeparator = symbols.getDecimalSeparator(); |
|
3323 |
percent = symbols.getPercent(); |
|
3324 |
perMill = symbols.getPerMill(); |
|
3325 |
digit = symbols.getDigit(); |
|
3326 |
separator = symbols.getPatternSeparator(); |
|
3327 |
exponent = symbols.getExponentSeparator(); |
|
3328 |
minus = symbols.getMinusSign(); |
|
3329 |
} |
|
3330 |
boolean gotNegative = false; |
|
3331 |
decimalSeparatorAlwaysShown = false; |
|
3332 |
isCurrencyFormat = false; |
|
3333 |
useExponentialNotation = false; |
|
3334 |
||
3335 |
int start = 0; |
|
3336 |
for (int j = 1; j >= 0 && start < pattern.length(); --j) { |
|
3337 |
boolean inQuote = false; |
|
3338 |
StringBuffer prefix = new StringBuffer(); |
|
3339 |
StringBuffer suffix = new StringBuffer(); |
|
3340 |
int decimalPos = -1; |
|
3341 |
int multiplier = 1; |
|
3342 |
int digitLeftCount = 0, zeroDigitCount = 0, digitRightCount = 0; |
|
3343 |
byte groupingCount = -1; |
|
3344 |
||
3345 |
// The phase ranges from 0 to 2. Phase 0 is the prefix. Phase 1 is |
|
3346 |
// the section of the pattern with digits, decimal separator, |
|
3347 |
// grouping characters. Phase 2 is the suffix. In phases 0 and 2, |
|
3348 |
// percent, per mille, and currency symbols are recognized and |
|
3349 |
// translated. The separation of the characters into phases is |
|
3350 |
// strictly enforced; if phase 1 characters are to appear in the |
|
3351 |
// suffix, for example, they must be quoted. |
|
3352 |
int phase = 0; |
|
3353 |
||
3354 |
// The affix is either the prefix or the suffix. |
|
3355 |
StringBuffer affix = prefix; |
|
3356 |
||
3357 |
for (int pos = start; pos < pattern.length(); ++pos) { |
|
3358 |
char ch = pattern.charAt(pos); |
|
3359 |
switch (phase) { |
|
3360 |
case 0: |
|
3361 |
case 2: |
|
3362 |
// Process the prefix / suffix characters |
|
3363 |
if (inQuote) { |
|
3364 |
// A quote within quotes indicates either the closing |
|
3365 |
// quote or two quotes, which is a quote literal. That |
|
3366 |
// is, we have the second quote in 'do' or 'don''t'. |
|
3367 |
if (ch == QUOTE) { |
|
3368 |
if ((pos+1) < pattern.length() && |
|
3369 |
pattern.charAt(pos+1) == QUOTE) { |
|
3370 |
++pos; |
|
3371 |
affix.append("''"); // 'don''t' |
|
3372 |
} else { |
|
3373 |
inQuote = false; // 'do' |
|
3374 |
} |
|
3375 |
continue; |
|
3376 |
} |
|
3377 |
} else { |
|
3378 |
// Process unquoted characters seen in prefix or suffix |
|
3379 |
// phase. |
|
3380 |
if (ch == digit || |
|
3381 |
ch == zeroDigit || |
|
3382 |
ch == groupingSeparator || |
|
3383 |
ch == decimalSeparator) { |
|
3384 |
phase = 1; |
|
3385 |
--pos; // Reprocess this character |
|
3386 |
continue; |
|
3387 |
} else if (ch == CURRENCY_SIGN) { |
|
3388 |
// Use lookahead to determine if the currency sign |
|
3389 |
// is doubled or not. |
|
3390 |
boolean doubled = (pos + 1) < pattern.length() && |
|
3391 |
pattern.charAt(pos + 1) == CURRENCY_SIGN; |
|
3392 |
if (doubled) { // Skip over the doubled character |
|
3393 |
++pos; |
|
3394 |
} |
|
3395 |
isCurrencyFormat = true; |
|
3396 |
affix.append(doubled ? "'\u00A4\u00A4" : "'\u00A4"); |
|
3397 |
continue; |
|
3398 |
} else if (ch == QUOTE) { |
|
3399 |
// A quote outside quotes indicates either the |
|
3400 |
// opening quote or two quotes, which is a quote |
|
3401 |
// literal. That is, we have the first quote in 'do' |
|
3402 |
// or o''clock. |
|
3403 |
if (ch == QUOTE) { |
|
3404 |
if ((pos+1) < pattern.length() && |
|
3405 |
pattern.charAt(pos+1) == QUOTE) { |
|
3406 |
++pos; |
|
3407 |
affix.append("''"); // o''clock |
|
3408 |
} else { |
|
3409 |
inQuote = true; // 'do' |
|
3410 |
} |
|
3411 |
continue; |
|
3412 |
} |
|
3413 |
} else if (ch == separator) { |
|
3414 |
// Don't allow separators before we see digit |
|
3415 |
// characters of phase 1, and don't allow separators |
|
3416 |
// in the second pattern (j == 0). |
|
3417 |
if (phase == 0 || j == 0) { |
|
3418 |
throw new IllegalArgumentException("Unquoted special character '" + |
|
3419 |
ch + "' in pattern \"" + pattern + '"'); |
|
3420 |
} |
|
3421 |
start = pos + 1; |
|
3422 |
pos = pattern.length(); |
|
3423 |
continue; |
|
3424 |
} |
|
3425 |
||
3426 |
// Next handle characters which are appended directly. |
|
3427 |
else if (ch == percent) { |
|
3428 |
if (multiplier != 1) { |
|
3429 |
throw new IllegalArgumentException("Too many percent/per mille characters in pattern \"" + |
|
3430 |
pattern + '"'); |
|
3431 |
} |
|
3432 |
multiplier = 100; |
|
3433 |
affix.append("'%"); |
|
3434 |
continue; |
|
3435 |
} else if (ch == perMill) { |
|
3436 |
if (multiplier != 1) { |
|
3437 |
throw new IllegalArgumentException("Too many percent/per mille characters in pattern \"" + |
|
3438 |
pattern + '"'); |
|
3439 |
} |
|
3440 |
multiplier = 1000; |
|
3441 |
affix.append("'\u2030"); |
|
3442 |
continue; |
|
3443 |
} else if (ch == minus) { |
|
3444 |
affix.append("'-"); |
|
3445 |
continue; |
|
3446 |
} |
|
3447 |
} |
|
3448 |
// Note that if we are within quotes, or if this is an |
|
3449 |
// unquoted, non-special character, then we usually fall |
|
3450 |
// through to here. |
|
3451 |
affix.append(ch); |
|
3452 |
break; |
|
3453 |
||
3454 |
case 1: |
|
45182 | 3455 |
// The negative subpattern (j = 0) serves only to specify the |
3456 |
// negative prefix and suffix, so all the phase 1 characters |
|
3457 |
// e.g. digits, zeroDigit, groupingSeparator, |
|
3458 |
// decimalSeparator, exponent are ignored |
|
3459 |
if (j == 0) { |
|
3460 |
while (pos < pattern.length()) { |
|
3461 |
char negPatternChar = pattern.charAt(pos); |
|
3462 |
if (negPatternChar == digit |
|
3463 |
|| negPatternChar == zeroDigit |
|
3464 |
|| negPatternChar == groupingSeparator |
|
3465 |
|| negPatternChar == decimalSeparator) { |
|
3466 |
++pos; |
|
3467 |
} else if (pattern.regionMatches(pos, exponent, |
|
3468 |
0, exponent.length())) { |
|
3469 |
pos = pos + exponent.length(); |
|
3470 |
} else { |
|
3471 |
// Not a phase 1 character, consider it as |
|
3472 |
// suffix and parse it in phase 2 |
|
3473 |
--pos; //process it again in outer loop |
|
3474 |
phase = 2; |
|
3475 |
affix = suffix; |
|
3476 |
break; |
|
3477 |
} |
|
2 | 3478 |
} |
3479 |
continue; |
|
3480 |
} |
|
3481 |
||
3482 |
// Process the digits, decimal, and grouping characters. We |
|
3483 |
// record five pieces of information. We expect the digits |
|
3484 |
// to occur in the pattern ####0000.####, and we record the |
|
3485 |
// number of left digits, zero (central) digits, and right |
|
3486 |
// digits. The position of the last grouping character is |
|
3487 |
// recorded (should be somewhere within the first two blocks |
|
3488 |
// of characters), as is the position of the decimal point, |
|
3489 |
// if any (should be in the zero digits). If there is no |
|
3490 |
// decimal point, then there should be no right digits. |
|
3491 |
if (ch == digit) { |
|
3492 |
if (zeroDigitCount > 0) { |
|
3493 |
++digitRightCount; |
|
3494 |
} else { |
|
3495 |
++digitLeftCount; |
|
3496 |
} |
|
3497 |
if (groupingCount >= 0 && decimalPos < 0) { |
|
3498 |
++groupingCount; |
|
3499 |
} |
|
3500 |
} else if (ch == zeroDigit) { |
|
3501 |
if (digitRightCount > 0) { |
|
3502 |
throw new IllegalArgumentException("Unexpected '0' in pattern \"" + |
|
3503 |
pattern + '"'); |
|
3504 |
} |
|
3505 |
++zeroDigitCount; |
|
3506 |
if (groupingCount >= 0 && decimalPos < 0) { |
|
3507 |
++groupingCount; |
|
3508 |
} |
|
3509 |
} else if (ch == groupingSeparator) { |
|
3510 |
groupingCount = 0; |
|
3511 |
} else if (ch == decimalSeparator) { |
|
3512 |
if (decimalPos >= 0) { |
|
3513 |
throw new IllegalArgumentException("Multiple decimal separators in pattern \"" + |
|
3514 |
pattern + '"'); |
|
3515 |
} |
|
3516 |
decimalPos = digitLeftCount + zeroDigitCount + digitRightCount; |
|
3517 |
} else if (pattern.regionMatches(pos, exponent, 0, exponent.length())){ |
|
3518 |
if (useExponentialNotation) { |
|
3519 |
throw new IllegalArgumentException("Multiple exponential " + |
|
3520 |
"symbols in pattern \"" + pattern + '"'); |
|
3521 |
} |
|
3522 |
useExponentialNotation = true; |
|
3523 |
minExponentDigits = 0; |
|
3524 |
||
3525 |
// Use lookahead to parse out the exponential part |
|
3526 |
// of the pattern, then jump into phase 2. |
|
3527 |
pos = pos+exponent.length(); |
|
3528 |
while (pos < pattern.length() && |
|
3529 |
pattern.charAt(pos) == zeroDigit) { |
|
3530 |
++minExponentDigits; |
|
3531 |
++pos; |
|
3532 |
} |
|
3533 |
||
3534 |
if ((digitLeftCount + zeroDigitCount) < 1 || |
|
3535 |
minExponentDigits < 1) { |
|
3536 |
throw new IllegalArgumentException("Malformed exponential " + |
|
3537 |
"pattern \"" + pattern + '"'); |
|
3538 |
} |
|
3539 |
||
3540 |
// Transition to phase 2 |
|
3541 |
phase = 2; |
|
3542 |
affix = suffix; |
|
3543 |
--pos; |
|
3544 |
continue; |
|
3545 |
} else { |
|
3546 |
phase = 2; |
|
3547 |
affix = suffix; |
|
3548 |
--pos; |
|
3549 |
continue; |
|
3550 |
} |
|
3551 |
break; |
|
3552 |
} |
|
3553 |
} |
|
3554 |
||
3555 |
// Handle patterns with no '0' pattern character. These patterns |
|
3556 |
// are legal, but must be interpreted. "##.###" -> "#0.###". |
|
3557 |
// ".###" -> ".0##". |
|
3558 |
/* We allow patterns of the form "####" to produce a zeroDigitCount |
|
3559 |
* of zero (got that?); although this seems like it might make it |
|
3560 |
* possible for format() to produce empty strings, format() checks |
|
3561 |
* for this condition and outputs a zero digit in this situation. |
|
3562 |
* Having a zeroDigitCount of zero yields a minimum integer digits |
|
3563 |
* of zero, which allows proper round-trip patterns. That is, we |
|
3564 |
* don't want "#" to become "#0" when toPattern() is called (even |
|
3565 |
* though that's what it really is, semantically). |
|
3566 |
*/ |
|
3567 |
if (zeroDigitCount == 0 && digitLeftCount > 0 && decimalPos >= 0) { |
|
3568 |
// Handle "###.###" and "###." and ".###" |
|
3569 |
int n = decimalPos; |
|
3570 |
if (n == 0) { // Handle ".###" |
|
3571 |
++n; |
|
3572 |
} |
|
3573 |
digitRightCount = digitLeftCount - n; |
|
3574 |
digitLeftCount = n - 1; |
|
3575 |
zeroDigitCount = 1; |
|
3576 |
} |
|
3577 |
||
3578 |
// Do syntax checking on the digits. |
|
3579 |
if ((decimalPos < 0 && digitRightCount > 0) || |
|
3580 |
(decimalPos >= 0 && (decimalPos < digitLeftCount || |
|
3581 |
decimalPos > (digitLeftCount + zeroDigitCount))) || |
|
3582 |
groupingCount == 0 || inQuote) { |
|
3583 |
throw new IllegalArgumentException("Malformed pattern \"" + |
|
3584 |
pattern + '"'); |
|
3585 |
} |
|
3586 |
||
3587 |
if (j == 1) { |
|
3588 |
posPrefixPattern = prefix.toString(); |
|
3589 |
posSuffixPattern = suffix.toString(); |
|
3590 |
negPrefixPattern = posPrefixPattern; // assume these for now |
|
3591 |
negSuffixPattern = posSuffixPattern; |
|
3592 |
int digitTotalCount = digitLeftCount + zeroDigitCount + digitRightCount; |
|
3593 |
/* The effectiveDecimalPos is the position the decimal is at or |
|
3594 |
* would be at if there is no decimal. Note that if decimalPos<0, |
|
3595 |
* then digitTotalCount == digitLeftCount + zeroDigitCount. |
|
3596 |
*/ |
|
3597 |
int effectiveDecimalPos = decimalPos >= 0 ? |
|
3598 |
decimalPos : digitTotalCount; |
|
3599 |
setMinimumIntegerDigits(effectiveDecimalPos - digitLeftCount); |
|
3600 |
setMaximumIntegerDigits(useExponentialNotation ? |
|
3601 |
digitLeftCount + getMinimumIntegerDigits() : |
|
3602 |
MAXIMUM_INTEGER_DIGITS); |
|
3603 |
setMaximumFractionDigits(decimalPos >= 0 ? |
|
3604 |
(digitTotalCount - decimalPos) : 0); |
|
3605 |
setMinimumFractionDigits(decimalPos >= 0 ? |
|
3606 |
(digitLeftCount + zeroDigitCount - decimalPos) : 0); |
|
3607 |
setGroupingUsed(groupingCount > 0); |
|
3608 |
this.groupingSize = (groupingCount > 0) ? groupingCount : 0; |
|
3609 |
this.multiplier = multiplier; |
|
3610 |
setDecimalSeparatorAlwaysShown(decimalPos == 0 || |
|
3611 |
decimalPos == digitTotalCount); |
|
3612 |
} else { |
|
3613 |
negPrefixPattern = prefix.toString(); |
|
3614 |
negSuffixPattern = suffix.toString(); |
|
3615 |
gotNegative = true; |
|
3616 |
} |
|
3617 |
} |
|
3618 |
||
53018
8bf9268df0e2
8215281: Use String.isEmpty() when applicable in java.base
redestad
parents:
52869
diff
changeset
|
3619 |
if (pattern.isEmpty()) { |
2 | 3620 |
posPrefixPattern = posSuffixPattern = ""; |
3621 |
setMinimumIntegerDigits(0); |
|
3622 |
setMaximumIntegerDigits(MAXIMUM_INTEGER_DIGITS); |
|
3623 |
setMinimumFractionDigits(0); |
|
3624 |
setMaximumFractionDigits(MAXIMUM_FRACTION_DIGITS); |
|
3625 |
} |
|
3626 |
||
3627 |
// If there was no negative pattern, or if the negative pattern is |
|
3628 |
// identical to the positive pattern, then prepend the minus sign to |
|
3629 |
// the positive pattern to form the negative pattern. |
|
3630 |
if (!gotNegative || |
|
3631 |
(negPrefixPattern.equals(posPrefixPattern) |
|
3632 |
&& negSuffixPattern.equals(posSuffixPattern))) { |
|
3633 |
negSuffixPattern = posSuffixPattern; |
|
3634 |
negPrefixPattern = "'-" + posPrefixPattern; |
|
3635 |
} |
|
3636 |
||
3637 |
expandAffixes(); |
|
3638 |
} |
|
3639 |
||
3640 |
/** |
|
3641 |
* Sets the maximum number of digits allowed in the integer portion of a |
|
3642 |
* number. |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3643 |
* For formatting numbers other than {@code BigInteger} and |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3644 |
* {@code BigDecimal} objects, the lower of {@code newValue} and |
2 | 3645 |
* 309 is used. Negative input values are replaced with 0. |
3646 |
* @see NumberFormat#setMaximumIntegerDigits |
|
3647 |
*/ |
|
13583 | 3648 |
@Override |
2 | 3649 |
public void setMaximumIntegerDigits(int newValue) { |
3650 |
maximumIntegerDigits = Math.min(Math.max(0, newValue), MAXIMUM_INTEGER_DIGITS); |
|
3651 |
super.setMaximumIntegerDigits((maximumIntegerDigits > DOUBLE_INTEGER_DIGITS) ? |
|
3652 |
DOUBLE_INTEGER_DIGITS : maximumIntegerDigits); |
|
3653 |
if (minimumIntegerDigits > maximumIntegerDigits) { |
|
3654 |
minimumIntegerDigits = maximumIntegerDigits; |
|
3655 |
super.setMinimumIntegerDigits((minimumIntegerDigits > DOUBLE_INTEGER_DIGITS) ? |
|
3656 |
DOUBLE_INTEGER_DIGITS : minimumIntegerDigits); |
|
3657 |
} |
|
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
3658 |
fastPathCheckNeeded = true; |
2 | 3659 |
} |
3660 |
||
3661 |
/** |
|
3662 |
* Sets the minimum number of digits allowed in the integer portion of a |
|
3663 |
* number. |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3664 |
* For formatting numbers other than {@code BigInteger} and |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3665 |
* {@code BigDecimal} objects, the lower of {@code newValue} and |
2 | 3666 |
* 309 is used. Negative input values are replaced with 0. |
3667 |
* @see NumberFormat#setMinimumIntegerDigits |
|
3668 |
*/ |
|
13583 | 3669 |
@Override |
2 | 3670 |
public void setMinimumIntegerDigits(int newValue) { |
3671 |
minimumIntegerDigits = Math.min(Math.max(0, newValue), MAXIMUM_INTEGER_DIGITS); |
|
3672 |
super.setMinimumIntegerDigits((minimumIntegerDigits > DOUBLE_INTEGER_DIGITS) ? |
|
3673 |
DOUBLE_INTEGER_DIGITS : minimumIntegerDigits); |
|
3674 |
if (minimumIntegerDigits > maximumIntegerDigits) { |
|
3675 |
maximumIntegerDigits = minimumIntegerDigits; |
|
3676 |
super.setMaximumIntegerDigits((maximumIntegerDigits > DOUBLE_INTEGER_DIGITS) ? |
|
3677 |
DOUBLE_INTEGER_DIGITS : maximumIntegerDigits); |
|
3678 |
} |
|
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
3679 |
fastPathCheckNeeded = true; |
2 | 3680 |
} |
3681 |
||
3682 |
/** |
|
3683 |
* Sets the maximum number of digits allowed in the fraction portion of a |
|
3684 |
* number. |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3685 |
* For formatting numbers other than {@code BigInteger} and |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3686 |
* {@code BigDecimal} objects, the lower of {@code newValue} and |
2 | 3687 |
* 340 is used. Negative input values are replaced with 0. |
3688 |
* @see NumberFormat#setMaximumFractionDigits |
|
3689 |
*/ |
|
13583 | 3690 |
@Override |
2 | 3691 |
public void setMaximumFractionDigits(int newValue) { |
3692 |
maximumFractionDigits = Math.min(Math.max(0, newValue), MAXIMUM_FRACTION_DIGITS); |
|
3693 |
super.setMaximumFractionDigits((maximumFractionDigits > DOUBLE_FRACTION_DIGITS) ? |
|
3694 |
DOUBLE_FRACTION_DIGITS : maximumFractionDigits); |
|
3695 |
if (minimumFractionDigits > maximumFractionDigits) { |
|
3696 |
minimumFractionDigits = maximumFractionDigits; |
|
3697 |
super.setMinimumFractionDigits((minimumFractionDigits > DOUBLE_FRACTION_DIGITS) ? |
|
3698 |
DOUBLE_FRACTION_DIGITS : minimumFractionDigits); |
|
3699 |
} |
|
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
3700 |
fastPathCheckNeeded = true; |
2 | 3701 |
} |
3702 |
||
3703 |
/** |
|
3704 |
* Sets the minimum number of digits allowed in the fraction portion of a |
|
3705 |
* number. |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3706 |
* For formatting numbers other than {@code BigInteger} and |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3707 |
* {@code BigDecimal} objects, the lower of {@code newValue} and |
2 | 3708 |
* 340 is used. Negative input values are replaced with 0. |
3709 |
* @see NumberFormat#setMinimumFractionDigits |
|
3710 |
*/ |
|
13583 | 3711 |
@Override |
2 | 3712 |
public void setMinimumFractionDigits(int newValue) { |
3713 |
minimumFractionDigits = Math.min(Math.max(0, newValue), MAXIMUM_FRACTION_DIGITS); |
|
3714 |
super.setMinimumFractionDigits((minimumFractionDigits > DOUBLE_FRACTION_DIGITS) ? |
|
3715 |
DOUBLE_FRACTION_DIGITS : minimumFractionDigits); |
|
3716 |
if (minimumFractionDigits > maximumFractionDigits) { |
|
3717 |
maximumFractionDigits = minimumFractionDigits; |
|
3718 |
super.setMaximumFractionDigits((maximumFractionDigits > DOUBLE_FRACTION_DIGITS) ? |
|
3719 |
DOUBLE_FRACTION_DIGITS : maximumFractionDigits); |
|
3720 |
} |
|
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
3721 |
fastPathCheckNeeded = true; |
2 | 3722 |
} |
3723 |
||
3724 |
/** |
|
3725 |
* Gets the maximum number of digits allowed in the integer portion of a |
|
3726 |
* number. |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3727 |
* For formatting numbers other than {@code BigInteger} and |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3728 |
* {@code BigDecimal} objects, the lower of the return value and |
2 | 3729 |
* 309 is used. |
3730 |
* @see #setMaximumIntegerDigits |
|
3731 |
*/ |
|
13583 | 3732 |
@Override |
2 | 3733 |
public int getMaximumIntegerDigits() { |
3734 |
return maximumIntegerDigits; |
|
3735 |
} |
|
3736 |
||
3737 |
/** |
|
3738 |
* Gets the minimum number of digits allowed in the integer portion of a |
|
3739 |
* number. |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3740 |
* For formatting numbers other than {@code BigInteger} and |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3741 |
* {@code BigDecimal} objects, the lower of the return value and |
2 | 3742 |
* 309 is used. |
3743 |
* @see #setMinimumIntegerDigits |
|
3744 |
*/ |
|
13583 | 3745 |
@Override |
2 | 3746 |
public int getMinimumIntegerDigits() { |
3747 |
return minimumIntegerDigits; |
|
3748 |
} |
|
3749 |
||
3750 |
/** |
|
3751 |
* Gets the maximum number of digits allowed in the fraction portion of a |
|
3752 |
* number. |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3753 |
* For formatting numbers other than {@code BigInteger} and |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3754 |
* {@code BigDecimal} objects, the lower of the return value and |
2 | 3755 |
* 340 is used. |
3756 |
* @see #setMaximumFractionDigits |
|
3757 |
*/ |
|
13583 | 3758 |
@Override |
2 | 3759 |
public int getMaximumFractionDigits() { |
3760 |
return maximumFractionDigits; |
|
3761 |
} |
|
3762 |
||
3763 |
/** |
|
3764 |
* Gets the minimum number of digits allowed in the fraction portion of a |
|
3765 |
* number. |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3766 |
* For formatting numbers other than {@code BigInteger} and |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3767 |
* {@code BigDecimal} objects, the lower of the return value and |
2 | 3768 |
* 340 is used. |
3769 |
* @see #setMinimumFractionDigits |
|
3770 |
*/ |
|
13583 | 3771 |
@Override |
2 | 3772 |
public int getMinimumFractionDigits() { |
3773 |
return minimumFractionDigits; |
|
3774 |
} |
|
3775 |
||
3776 |
/** |
|
3777 |
* Gets the currency used by this decimal format when formatting |
|
3778 |
* currency values. |
|
3779 |
* The currency is obtained by calling |
|
3780 |
* {@link DecimalFormatSymbols#getCurrency DecimalFormatSymbols.getCurrency} |
|
3781 |
* on this number format's symbols. |
|
3782 |
* |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3783 |
* @return the currency used by this decimal format, or {@code null} |
2 | 3784 |
* @since 1.4 |
3785 |
*/ |
|
13583 | 3786 |
@Override |
2 | 3787 |
public Currency getCurrency() { |
3788 |
return symbols.getCurrency(); |
|
3789 |
} |
|
3790 |
||
3791 |
/** |
|
3792 |
* Sets the currency used by this number format when formatting |
|
3793 |
* currency values. This does not update the minimum or maximum |
|
3794 |
* number of fraction digits used by the number format. |
|
3795 |
* The currency is set by calling |
|
3796 |
* {@link DecimalFormatSymbols#setCurrency DecimalFormatSymbols.setCurrency} |
|
3797 |
* on this number format's symbols. |
|
3798 |
* |
|
3799 |
* @param currency the new currency to be used by this decimal format |
|
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
3800 |
* @throws NullPointerException if {@code currency} is null |
2 | 3801 |
* @since 1.4 |
3802 |
*/ |
|
13583 | 3803 |
@Override |
2 | 3804 |
public void setCurrency(Currency currency) { |
3805 |
if (currency != symbols.getCurrency()) { |
|
3806 |
symbols.setCurrency(currency); |
|
3807 |
if (isCurrencyFormat) { |
|
3808 |
expandAffixes(); |
|
3809 |
} |
|
3810 |
} |
|
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
3811 |
fastPathCheckNeeded = true; |
2 | 3812 |
} |
3813 |
||
3814 |
/** |
|
3815 |
* Gets the {@link java.math.RoundingMode} used in this DecimalFormat. |
|
3816 |
* |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3817 |
* @return The {@code RoundingMode} used for this DecimalFormat. |
2 | 3818 |
* @see #setRoundingMode(RoundingMode) |
3819 |
* @since 1.6 |
|
3820 |
*/ |
|
13583 | 3821 |
@Override |
2 | 3822 |
public RoundingMode getRoundingMode() { |
3823 |
return roundingMode; |
|
3824 |
} |
|
3825 |
||
3826 |
/** |
|
3827 |
* Sets the {@link java.math.RoundingMode} used in this DecimalFormat. |
|
3828 |
* |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3829 |
* @param roundingMode The {@code RoundingMode} to be used |
2 | 3830 |
* @see #getRoundingMode() |
58242
94bb65cb37d3
8230648: Replace @exception tag with @throws in java.base
jboes
parents:
57956
diff
changeset
|
3831 |
* @throws NullPointerException if {@code roundingMode} is null. |
2 | 3832 |
* @since 1.6 |
3833 |
*/ |
|
13583 | 3834 |
@Override |
2 | 3835 |
public void setRoundingMode(RoundingMode roundingMode) { |
3836 |
if (roundingMode == null) { |
|
3837 |
throw new NullPointerException(); |
|
3838 |
} |
|
3839 |
||
3840 |
this.roundingMode = roundingMode; |
|
3841 |
digitList.setRoundingMode(roundingMode); |
|
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
3842 |
fastPathCheckNeeded = true; |
2 | 3843 |
} |
3844 |
||
3845 |
/** |
|
3846 |
* Reads the default serializable fields from the stream and performs |
|
3847 |
* validations and adjustments for older serialized versions. The |
|
3848 |
* validations and adjustments are: |
|
3849 |
* <ol> |
|
3850 |
* <li> |
|
3851 |
* Verify that the superclass's digit count fields correctly reflect |
|
3852 |
* the limits imposed on formatting numbers other than |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3853 |
* {@code BigInteger} and {@code BigDecimal} objects. These |
2 | 3854 |
* limits are stored in the superclass for serialization compatibility |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3855 |
* with older versions, while the limits for {@code BigInteger} and |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3856 |
* {@code BigDecimal} objects are kept in this class. |
2 | 3857 |
* If, in the superclass, the minimum or maximum integer digit count is |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3858 |
* larger than {@code DOUBLE_INTEGER_DIGITS} or if the minimum or |
2 | 3859 |
* maximum fraction digit count is larger than |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3860 |
* {@code DOUBLE_FRACTION_DIGITS}, then the stream data is invalid |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3861 |
* and this method throws an {@code InvalidObjectException}. |
2 | 3862 |
* <li> |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3863 |
* If {@code serialVersionOnStream} is less than 4, initialize |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3864 |
* {@code roundingMode} to {@link java.math.RoundingMode#HALF_EVEN |
2 | 3865 |
* RoundingMode.HALF_EVEN}. This field is new with version 4. |
3866 |
* <li> |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3867 |
* If {@code serialVersionOnStream} is less than 3, then call |
2 | 3868 |
* the setters for the minimum and maximum integer and fraction digits with |
3869 |
* the values of the corresponding superclass getters to initialize the |
|
3870 |
* fields in this class. The fields in this class are new with version 3. |
|
3871 |
* <li> |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3872 |
* If {@code serialVersionOnStream} is less than 1, indicating that |
2 | 3873 |
* the stream was written by JDK 1.1, initialize |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3874 |
* {@code useExponentialNotation} |
2 | 3875 |
* to false, since it was not present in JDK 1.1. |
3876 |
* <li> |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3877 |
* Set {@code serialVersionOnStream} to the maximum allowed value so |
2 | 3878 |
* that default serialization will work properly if this object is streamed |
3879 |
* out again. |
|
3880 |
* </ol> |
|
3881 |
* |
|
3882 |
* <p>Stream versions older than 2 will not have the affix pattern variables |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3883 |
* {@code posPrefixPattern} etc. As a result, they will be initialized |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3884 |
* to {@code null}, which means the affix strings will be taken as |
2 | 3885 |
* literal values. This is exactly what we want, since that corresponds to |
3886 |
* the pre-version-2 behavior. |
|
3887 |
*/ |
|
57956
e0b8b019d2f5
8229997: Apply java.io.Serial annotations in java.base
darcy
parents:
54252
diff
changeset
|
3888 |
@java.io.Serial |
2 | 3889 |
private void readObject(ObjectInputStream stream) |
3890 |
throws IOException, ClassNotFoundException |
|
3891 |
{ |
|
3892 |
stream.defaultReadObject(); |
|
3893 |
digitList = new DigitList(); |
|
3894 |
||
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
3895 |
// We force complete fast-path reinitialization when the instance is |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
3896 |
// deserialized. See clone() comment on fastPathCheckNeeded. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
3897 |
fastPathCheckNeeded = true; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
3898 |
isFastPath = false; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
3899 |
fastPathData = null; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
3900 |
|
2 | 3901 |
if (serialVersionOnStream < 4) { |
3902 |
setRoundingMode(RoundingMode.HALF_EVEN); |
|
14020
b17c22caa38c
7196316: Wrong rounding mode in DecimalFormat after deserialization
peytoia
parents:
14015
diff
changeset
|
3903 |
} else { |
b17c22caa38c
7196316: Wrong rounding mode in DecimalFormat after deserialization
peytoia
parents:
14015
diff
changeset
|
3904 |
setRoundingMode(getRoundingMode()); |
2 | 3905 |
} |
14020
b17c22caa38c
7196316: Wrong rounding mode in DecimalFormat after deserialization
peytoia
parents:
14015
diff
changeset
|
3906 |
|
2 | 3907 |
// We only need to check the maximum counts because NumberFormat |
3908 |
// .readObject has already ensured that the maximum is greater than the |
|
3909 |
// minimum count. |
|
3910 |
if (super.getMaximumIntegerDigits() > DOUBLE_INTEGER_DIGITS || |
|
3911 |
super.getMaximumFractionDigits() > DOUBLE_FRACTION_DIGITS) { |
|
3912 |
throw new InvalidObjectException("Digit count out of range"); |
|
3913 |
} |
|
3914 |
if (serialVersionOnStream < 3) { |
|
3915 |
setMaximumIntegerDigits(super.getMaximumIntegerDigits()); |
|
3916 |
setMinimumIntegerDigits(super.getMinimumIntegerDigits()); |
|
3917 |
setMaximumFractionDigits(super.getMaximumFractionDigits()); |
|
3918 |
setMinimumFractionDigits(super.getMinimumFractionDigits()); |
|
3919 |
} |
|
3920 |
if (serialVersionOnStream < 1) { |
|
3921 |
// Didn't have exponential fields |
|
3922 |
useExponentialNotation = false; |
|
3923 |
} |
|
58603
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
3924 |
|
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
3925 |
// Restore the invariant value if groupingSize is invalid. |
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
3926 |
if (groupingSize < 0) { |
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
3927 |
groupingSize = 3; |
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
3928 |
} |
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
3929 |
|
2 | 3930 |
serialVersionOnStream = currentSerialVersion; |
3931 |
} |
|
3932 |
||
3933 |
//---------------------------------------------------------------------- |
|
3934 |
// INSTANCE VARIABLES |
|
3935 |
//---------------------------------------------------------------------- |
|
3936 |
||
3937 |
private transient DigitList digitList = new DigitList(); |
|
3938 |
||
3939 |
/** |
|
3940 |
* The symbol used as a prefix when formatting positive numbers, e.g. "+". |
|
3941 |
* |
|
3942 |
* @serial |
|
3943 |
* @see #getPositivePrefix |
|
3944 |
*/ |
|
3945 |
private String positivePrefix = ""; |
|
3946 |
||
3947 |
/** |
|
3948 |
* The symbol used as a suffix when formatting positive numbers. |
|
3949 |
* This is often an empty string. |
|
3950 |
* |
|
3951 |
* @serial |
|
3952 |
* @see #getPositiveSuffix |
|
3953 |
*/ |
|
3954 |
private String positiveSuffix = ""; |
|
3955 |
||
3956 |
/** |
|
3957 |
* The symbol used as a prefix when formatting negative numbers, e.g. "-". |
|
3958 |
* |
|
3959 |
* @serial |
|
3960 |
* @see #getNegativePrefix |
|
3961 |
*/ |
|
3962 |
private String negativePrefix = "-"; |
|
3963 |
||
3964 |
/** |
|
3965 |
* The symbol used as a suffix when formatting negative numbers. |
|
3966 |
* This is often an empty string. |
|
3967 |
* |
|
3968 |
* @serial |
|
3969 |
* @see #getNegativeSuffix |
|
3970 |
*/ |
|
3971 |
private String negativeSuffix = ""; |
|
3972 |
||
3973 |
/** |
|
3974 |
* The prefix pattern for non-negative numbers. This variable corresponds |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3975 |
* to {@code positivePrefix}. |
2 | 3976 |
* |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3977 |
* <p>This pattern is expanded by the method {@code expandAffix()} to |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3978 |
* {@code positivePrefix} to update the latter to reflect changes in |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3979 |
* {@code symbols}. If this variable is {@code null} then |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3980 |
* {@code positivePrefix} is taken as a literal value that does not |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3981 |
* change when {@code symbols} changes. This variable is always |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3982 |
* {@code null} for {@code DecimalFormat} objects older than |
2 | 3983 |
* stream version 2 restored from stream. |
3984 |
* |
|
3985 |
* @serial |
|
3986 |
* @since 1.3 |
|
3987 |
*/ |
|
3988 |
private String posPrefixPattern; |
|
3989 |
||
3990 |
/** |
|
3991 |
* The suffix pattern for non-negative numbers. This variable corresponds |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3992 |
* to {@code positiveSuffix}. This variable is analogous to |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
3993 |
* {@code posPrefixPattern}; see that variable for further |
2 | 3994 |
* documentation. |
3995 |
* |
|
3996 |
* @serial |
|
3997 |
* @since 1.3 |
|
3998 |
*/ |
|
3999 |
private String posSuffixPattern; |
|
4000 |
||
4001 |
/** |
|
4002 |
* The prefix pattern for negative numbers. This variable corresponds |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4003 |
* to {@code negativePrefix}. This variable is analogous to |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4004 |
* {@code posPrefixPattern}; see that variable for further |
2 | 4005 |
* documentation. |
4006 |
* |
|
4007 |
* @serial |
|
4008 |
* @since 1.3 |
|
4009 |
*/ |
|
4010 |
private String negPrefixPattern; |
|
4011 |
||
4012 |
/** |
|
4013 |
* The suffix pattern for negative numbers. This variable corresponds |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4014 |
* to {@code negativeSuffix}. This variable is analogous to |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4015 |
* {@code posPrefixPattern}; see that variable for further |
2 | 4016 |
* documentation. |
4017 |
* |
|
4018 |
* @serial |
|
4019 |
* @since 1.3 |
|
4020 |
*/ |
|
4021 |
private String negSuffixPattern; |
|
4022 |
||
4023 |
/** |
|
4024 |
* The multiplier for use in percent, per mille, etc. |
|
4025 |
* |
|
4026 |
* @serial |
|
4027 |
* @see #getMultiplier |
|
4028 |
*/ |
|
4029 |
private int multiplier = 1; |
|
4030 |
||
4031 |
/** |
|
4032 |
* The number of digits between grouping separators in the integer |
|
58603
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
4033 |
* portion of a number. Must be non-negative and less than or equal to |
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
4034 |
* {@link java.lang.Byte#MAX_VALUE Byte.MAX_VALUE} if |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4035 |
* {@code NumberFormat.groupingUsed} is true. |
2 | 4036 |
* |
4037 |
* @serial |
|
4038 |
* @see #getGroupingSize |
|
4039 |
* @see java.text.NumberFormat#isGroupingUsed |
|
4040 |
*/ |
|
58603
2312d1a04c49
8212749: DecimalFormat.setGroupingSize(int) allows setting negative grouping size
naoto
parents:
58242
diff
changeset
|
4041 |
private byte groupingSize = 3; // invariant, 0 - 127, if groupingUsed |
2 | 4042 |
|
4043 |
/** |
|
4044 |
* If true, forces the decimal separator to always appear in a formatted |
|
4045 |
* number, even if the fractional part of the number is zero. |
|
4046 |
* |
|
4047 |
* @serial |
|
4048 |
* @see #isDecimalSeparatorAlwaysShown |
|
4049 |
*/ |
|
4050 |
private boolean decimalSeparatorAlwaysShown = false; |
|
4051 |
||
4052 |
/** |
|
4053 |
* If true, parse returns BigDecimal wherever possible. |
|
4054 |
* |
|
4055 |
* @serial |
|
4056 |
* @see #isParseBigDecimal |
|
4057 |
* @since 1.5 |
|
4058 |
*/ |
|
4059 |
private boolean parseBigDecimal = false; |
|
4060 |
||
4061 |
||
4062 |
/** |
|
4063 |
* True if this object represents a currency format. This determines |
|
4064 |
* whether the monetary decimal separator is used instead of the normal one. |
|
4065 |
*/ |
|
4066 |
private transient boolean isCurrencyFormat = false; |
|
4067 |
||
4068 |
/** |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4069 |
* The {@code DecimalFormatSymbols} object used by this format. |
2 | 4070 |
* It contains the symbols used to format numbers, e.g. the grouping separator, |
4071 |
* decimal separator, and so on. |
|
4072 |
* |
|
4073 |
* @serial |
|
4074 |
* @see #setDecimalFormatSymbols |
|
4075 |
* @see java.text.DecimalFormatSymbols |
|
4076 |
*/ |
|
4077 |
private DecimalFormatSymbols symbols = null; // LIU new DecimalFormatSymbols(); |
|
4078 |
||
4079 |
/** |
|
4080 |
* True to force the use of exponential (i.e. scientific) notation when formatting |
|
4081 |
* numbers. |
|
4082 |
* |
|
4083 |
* @serial |
|
4084 |
* @since 1.2 |
|
4085 |
*/ |
|
4086 |
private boolean useExponentialNotation; // Newly persistent in the Java 2 platform v.1.2 |
|
4087 |
||
4088 |
/** |
|
4089 |
* FieldPositions describing the positive prefix String. This is |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4090 |
* lazily created. Use {@code getPositivePrefixFieldPositions} |
2 | 4091 |
* when needed. |
4092 |
*/ |
|
4093 |
private transient FieldPosition[] positivePrefixFieldPositions; |
|
4094 |
||
4095 |
/** |
|
4096 |
* FieldPositions describing the positive suffix String. This is |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4097 |
* lazily created. Use {@code getPositiveSuffixFieldPositions} |
2 | 4098 |
* when needed. |
4099 |
*/ |
|
4100 |
private transient FieldPosition[] positiveSuffixFieldPositions; |
|
4101 |
||
4102 |
/** |
|
4103 |
* FieldPositions describing the negative prefix String. This is |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4104 |
* lazily created. Use {@code getNegativePrefixFieldPositions} |
2 | 4105 |
* when needed. |
4106 |
*/ |
|
4107 |
private transient FieldPosition[] negativePrefixFieldPositions; |
|
4108 |
||
4109 |
/** |
|
4110 |
* FieldPositions describing the negative suffix String. This is |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4111 |
* lazily created. Use {@code getNegativeSuffixFieldPositions} |
2 | 4112 |
* when needed. |
4113 |
*/ |
|
4114 |
private transient FieldPosition[] negativeSuffixFieldPositions; |
|
4115 |
||
4116 |
/** |
|
4117 |
* The minimum number of digits used to display the exponent when a number is |
|
4118 |
* formatted in exponential notation. This field is ignored if |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4119 |
* {@code useExponentialNotation} is not true. |
2 | 4120 |
* |
4121 |
* @serial |
|
4122 |
* @since 1.2 |
|
4123 |
*/ |
|
4124 |
private byte minExponentDigits; // Newly persistent in the Java 2 platform v.1.2 |
|
4125 |
||
4126 |
/** |
|
4127 |
* The maximum number of digits allowed in the integer portion of a |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4128 |
* {@code BigInteger} or {@code BigDecimal} number. |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4129 |
* {@code maximumIntegerDigits} must be greater than or equal to |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4130 |
* {@code minimumIntegerDigits}. |
2 | 4131 |
* |
4132 |
* @serial |
|
4133 |
* @see #getMaximumIntegerDigits |
|
4134 |
* @since 1.5 |
|
4135 |
*/ |
|
4136 |
private int maximumIntegerDigits = super.getMaximumIntegerDigits(); |
|
4137 |
||
4138 |
/** |
|
4139 |
* The minimum number of digits allowed in the integer portion of a |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4140 |
* {@code BigInteger} or {@code BigDecimal} number. |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4141 |
* {@code minimumIntegerDigits} must be less than or equal to |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4142 |
* {@code maximumIntegerDigits}. |
2 | 4143 |
* |
4144 |
* @serial |
|
4145 |
* @see #getMinimumIntegerDigits |
|
4146 |
* @since 1.5 |
|
4147 |
*/ |
|
4148 |
private int minimumIntegerDigits = super.getMinimumIntegerDigits(); |
|
4149 |
||
4150 |
/** |
|
4151 |
* The maximum number of digits allowed in the fractional portion of a |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4152 |
* {@code BigInteger} or {@code BigDecimal} number. |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4153 |
* {@code maximumFractionDigits} must be greater than or equal to |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4154 |
* {@code minimumFractionDigits}. |
2 | 4155 |
* |
4156 |
* @serial |
|
4157 |
* @see #getMaximumFractionDigits |
|
4158 |
* @since 1.5 |
|
4159 |
*/ |
|
4160 |
private int maximumFractionDigits = super.getMaximumFractionDigits(); |
|
4161 |
||
4162 |
/** |
|
4163 |
* The minimum number of digits allowed in the fractional portion of a |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4164 |
* {@code BigInteger} or {@code BigDecimal} number. |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4165 |
* {@code minimumFractionDigits} must be less than or equal to |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4166 |
* {@code maximumFractionDigits}. |
2 | 4167 |
* |
4168 |
* @serial |
|
4169 |
* @see #getMinimumFractionDigits |
|
4170 |
* @since 1.5 |
|
4171 |
*/ |
|
4172 |
private int minimumFractionDigits = super.getMinimumFractionDigits(); |
|
4173 |
||
4174 |
/** |
|
4175 |
* The {@link java.math.RoundingMode} used in this DecimalFormat. |
|
4176 |
* |
|
4177 |
* @serial |
|
4178 |
* @since 1.6 |
|
4179 |
*/ |
|
4180 |
private RoundingMode roundingMode = RoundingMode.HALF_EVEN; |
|
4181 |
||
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4182 |
// ------ DecimalFormat fields for fast-path for double algorithm ------ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4183 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4184 |
/** |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4185 |
* Helper inner utility class for storing the data used in the fast-path |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4186 |
* algorithm. Almost all fields related to fast-path are encapsulated in |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4187 |
* this class. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4188 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4189 |
* Any {@code DecimalFormat} instance has a {@code fastPathData} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4190 |
* reference field that is null unless both the properties of the instance |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4191 |
* are such that the instance is in the "fast-path" state, and a format call |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4192 |
* has been done at least once while in this state. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4193 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4194 |
* Almost all fields are related to the "fast-path" state only and don't |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4195 |
* change until one of the instance properties is changed. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4196 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4197 |
* {@code firstUsedIndex} and {@code lastFreeIndex} are the only |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4198 |
* two fields that are used and modified while inside a call to |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4199 |
* {@code fastDoubleFormat}. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4200 |
* |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4201 |
*/ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4202 |
private static class FastPathData { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4203 |
// --- Temporary fields used in fast-path, shared by several methods. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4204 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4205 |
/** The first unused index at the end of the formatted result. */ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4206 |
int lastFreeIndex; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4207 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4208 |
/** The first used index at the beginning of the formatted result */ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4209 |
int firstUsedIndex; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4210 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4211 |
// --- State fields related to fast-path status. Changes due to a |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4212 |
// property change only. Set by checkAndSetFastPathStatus() only. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4213 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4214 |
/** Difference between locale zero and default zero representation. */ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4215 |
int zeroDelta; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4216 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4217 |
/** Locale char for grouping separator. */ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4218 |
char groupingChar; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4219 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4220 |
/** Fixed index position of last integral digit of formatted result */ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4221 |
int integralLastIndex; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4222 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4223 |
/** Fixed index position of first fractional digit of formatted result */ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4224 |
int fractionalFirstIndex; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4225 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4226 |
/** Fractional constants depending on decimal|currency state */ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4227 |
double fractionalScaleFactor; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4228 |
int fractionalMaxIntBound; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4229 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4230 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4231 |
/** The char array buffer that will contain the formatted result */ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4232 |
char[] fastPathContainer; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4233 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4234 |
/** Suffixes recorded as char array for efficiency. */ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4235 |
char[] charsPositivePrefix; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4236 |
char[] charsNegativePrefix; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4237 |
char[] charsPositiveSuffix; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4238 |
char[] charsNegativeSuffix; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4239 |
boolean positiveAffixesRequired = true; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4240 |
boolean negativeAffixesRequired = true; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4241 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4242 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4243 |
/** The format fast-path status of the instance. Logical state. */ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4244 |
private transient boolean isFastPath = false; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4245 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4246 |
/** Flag stating need of check and reinit fast-path status on next format call. */ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4247 |
private transient boolean fastPathCheckNeeded = true; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4248 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4249 |
/** DecimalFormat reference to its FastPathData */ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4250 |
private transient FastPathData fastPathData; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4251 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4252 |
|
2 | 4253 |
//---------------------------------------------------------------------- |
4254 |
||
4255 |
static final int currentSerialVersion = 4; |
|
4256 |
||
4257 |
/** |
|
4258 |
* The internal serial version which says which version was written. |
|
4259 |
* Possible values are: |
|
4260 |
* <ul> |
|
4261 |
* <li><b>0</b> (default): versions before the Java 2 platform v1.2 |
|
4262 |
* <li><b>1</b>: version for 1.2, which includes the two new fields |
|
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4263 |
* {@code useExponentialNotation} and |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4264 |
* {@code minExponentDigits}. |
2 | 4265 |
* <li><b>2</b>: version for 1.3 and later, which adds four new fields: |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4266 |
* {@code posPrefixPattern}, {@code posSuffixPattern}, |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4267 |
* {@code negPrefixPattern}, and {@code negSuffixPattern}. |
2 | 4268 |
* <li><b>3</b>: version for 1.5 and later, which adds five new fields: |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4269 |
* {@code maximumIntegerDigits}, |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4270 |
* {@code minimumIntegerDigits}, |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4271 |
* {@code maximumFractionDigits}, |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4272 |
* {@code minimumFractionDigits}, and |
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4273 |
* {@code parseBigDecimal}. |
2 | 4274 |
* <li><b>4</b>: version for 1.6 and later, which adds one new field: |
54252
83deaa8f0c8e
8220224: With CLDR provider, NumberFormat.format could not handle locale with number extension correctly.
naoto
parents:
54206
diff
changeset
|
4275 |
* {@code roundingMode}. |
2 | 4276 |
* </ul> |
4277 |
* @since 1.2 |
|
4278 |
* @serial |
|
4279 |
*/ |
|
4280 |
private int serialVersionOnStream = currentSerialVersion; |
|
4281 |
||
4282 |
//---------------------------------------------------------------------- |
|
4283 |
// CONSTANTS |
|
4284 |
//---------------------------------------------------------------------- |
|
4285 |
||
14015
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4286 |
// ------ Fast-Path for double Constants ------ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4287 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4288 |
/** Maximum valid integer value for applying fast-path algorithm */ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4289 |
private static final double MAX_INT_AS_DOUBLE = (double) Integer.MAX_VALUE; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4290 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4291 |
/** |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4292 |
* The digit arrays used in the fast-path methods for collecting digits. |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4293 |
* Using 3 constants arrays of chars ensures a very fast collection of digits |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4294 |
*/ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4295 |
private static class DigitArrays { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4296 |
static final char[] DigitOnes1000 = new char[1000]; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4297 |
static final char[] DigitTens1000 = new char[1000]; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4298 |
static final char[] DigitHundreds1000 = new char[1000]; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4299 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4300 |
// initialize on demand holder class idiom for arrays of digits |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4301 |
static { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4302 |
int tenIndex = 0; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4303 |
int hundredIndex = 0; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4304 |
char digitOne = '0'; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4305 |
char digitTen = '0'; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4306 |
char digitHundred = '0'; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4307 |
for (int i = 0; i < 1000; i++ ) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4308 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4309 |
DigitOnes1000[i] = digitOne; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4310 |
if (digitOne == '9') |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4311 |
digitOne = '0'; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4312 |
else |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4313 |
digitOne++; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4314 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4315 |
DigitTens1000[i] = digitTen; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4316 |
if (i == (tenIndex + 9)) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4317 |
tenIndex += 10; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4318 |
if (digitTen == '9') |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4319 |
digitTen = '0'; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4320 |
else |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4321 |
digitTen++; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4322 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4323 |
|
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4324 |
DigitHundreds1000[i] = digitHundred; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4325 |
if (i == (hundredIndex + 99)) { |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4326 |
digitHundred++; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4327 |
hundredIndex += 100; |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4328 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4329 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4330 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4331 |
} |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4332 |
// ------ Fast-Path for double Constants end ------ |
f771d5fb3b27
7050528: Improve performance of java.text.DecimalFormat.format() call stack
olagneau
parents:
13583
diff
changeset
|
4333 |
|
2 | 4334 |
// Constants for characters used in programmatic (unlocalized) patterns. |
4335 |
private static final char PATTERN_ZERO_DIGIT = '0'; |
|
4336 |
private static final char PATTERN_GROUPING_SEPARATOR = ','; |
|
4337 |
private static final char PATTERN_DECIMAL_SEPARATOR = '.'; |
|
4338 |
private static final char PATTERN_PER_MILLE = '\u2030'; |
|
4339 |
private static final char PATTERN_PERCENT = '%'; |
|
4340 |
private static final char PATTERN_DIGIT = '#'; |
|
4341 |
private static final char PATTERN_SEPARATOR = ';'; |
|
4342 |
private static final String PATTERN_EXPONENT = "E"; |
|
4343 |
private static final char PATTERN_MINUS = '-'; |
|
4344 |
||
4345 |
/** |
|
4346 |
* The CURRENCY_SIGN is the standard Unicode symbol for currency. It |
|
4347 |
* is used in patterns and substituted with either the currency symbol, |
|
4348 |
* or if it is doubled, with the international currency symbol. If the |
|
4349 |
* CURRENCY_SIGN is seen in a pattern, then the decimal separator is |
|
4350 |
* replaced with the monetary decimal separator. |
|
4351 |
* |
|
4352 |
* The CURRENCY_SIGN is not localized. |
|
4353 |
*/ |
|
4354 |
private static final char CURRENCY_SIGN = '\u00A4'; |
|
4355 |
||
4356 |
private static final char QUOTE = '\''; |
|
4357 |
||
4358 |
private static FieldPosition[] EmptyFieldPositionArray = new FieldPosition[0]; |
|
4359 |
||
4360 |
// Upper limit on integer and fraction digits for a Java double |
|
4361 |
static final int DOUBLE_INTEGER_DIGITS = 309; |
|
4362 |
static final int DOUBLE_FRACTION_DIGITS = 340; |
|
4363 |
||
4364 |
// Upper limit on integer and fraction digits for BigDecimal and BigInteger |
|
4365 |
static final int MAXIMUM_INTEGER_DIGITS = Integer.MAX_VALUE; |
|
4366 |
static final int MAXIMUM_FRACTION_DIGITS = Integer.MAX_VALUE; |
|
4367 |
||
4368 |
// Proclaim JDK 1.1 serial compatibility. |
|
57956
e0b8b019d2f5
8229997: Apply java.io.Serial annotations in java.base
darcy
parents:
54252
diff
changeset
|
4369 |
@java.io.Serial |
2 | 4370 |
static final long serialVersionUID = 864413376551465018L; |
4371 |
} |