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