GNU Classpath (0.17) | ||
Frames | No Frames |
1: /* NumberFormat.java -- Formats and parses numbers 2: Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004 Free Software Foundation, Inc. 3: 4: This file is part of GNU Classpath. 5: 6: GNU Classpath is free software; you can redistribute it and/or modify 7: it under the terms of the GNU General Public License as published by 8: the Free Software Foundation; either version 2, or (at your option) 9: any later version. 10: 11: GNU Classpath is distributed in the hope that it will be useful, but 12: WITHOUT ANY WARRANTY; without even the implied warranty of 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14: General Public License for more details. 15: 16: You should have received a copy of the GNU General Public License 17: along with GNU Classpath; see the file COPYING. If not, write to the 18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19: 02110-1301 USA. 20: 21: Linking this library statically or dynamically with other modules is 22: making a combined work based on this library. Thus, the terms and 23: conditions of the GNU General Public License cover the whole 24: combination. 25: 26: As a special exception, the copyright holders of this library give you 27: permission to link this library with independent modules to produce an 28: executable, regardless of the license terms of these independent 29: modules, and to copy and distribute the resulting executable under 30: terms of your choice, provided that you also meet, for each linked 31: independent module, the terms and conditions of the license of that 32: module. An independent module is a module which is not derived from 33: or based on this library. If you modify this library, you may extend 34: this exception to your version of the library, but you are not 35: obligated to do so. If you do not wish to do so, delete this 36: exception statement from your version. */ 37: 38: 39: package java.text; 40: 41: import java.io.IOException; 42: import java.io.InvalidObjectException; 43: import java.io.ObjectInputStream; 44: import java.io.ObjectOutputStream; 45: import java.util.Currency; 46: import java.util.Locale; 47: import java.util.MissingResourceException; 48: import java.util.ResourceBundle; 49: 50: /** 51: * This is the abstract superclass of all classes which format and 52: * parse numeric values such as decimal numbers, integers, currency values, 53: * and percentages. These classes perform their parsing and formatting 54: * in a locale specific manner, accounting for such items as differing 55: * currency symbols and thousands separators. 56: * <p> 57: * To create an instance of a concrete subclass of <code>NumberFormat</code>, 58: * do not call a class constructor directly. Instead, use one of the 59: * static factory methods in this class such as 60: * <code>getCurrencyInstance</code>. 61: * 62: * @author Tom Tromey (tromey@cygnus.com) 63: * @author Aaron M. Renn (arenn@urbanophile.com) 64: * @date March 4, 1999 65: */ 66: /* Written using "Java Class Libraries", 2nd edition, plus online 67: * API docs for JDK 1.2 from http://www.javasoft.com. 68: * Status: Believed complete and correct to 1.2, except getAvailableLocales. 69: */ 70: public abstract class NumberFormat extends Format implements Cloneable 71: { 72: /** 73: * This is a constant used to create a <code>FieldPosition</code> object 74: * that will return the integer portion of a formatted number. 75: */ 76: public static final int INTEGER_FIELD = 0; 77: 78: /** 79: * This is a constant used to create a <code>FieldPosition</code> object 80: * that will return the fractional portion of a formatted number. 81: */ 82: public static final int FRACTION_FIELD = 1; 83: 84: public static class Field extends Format.Field 85: { 86: static final long serialVersionUID = 7494728892700160890L; 87: 88: /** 89: * Attribute set to all characters containing digits of the integer 90: * part. 91: */ 92: public static final NumberFormat.Field INTEGER 93: = new Field("integer"); 94: 95: /** 96: * Attribute set to all characters containing digits of the fractional 97: * part. 98: */ 99: public static final NumberFormat.Field FRACTION 100: = new Field("fraction"); 101: 102: /** 103: * Attribute set to all characters containing digits of the exponential 104: * part. 105: */ 106: public static final NumberFormat.Field EXPONENT 107: = new Field("exponent"); 108: 109: /** 110: * Attribute set to all characters containing a decimal separator. 111: */ 112: public static final NumberFormat.Field DECIMAL_SEPARATOR 113: = new Field("decimal separator"); 114: 115: /** 116: * Attribute set to all characters containing a sign (plus or minus). 117: */ 118: public static final NumberFormat.Field SIGN 119: = new Field("sign"); 120: 121: /** 122: * Attribute set to all characters containing a grouping separator (e.g. 123: * a comma, a white space,...). 124: */ 125: public static final NumberFormat.Field GROUPING_SEPARATOR 126: = new Field("grouping separator"); 127: 128: /** 129: * Attribute set to all characters containing an exponential symbol (e.g. 130: * 'E') 131: */ 132: public static final NumberFormat.Field EXPONENT_SYMBOL 133: = new Field("exponent symbol"); 134: 135: /** 136: * Attribute set to all characters containing a percent symbol (e.g. '%') 137: */ 138: public static final NumberFormat.Field PERCENT 139: = new Field("percent"); 140: 141: /** 142: * Attribute set to all characters containing a permille symbol. 143: */ 144: public static final NumberFormat.Field PERMILLE 145: = new Field("permille"); 146: 147: /** 148: * Attribute set to all characters containing the currency unit. 149: */ 150: public static final NumberFormat.Field CURRENCY 151: = new Field("currency"); 152: 153: /** 154: * Attribute set to all characters containing the exponent sign. 155: */ 156: public static final NumberFormat.Field EXPONENT_SIGN 157: = new Field("exponent sign"); 158: 159: /** 160: * Private fields to register all fields contained in this descriptor. 161: */ 162: private static final NumberFormat.Field[] allFields = 163: { 164: INTEGER, FRACTION, EXPONENT, DECIMAL_SEPARATOR, SIGN, 165: GROUPING_SEPARATOR, EXPONENT_SYMBOL, PERCENT, 166: PERMILLE, CURRENCY, EXPONENT_SIGN 167: }; 168: 169: /** 170: * This constructor is only used by the deserializer. Without it, 171: * it would fail to construct a valid object. 172: */ 173: private Field() 174: { 175: super(""); 176: } 177: 178: /** 179: * Create a Field instance with the specified field name. 180: * 181: * @param field_name Field name for the new Field instance. 182: */ 183: protected Field(String field_name) 184: { 185: super (field_name); 186: } 187: 188: /** 189: * This function is used by the deserializer to know which object 190: * to use when it encounters an encoded NumberFormat.Field in a 191: * serialization stream. If the stream is valid it should return 192: * one of the above field. In the other case we throw an exception. 193: * 194: * @return a valid official NumberFormat.Field instance. 195: * 196: * @throws InvalidObjectException if the field name is invalid. 197: */ 198: protected Object readResolve() throws InvalidObjectException 199: { 200: String s = getName(); 201: for (int i = 0; i < allFields.length; i++) 202: if (s.equals(allFields[i].getName())) 203: return allFields[i]; 204: 205: throw new InvalidObjectException("no such NumberFormat field called " 206: + s); 207: } 208: } 209: 210: /** 211: * This method is a specialization of the format method that performs 212: * a simple formatting of the specified <code>long</code> number. 213: * 214: * @param number The <code>long</code> to format. 215: * 216: * @return The formatted number 217: */ 218: public final String format (long number) 219: { 220: StringBuffer sbuf = new StringBuffer(50); 221: format (number, sbuf, null); 222: return sbuf.toString(); 223: } 224: 225: public final StringBuffer format (Object obj, StringBuffer sbuf, 226: FieldPosition pos) 227: { 228: if (obj instanceof Number) 229: return format(((Number) obj).doubleValue(), sbuf, pos); 230: else 231: throw new IllegalArgumentException 232: ("Cannot format given Object as a Number"); 233: } 234: 235: /** 236: * This method formats the specified <code>double</code> and appends it to 237: * a <code>StringBuffer</code>. 238: * 239: * @param number The <code>double</code> to format. 240: * @param sb The <code>StringBuffer</code> to append the formatted number to. 241: * @param pos The desired <code>FieldPosition</code>. 242: * 243: * @return The <code>StringBuffer</code> with the appended number. 244: */ 245: public abstract StringBuffer format (double number, 246: StringBuffer sbuf, FieldPosition pos); 247: 248: /** 249: * This method formats the specified <code>long</code> and appends it to 250: * a <code>StringBuffer</code>. 251: * 252: * @param number The <code>long</code> to format. 253: * @param sb The <code>StringBuffer</code> to append the formatted number to. 254: * @param pos The desired <code>FieldPosition</code>. 255: * 256: * @return The <code>StringBuffer</code> with the appended number. 257: */ 258: public abstract StringBuffer format (long number, 259: StringBuffer sbuf, FieldPosition pos); 260: 261: /** 262: * This method tests the specified object for equality against this object. 263: * This will be <code>true</code> if the following conditions are met: 264: * <p> 265: * <ul> 266: * <li>The specified object is not <code>null</code>. 267: * <li>The specified object is an instance of <code>NumberFormat</code>. 268: * </ul> 269: * <p> 270: * Since this method does not test much, it is highly advised that 271: * concrete subclasses override this method. 272: * 273: * @param obj The <code>Object</code> to test against equality with 274: * this object. 275: * 276: * @return <code>true</code> if the specified object is equal to 277: * this object, <code>false</code> otherwise. 278: */ 279: public boolean equals (Object obj) 280: { 281: if (! (obj instanceof NumberFormat)) 282: return false; 283: NumberFormat nf = (NumberFormat) obj; 284: return (groupingUsed == nf.groupingUsed 285: && maximumFractionDigits == nf.maximumFractionDigits 286: && maximumIntegerDigits == nf.maximumIntegerDigits 287: && minimumFractionDigits == nf.minimumFractionDigits 288: && minimumIntegerDigits == nf.minimumIntegerDigits 289: && parseIntegerOnly == nf.parseIntegerOnly); 290: } 291: 292: /** 293: * This method returns a list of locales for which concrete instances 294: * of <code>NumberFormat</code> subclasses may be created. 295: * 296: * @return The list of available locales. 297: */ 298: public static Locale[] getAvailableLocales () 299: { 300: Locale[] list = new Locale[1]; 301: list[0] = Locale.US; 302: return list; 303: } 304: 305: private static NumberFormat computeInstance(Locale loc, String resource, 306: String def) 307: { 308: ResourceBundle res; 309: try 310: { 311: res = ResourceBundle.getBundle("gnu.java.locale.LocaleInformation", 312: loc, ClassLoader.getSystemClassLoader()); 313: } 314: catch (MissingResourceException x) 315: { 316: res = null; 317: } 318: String fmt; 319: try 320: { 321: fmt = res == null ? def : res.getString(resource); 322: } 323: catch (MissingResourceException x) 324: { 325: fmt = def; 326: } 327: DecimalFormatSymbols dfs = new DecimalFormatSymbols (loc); 328: return new DecimalFormat (fmt, dfs); 329: } 330: 331: /** 332: * This method returns an instance of <code>NumberFormat</code> suitable 333: * for formatting and parsing currency values in the default locale. 334: * 335: * @return An instance of <code>NumberFormat</code> for handling currencies. 336: */ 337: public static final NumberFormat getCurrencyInstance () 338: { 339: return getCurrencyInstance (Locale.getDefault()); 340: } 341: 342: /** 343: * This method returns an instance of <code>NumberFormat</code> suitable 344: * for formatting and parsing currency values in the specified locale. 345: * 346: * @return An instance of <code>NumberFormat</code> for handling currencies. 347: */ 348: public static NumberFormat getCurrencyInstance (Locale loc) 349: { 350: NumberFormat format; 351: 352: format = computeInstance (loc, "currencyFormat", "$#,##0.00;($#,##0.00)"); 353: format.setMaximumFractionDigits(format.getCurrency().getDefaultFractionDigits()); 354: return format; 355: } 356: 357: /** 358: * This method returns a default instance for the default locale. This 359: * will be a concrete subclass of <code>NumberFormat</code>, but the 360: * actual class returned is dependent on the locale. 361: * 362: * @return An instance of the default <code>NumberFormat</code> class. 363: */ 364: public static final NumberFormat getInstance () 365: { 366: return getInstance (Locale.getDefault()); 367: } 368: 369: /** 370: * This method returns a default instance for the specified locale. This 371: * will be a concrete subclass of <code>NumberFormat</code>, but the 372: * actual class returned is dependent on the locale. 373: * 374: * @param locale The desired locale. 375: * 376: * @return An instance of the default <code>NumberFormat</code> class. 377: */ 378: public static NumberFormat getInstance (Locale loc) 379: { 380: // For now always return a number instance. 381: return getNumberInstance (loc); 382: } 383: 384: /** 385: * This method returns the maximum number of digits allowed in the fraction 386: * portion of a number. 387: * 388: * @return The maximum number of digits allowed in the fraction 389: * portion of a number. 390: */ 391: public int getMaximumFractionDigits () 392: { 393: return maximumFractionDigits; 394: } 395: 396: /** 397: * This method returns the maximum number of digits allowed in the integer 398: * portion of a number. 399: * 400: * @return The maximum number of digits allowed in the integer 401: * portion of a number. 402: */ 403: public int getMaximumIntegerDigits () 404: { 405: return maximumIntegerDigits; 406: } 407: 408: /** 409: * This method returns the minimum number of digits allowed in the fraction 410: * portion of a number. 411: * 412: * @return The minimum number of digits allowed in the fraction 413: * portion of a number. 414: */ 415: public int getMinimumFractionDigits () 416: { 417: return minimumFractionDigits; 418: } 419: 420: /** 421: * This method returns the minimum number of digits allowed in the integer 422: * portion of a number. 423: * 424: * @return The minimum number of digits allowed in the integer 425: * portion of a number. 426: */ 427: public int getMinimumIntegerDigits () 428: { 429: return minimumIntegerDigits; 430: } 431: 432: /** 433: * This method returns a default instance for the specified locale. This 434: * will be a concrete subclass of <code>NumberFormat</code>, but the 435: * actual class returned is dependent on the locale. 436: * 437: * @param locale The desired locale. 438: * 439: * @return An instance of the default <code>NumberFormat</code> class. 440: */ 441: public static final NumberFormat getNumberInstance () 442: { 443: return getNumberInstance (Locale.getDefault()); 444: } 445: 446: /** 447: * This method returns a general purpose number formatting and parsing 448: * class for the default locale. This will be a concrete subclass of 449: * <code>NumberFormat</code>, but the actual class returned is dependent 450: * on the locale. 451: * 452: * @return An instance of a generic number formatter for the default locale. 453: */ 454: public static NumberFormat getNumberInstance (Locale loc) 455: { 456: return computeInstance (loc, "numberFormat", "#,##0.###"); 457: } 458: 459: /** 460: * This method returns an integer formatting and parsing class for the 461: * default locale. This will be a concrete subclass of <code>NumberFormat</code>, 462: * but the actual class returned is dependent on the locale. 463: * 464: * @return An instance of an integer number formatter for the default locale. 465: * @since 1.4 466: */ 467: public static final NumberFormat getIntegerInstance() 468: { 469: return getIntegerInstance (Locale.getDefault()); 470: } 471: 472: /** 473: * This method returns an integer formatting and parsing class for the 474: * default locale. This will be a concrete subclass of <code>NumberFormat</code>, 475: * but the actual class returned is dependent on the locale. 476: * 477: * @param locale the desired locale. 478: * 479: * @return An instance of an integer number formatter for the desired locale. 480: * @since 1.4 481: */ 482: public static NumberFormat getIntegerInstance(Locale locale) 483: { 484: NumberFormat format = computeInstance (locale, "numberFormat", "#,##0"); 485: format.setMaximumFractionDigits(0); 486: format.setParseIntegerOnly (true); 487: return format; 488: } 489: 490: /** 491: * This method returns an instance of <code>NumberFormat</code> suitable 492: * for formatting and parsing percentage values in the default locale. 493: * 494: * @return An instance of <code>NumberFormat</code> for handling percentages. 495: */ 496: public static final NumberFormat getPercentInstance () 497: { 498: return getPercentInstance (Locale.getDefault()); 499: } 500: 501: /** 502: * This method returns an instance of <code>NumberFormat</code> suitable 503: * for formatting and parsing percentage values in the specified locale. 504: * 505: * @param locale The desired locale. 506: * 507: * @return An instance of <code>NumberFormat</code> for handling percentages. 508: */ 509: public static NumberFormat getPercentInstance (Locale loc) 510: { 511: return computeInstance (loc, "percentFormat", "#,##0%"); 512: } 513: 514: /** 515: * This method returns a hash value for this object. 516: * 517: * @return The hash code. 518: */ 519: public int hashCode () 520: { 521: int hash = super.hashCode(); 522: hash ^= (maximumFractionDigits + maximumIntegerDigits 523: + minimumFractionDigits + minimumIntegerDigits); 524: if (groupingUsed) 525: hash ^= 0xf0f0; 526: if (parseIntegerOnly) 527: hash ^= 0x0f0f; 528: return hash; 529: } 530: 531: /** 532: * This method tests whether or not grouping is in use. Grouping is 533: * a method of marking separations in numbers, such as thousand separators 534: * in the US English locale. The grouping positions and symbols are all 535: * locale specific. As an example, with grouping disabled, the number one 536: * million would appear as "1000000". With grouping enabled, this number 537: * might appear as "1,000,000". (Both of these assume the US English 538: * locale). 539: * 540: * @return <code>true</code> if grouping is enabled, 541: * <code>false</code> otherwise. 542: */ 543: public boolean isGroupingUsed () 544: { 545: return groupingUsed; 546: } 547: 548: /** 549: * This method tests whether or not only integer values should be parsed. 550: * If this class is parsing only integers, parsing stops at the decimal 551: * point. 552: * 553: * @return <code>true</code> if only integers are parsed, 554: * <code>false</code> otherwise. 555: */ 556: public boolean isParseIntegerOnly () 557: { 558: return parseIntegerOnly; 559: } 560: 561: /** 562: * This is a default constructor for use by subclasses. 563: */ 564: public NumberFormat () 565: { 566: } 567: 568: /** 569: * This method parses the specified string into a <code>Number</code>. This 570: * will be a <code>Long</code> if possible, otherwise it will be a 571: * <code>Double</code>. If no number can be parsed, no exception is 572: * thrown. Instead, the parse position remains at its initial index. 573: * 574: * @param str The string to parse. 575: * @param pp The desired <code>ParsePosition</code>. 576: * 577: * @return The parsed <code>Number</code> 578: */ 579: public abstract Number parse (String sourceStr, ParsePosition pos); 580: 581: /** 582: * This method parses the specified string into a <code>Number</code>. This 583: * will be a <code>Long</code> if possible, otherwise it will be a 584: * <code>Double</code>. If no number can be parsed, an exception will be 585: * thrown. 586: * 587: * @param str The string to parse. 588: * 589: * @return The parsed <code>Number</code> 590: * 591: * @exception ParseException If no number can be parsed. 592: */ 593: public Number parse (String sourceStr) throws ParseException 594: { 595: ParsePosition pp = new ParsePosition (0); 596: Number r = parse (sourceStr, pp); 597: if (r == null) 598: { 599: int index = pp.getErrorIndex(); 600: if (index < 0) 601: index = pp.getIndex(); 602: throw new ParseException ("couldn't parse number", index); 603: } 604: return r; 605: } 606: 607: /** 608: * This method parses the specified string into an <code>Object</code>. This 609: * will be a <code>Long</code> if possible, otherwise it will be a 610: * <code>Double</code>. If no number can be parsed, no exception is 611: * thrown. Instead, the parse position remains at its initial index. 612: * 613: * @param str The string to parse. 614: * @param pp The desired <code>ParsePosition</code>. 615: * 616: * @return The parsed <code>Object</code> 617: */ 618: public final Object parseObject (String sourceStr, ParsePosition pos) 619: { 620: return parse (sourceStr, pos); 621: } 622: 623: /** 624: * This method sets the grouping behavior of this formatter. Grouping is 625: * a method of marking separations in numbers, such as thousand separators 626: * in the US English locale. The grouping positions and symbols are all 627: * locale specific. As an example, with grouping disabled, the number one 628: * million would appear as "1000000". With grouping enabled, this number 629: * might appear as "1,000,000". (Both of these assume the US English 630: * locale). 631: * 632: * @param groupingUsed <code>true</code> to enable grouping, 633: * <code>false</code> to disable it. 634: */ 635: public void setGroupingUsed (boolean newValue) 636: { 637: groupingUsed = newValue; 638: } 639: 640: /** 641: * This method sets the maximum number of digits allowed in the fraction 642: * portion of a number to the specified value. If this is less than the 643: * current minimum allowed digits, the minimum allowed digits value will 644: * be lowered to be equal to the new maximum allowed digits value. 645: * 646: * @param maximumFractionDigits The new maximum fraction digits value. 647: */ 648: public void setMaximumFractionDigits (int newValue) 649: { 650: maximumFractionDigits = newValue; 651: if (getMinimumFractionDigits () > maximumFractionDigits) 652: setMinimumFractionDigits (maximumFractionDigits); 653: } 654: 655: /** 656: * This method sets the maximum number of digits allowed in the integer 657: * portion of a number to the specified value. If this is less than the 658: * current minimum allowed digits, the minimum allowed digits value will 659: * be lowered to be equal to the new maximum allowed digits value. 660: * 661: * @param maximumIntegerDigits The new maximum integer digits value. 662: */ 663: public void setMaximumIntegerDigits (int newValue) 664: { 665: maximumIntegerDigits = newValue; 666: if (getMinimumIntegerDigits () > maximumIntegerDigits) 667: setMinimumIntegerDigits (maximumIntegerDigits); 668: } 669: 670: /** 671: * This method sets the minimum number of digits allowed in the fraction 672: * portion of a number to the specified value. If this is greater than the 673: * current maximum allowed digits, the maximum allowed digits value will 674: * be raised to be equal to the new minimum allowed digits value. 675: * 676: * @param minimumFractionDigits The new minimum fraction digits value. 677: */ 678: public void setMinimumFractionDigits (int newValue) 679: { 680: minimumFractionDigits = newValue; 681: if (getMaximumFractionDigits () < minimumFractionDigits) 682: setMaximumFractionDigits (minimumFractionDigits); 683: } 684: 685: /** 686: * This method sets the minimum number of digits allowed in the integer 687: * portion of a number to the specified value. If this is greater than the 688: * current maximum allowed digits, the maximum allowed digits value will 689: * be raised to be equal to the new minimum allowed digits value. 690: * 691: * @param minimumIntegerDigits The new minimum integer digits value. 692: */ 693: public void setMinimumIntegerDigits (int newValue) 694: { 695: minimumIntegerDigits = newValue; 696: if (getMaximumIntegerDigits () < minimumIntegerDigits) 697: setMaximumIntegerDigits (minimumIntegerDigits); 698: } 699: 700: /** 701: * This method sets the parsing behavior of this object to parse only 702: * integers or not. 703: * 704: * @param parseIntegerOnly <code>true</code> to parse only integers, 705: * <code>false</code> otherwise. 706: */ 707: public void setParseIntegerOnly (boolean value) 708: { 709: parseIntegerOnly = value; 710: } 711: 712: /** 713: * This method is a specialization of the format method that performs 714: * a simple formatting of the specified <code>double</code> number. 715: * 716: * @param number The <code>double</code> to format. 717: * 718: * @return The formatted number 719: */ 720: public final String format (double number) 721: { 722: StringBuffer sbuf = new StringBuffer(50); 723: format (number, sbuf, null); 724: return sbuf.toString(); 725: } 726: 727: // These field names are fixed by the serialization spec. 728: boolean groupingUsed; 729: int maximumFractionDigits; 730: private byte maxFractionDigits; 731: int maximumIntegerDigits; 732: private byte maxIntegerDigits; 733: int minimumFractionDigits; 734: private byte minFractionDigits; 735: int minimumIntegerDigits; 736: private byte minIntegerDigits; 737: boolean parseIntegerOnly; 738: private int serialVersionOnStream; 739: private static final long serialVersionUID = -2308460125733713944L; 740: 741: private void readObject(ObjectInputStream stream) 742: throws IOException, ClassNotFoundException 743: { 744: stream.defaultReadObject(); 745: if (serialVersionOnStream < 1) 746: { 747: maximumFractionDigits = maxFractionDigits; 748: maximumIntegerDigits = maxIntegerDigits; 749: minimumFractionDigits = minFractionDigits; 750: minimumIntegerDigits = minIntegerDigits; 751: serialVersionOnStream = 1; 752: } 753: } 754: 755: private void writeObject(ObjectOutputStream stream) throws IOException 756: { 757: maxFractionDigits = maximumFractionDigits < Byte.MAX_VALUE ? 758: (byte) maximumFractionDigits : Byte.MAX_VALUE; 759: maxIntegerDigits = maximumIntegerDigits < Byte.MAX_VALUE ? 760: (byte) maximumIntegerDigits : Byte.MAX_VALUE; 761: minFractionDigits = minimumFractionDigits < Byte.MAX_VALUE ? 762: (byte) minimumFractionDigits : Byte.MAX_VALUE; 763: minIntegerDigits = minimumIntegerDigits < Byte.MAX_VALUE ? 764: (byte) minimumIntegerDigits : Byte.MAX_VALUE; 765: serialVersionOnStream = 1; 766: stream.defaultWriteObject(); 767: } 768: 769: /** 770: * Returns the currency used by this number format when formatting currency 771: * values. 772: * 773: * The default implementation throws UnsupportedOperationException. 774: * 775: * @return The used currency object, or null. 776: * 777: * @throws UnsupportedOperationException If the number format class doesn't 778: * implement currency formatting. 779: * 780: * @since 1.4 781: */ 782: public Currency getCurrency() 783: { 784: throw new UnsupportedOperationException(); 785: } 786: 787: /** 788: * Sets the currency used by this number format when formatting currency 789: * values. 790: * 791: * The default implementation throws UnsupportedOperationException. 792: * 793: * @param currency The new currency to be used by this number format. 794: * 795: * @throws NullPointerException If currenc is null. 796: * @throws UnsupportedOperationException If the number format class doesn't 797: * implement currency formatting. 798: * 799: * @since 1.4 800: */ 801: public void setCurrency(Currency currency) 802: { 803: if (currency == null) 804: throw new NullPointerException("currency may not be null"); 805: 806: throw new UnsupportedOperationException(); 807: } 808: }
GNU Classpath (0.17) |