Import GNU Classpath (20121202).
[official-gcc.git] / libjava / classpath / java / text / NumberFormat.java
blob555ee373957bd88d5cdf841e1ccf20c5cd4d17ac
1 /* NumberFormat.java -- Formats and parses numbers
2 Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2007, 2012
3 Free Software Foundation, Inc.
5 This file is part of GNU Classpath.
7 GNU Classpath is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU Classpath is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Classpath; see the file COPYING. If not, write to the
19 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 02110-1301 USA.
22 Linking this library statically or dynamically with other modules is
23 making a combined work based on this library. Thus, the terms and
24 conditions of the GNU General Public License cover the whole
25 combination.
27 As a special exception, the copyright holders of this library give you
28 permission to link this library with independent modules to produce an
29 executable, regardless of the license terms of these independent
30 modules, and to copy and distribute the resulting executable under
31 terms of your choice, provided that you also meet, for each linked
32 independent module, the terms and conditions of the license of that
33 module. An independent module is a module which is not derived from
34 or based on this library. If you modify this library, you may extend
35 this exception to your version of the library, but you are not
36 obligated to do so. If you do not wish to do so, delete this
37 exception statement from your version. */
40 package java.text;
42 import gnu.java.locale.LocaleHelper;
44 import java.io.IOException;
45 import java.io.InvalidObjectException;
46 import java.io.ObjectInputStream;
47 import java.io.ObjectOutputStream;
49 import java.text.spi.NumberFormatProvider;
51 import java.util.Currency;
52 import java.util.Locale;
53 import java.util.MissingResourceException;
54 import java.util.ResourceBundle;
55 import java.util.ServiceLoader;
57 /**
58 * This is the abstract superclass of all classes which format and
59 * parse numeric values such as decimal numbers, integers, currency values,
60 * and percentages. These classes perform their parsing and formatting
61 * in a locale specific manner, accounting for such items as differing
62 * currency symbols and thousands separators.
63 * <p>
64 * To create an instance of a concrete subclass of <code>NumberFormat</code>,
65 * do not call a class constructor directly. Instead, use one of the
66 * static factory methods in this class such as
67 * <code>getCurrencyInstance</code>.
69 * @author Tom Tromey (tromey@cygnus.com)
70 * @author Aaron M. Renn (arenn@urbanophile.com)
71 * @date March 4, 1999
73 /* Written using "Java Class Libraries", 2nd edition, plus online
74 * API docs for JDK 1.2 from http://www.javasoft.com.
75 * Status: Believed complete and correct to 1.2, except getAvailableLocales.
77 public abstract class NumberFormat extends Format implements Cloneable
79 /**
80 * This is a constant used to create a <code>FieldPosition</code> object
81 * that will return the integer portion of a formatted number.
83 public static final int INTEGER_FIELD = 0;
85 /**
86 * This is a constant used to create a <code>FieldPosition</code> object
87 * that will return the fractional portion of a formatted number.
89 public static final int FRACTION_FIELD = 1;
91 public static class Field extends Format.Field
93 static final long serialVersionUID = 7494728892700160890L;
95 /**
96 * Attribute set to all characters containing digits of the integer
97 * part.
99 public static final NumberFormat.Field INTEGER
100 = new Field("integer");
103 * Attribute set to all characters containing digits of the fractional
104 * part.
106 public static final NumberFormat.Field FRACTION
107 = new Field("fraction");
110 * Attribute set to all characters containing digits of the exponential
111 * part.
113 public static final NumberFormat.Field EXPONENT
114 = new Field("exponent");
117 * Attribute set to all characters containing a decimal separator.
119 public static final NumberFormat.Field DECIMAL_SEPARATOR
120 = new Field("decimal separator");
123 * Attribute set to all characters containing a sign (plus or minus).
125 public static final NumberFormat.Field SIGN
126 = new Field("sign");
129 * Attribute set to all characters containing a grouping separator (e.g.
130 * a comma, a white space,...).
132 public static final NumberFormat.Field GROUPING_SEPARATOR
133 = new Field("grouping separator");
136 * Attribute set to all characters containing an exponential symbol (e.g.
137 * 'E')
139 public static final NumberFormat.Field EXPONENT_SYMBOL
140 = new Field("exponent symbol");
143 * Attribute set to all characters containing a percent symbol (e.g. '%')
145 public static final NumberFormat.Field PERCENT
146 = new Field("percent");
149 * Attribute set to all characters containing a permille symbol.
151 public static final NumberFormat.Field PERMILLE
152 = new Field("permille");
155 * Attribute set to all characters containing the currency unit.
157 public static final NumberFormat.Field CURRENCY
158 = new Field("currency");
161 * Attribute set to all characters containing the exponent sign.
163 public static final NumberFormat.Field EXPONENT_SIGN
164 = new Field("exponent sign");
167 * Private fields to register all fields contained in this descriptor.
169 private static final NumberFormat.Field[] allFields =
171 INTEGER, FRACTION, EXPONENT, DECIMAL_SEPARATOR, SIGN,
172 GROUPING_SEPARATOR, EXPONENT_SYMBOL, PERCENT,
173 PERMILLE, CURRENCY, EXPONENT_SIGN
177 * This constructor is only used by the deserializer. Without it,
178 * it would fail to construct a valid object.
180 private Field()
182 super("");
186 * Create a Field instance with the specified field name.
188 * @param field_name Field name for the new Field instance.
190 protected Field(String field_name)
192 super (field_name);
196 * This function is used by the deserializer to know which object
197 * to use when it encounters an encoded NumberFormat.Field in a
198 * serialization stream. If the stream is valid it should return
199 * one of the above field. In the other case we throw an exception.
201 * @return a valid official NumberFormat.Field instance.
203 * @throws InvalidObjectException if the field name is invalid.
205 protected Object readResolve() throws InvalidObjectException
207 String s = getName();
208 for (int i = 0; i < allFields.length; i++)
209 if (s.equals(allFields[i].getName()))
210 return allFields[i];
212 throw new InvalidObjectException("no such NumberFormat field called "
213 + s);
218 * This method is a specialization of the format method that performs
219 * a simple formatting of the specified <code>long</code> number.
221 * @param number The <code>long</code> to format.
223 * @return The formatted number
225 public final String format (long number)
227 StringBuffer sbuf = new StringBuffer(50);
228 format (number, sbuf, new FieldPosition(0));
229 return sbuf.toString();
233 * @specnote this method was final in releases before 1.5
235 public StringBuffer format (Object obj, StringBuffer sbuf,
236 FieldPosition pos)
238 if (obj instanceof Number)
239 return format(((Number) obj).doubleValue(), sbuf, pos);
241 throw new
242 IllegalArgumentException("Cannot format given Object as a Number");
246 * This method formats the specified <code>double</code> and appends it to
247 * a <code>StringBuffer</code>.
249 * @param number The <code>double</code> to format.
250 * @param sbuf The <code>StringBuffer</code> to append the formatted number
251 * to.
252 * @param pos The desired <code>FieldPosition</code>.
254 * @return The <code>StringBuffer</code> with the appended number.
256 public abstract StringBuffer format (double number,
257 StringBuffer sbuf, FieldPosition pos);
260 * This method formats the specified <code>long</code> and appends it to
261 * a <code>StringBuffer</code>.
263 * @param number The <code>long</code> to format.
264 * @param sbuf The <code>StringBuffer</code> to append the formatted number
265 * to.
266 * @param pos The desired <code>FieldPosition</code>.
268 * @return The <code>StringBuffer</code> with the appended number.
270 public abstract StringBuffer format (long number,
271 StringBuffer sbuf, FieldPosition pos);
274 * This method tests the specified object for equality against this object.
275 * This will be <code>true</code> if the following conditions are met:
276 * <p>
277 * <ul>
278 * <li>The specified object is not <code>null</code>.
279 * <li>The specified object is an instance of <code>NumberFormat</code>.
280 * </ul>
281 * <p>
282 * Since this method does not test much, it is highly advised that
283 * concrete subclasses override this method.
285 * @param obj The <code>Object</code> to test against equality with
286 * this object.
288 * @return <code>true</code> if the specified object is equal to
289 * this object, <code>false</code> otherwise.
291 public boolean equals (Object obj)
293 if (! (obj instanceof NumberFormat))
294 return false;
295 NumberFormat nf = (NumberFormat) obj;
296 return (groupingUsed == nf.groupingUsed
297 && maximumFractionDigits == nf.maximumFractionDigits
298 && maximumIntegerDigits == nf.maximumIntegerDigits
299 && minimumFractionDigits == nf.minimumFractionDigits
300 && minimumIntegerDigits == nf.minimumIntegerDigits
301 && parseIntegerOnly == nf.parseIntegerOnly);
305 * This method returns a list of locales for which concrete instances
306 * of <code>NumberFormat</code> subclasses may be created.
308 * @return The list of available locales.
310 public static Locale[] getAvailableLocales ()
312 Locale[] list = new Locale[1];
313 list[0] = Locale.US;
314 return list;
317 private static NumberFormat computeInstance(Locale loc, String resource,
318 String def)
319 throws MissingResourceException
321 if (loc.equals(Locale.ROOT))
322 return new DecimalFormat(def, DecimalFormatSymbols.getInstance(loc));
323 ResourceBundle res =
324 ResourceBundle.getBundle("gnu.java.locale.LocaleInformation",
325 loc, ClassLoader.getSystemClassLoader());
326 String fmt;
329 fmt = res == null ? def : res.getString(resource);
331 catch (MissingResourceException x)
333 fmt = def;
335 DecimalFormatSymbols dfs = DecimalFormatSymbols.getInstance(loc);
336 return new DecimalFormat (fmt, dfs);
340 * This method returns an instance of <code>NumberFormat</code> suitable
341 * for formatting and parsing currency values in the default locale.
343 * @return An instance of <code>NumberFormat</code> for handling currencies.
345 public static final NumberFormat getCurrencyInstance ()
347 return getCurrencyInstance (Locale.getDefault());
351 * This method returns an instance of <code>NumberFormat</code> suitable
352 * for formatting and parsing currency values in the specified locale.
354 * @return An instance of <code>NumberFormat</code> for handling currencies.
356 public static NumberFormat getCurrencyInstance (Locale loc)
360 NumberFormat format;
362 format = computeInstance (loc, "currencyFormat",
363 "\u00A4#,##0.00;(\u00A4#,##0.00)");
364 format.setMaximumFractionDigits(format.getCurrency().getDefaultFractionDigits());
365 return format;
367 catch (MissingResourceException e)
369 for (NumberFormatProvider p :
370 ServiceLoader.load(NumberFormatProvider.class))
372 for (Locale l : p.getAvailableLocales())
374 if (l.equals(loc))
376 NumberFormat nf = p.getCurrencyInstance(loc);
377 if (nf != null)
378 return nf;
379 break;
383 return getCurrencyInstance(LocaleHelper.getFallbackLocale(loc));
388 * This method returns a default instance for the default locale. This
389 * will be a concrete subclass of <code>NumberFormat</code>, but the
390 * actual class returned is dependent on the locale.
392 * @return An instance of the default <code>NumberFormat</code> class.
394 public static final NumberFormat getInstance ()
396 return getInstance (Locale.getDefault());
400 * This method returns a default instance for the specified locale. This
401 * will be a concrete subclass of <code>NumberFormat</code>, but the
402 * actual class returned is dependent on the locale.
404 * @param loc The desired locale.
406 * @return An instance of the default <code>NumberFormat</code> class.
408 public static NumberFormat getInstance (Locale loc)
410 // For now always return a number instance.
411 return getNumberInstance (loc);
415 * This method returns the maximum number of digits allowed in the fraction
416 * portion of a number.
418 * @return The maximum number of digits allowed in the fraction
419 * portion of a number.
421 public int getMaximumFractionDigits ()
423 return maximumFractionDigits;
427 * This method returns the maximum number of digits allowed in the integer
428 * portion of a number.
430 * @return The maximum number of digits allowed in the integer
431 * portion of a number.
433 public int getMaximumIntegerDigits ()
435 return maximumIntegerDigits;
439 * This method returns the minimum number of digits allowed in the fraction
440 * portion of a number.
442 * @return The minimum number of digits allowed in the fraction
443 * portion of a number.
445 public int getMinimumFractionDigits ()
447 return minimumFractionDigits;
451 * This method returns the minimum number of digits allowed in the integer
452 * portion of a number.
454 * @return The minimum number of digits allowed in the integer
455 * portion of a number.
457 public int getMinimumIntegerDigits ()
459 return minimumIntegerDigits;
463 * This method returns a default instance for the specified locale. This
464 * will be a concrete subclass of <code>NumberFormat</code>, but the
465 * actual class returned is dependent on the locale.
467 * @return An instance of the default <code>NumberFormat</code> class.
469 public static final NumberFormat getNumberInstance ()
471 return getNumberInstance (Locale.getDefault());
475 * This method returns a general purpose number formatting and parsing
476 * class for the default locale. This will be a concrete subclass of
477 * <code>NumberFormat</code>, but the actual class returned is dependent
478 * on the locale.
480 * @return An instance of a generic number formatter for the default locale.
482 public static NumberFormat getNumberInstance (Locale loc)
486 return computeInstance (loc, "numberFormat", "#,##0.###");
488 catch (MissingResourceException e)
490 for (NumberFormatProvider p :
491 ServiceLoader.load(NumberFormatProvider.class))
493 for (Locale l : p.getAvailableLocales())
495 if (l.equals(loc))
497 NumberFormat nf = p.getNumberInstance(loc);
498 if (nf != null)
499 return nf;
500 break;
504 return getNumberInstance(LocaleHelper.getFallbackLocale(loc));
509 * This method returns an integer formatting and parsing class for the
510 * default locale. This will be a concrete subclass of <code>NumberFormat</code>,
511 * but the actual class returned is dependent on the locale.
513 * @return An instance of an integer number formatter for the default locale.
514 * @since 1.4
516 public static final NumberFormat getIntegerInstance()
518 return getIntegerInstance (Locale.getDefault());
522 * This method returns an integer formatting and parsing class for the
523 * default locale. This will be a concrete subclass of <code>NumberFormat</code>,
524 * but the actual class returned is dependent on the locale.
526 * @param locale the desired locale.
528 * @return An instance of an integer number formatter for the desired locale.
529 * @since 1.4
531 public static NumberFormat getIntegerInstance(Locale locale)
535 NumberFormat format = computeInstance (locale,
536 "integerFormat", "#,##0");
537 format.setMaximumFractionDigits(0);
538 format.setParseIntegerOnly (true);
539 return format;
541 catch (MissingResourceException e)
543 for (NumberFormatProvider p :
544 ServiceLoader.load(NumberFormatProvider.class))
546 for (Locale l : p.getAvailableLocales())
548 if (l.equals(locale))
550 NumberFormat nf = p.getIntegerInstance(locale);
551 if (nf != null)
552 return nf;
553 break;
557 return getIntegerInstance(LocaleHelper.getFallbackLocale(locale));
562 * This method returns an instance of <code>NumberFormat</code> suitable
563 * for formatting and parsing percentage values in the default locale.
565 * @return An instance of <code>NumberFormat</code> for handling percentages.
567 public static final NumberFormat getPercentInstance ()
569 return getPercentInstance (Locale.getDefault());
573 * This method returns an instance of <code>NumberFormat</code> suitable
574 * for formatting and parsing percentage values in the specified locale.
576 * @param loc The desired locale.
578 * @return An instance of <code>NumberFormat</code> for handling percentages.
580 public static NumberFormat getPercentInstance (Locale loc)
584 return computeInstance (loc, "percentFormat", "#,##0%");
586 catch (MissingResourceException e)
588 for (NumberFormatProvider p :
589 ServiceLoader.load(NumberFormatProvider.class))
591 for (Locale l : p.getAvailableLocales())
593 if (l.equals(loc))
595 NumberFormat nf = p.getPercentInstance(loc);
596 if (nf != null)
597 return nf;
598 break;
602 return getPercentInstance(LocaleHelper.getFallbackLocale(loc));
607 * This method returns a hash value for this object.
609 * @return The hash code.
611 public int hashCode ()
613 int hash = super.hashCode();
614 hash ^= (maximumFractionDigits + maximumIntegerDigits
615 + minimumFractionDigits + minimumIntegerDigits);
616 if (groupingUsed)
617 hash ^= 0xf0f0;
618 if (parseIntegerOnly)
619 hash ^= 0x0f0f;
620 return hash;
624 * This method tests whether or not grouping is in use. 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).
632 * @return <code>true</code> if grouping is enabled,
633 * <code>false</code> otherwise.
635 public boolean isGroupingUsed ()
637 return groupingUsed;
641 * This method tests whether or not only integer values should be parsed.
642 * If this class is parsing only integers, parsing stops at the decimal
643 * point.
645 * @return <code>true</code> if only integers are parsed,
646 * <code>false</code> otherwise.
648 public boolean isParseIntegerOnly ()
650 return parseIntegerOnly;
654 * This is a default constructor for use by subclasses.
656 protected NumberFormat ()
661 * This method parses the specified string into a <code>Number</code>. This
662 * will be a <code>Long</code> if possible, otherwise it will be a
663 * <code>Double</code>. If no number can be parsed, no exception is
664 * thrown. Instead, the parse position remains at its initial index.
666 * @param sourceStr The string to parse.
667 * @param pos The desired <code>ParsePosition</code>.
669 * @return The parsed <code>Number</code>
671 public abstract Number parse (String sourceStr, ParsePosition pos);
674 * This method parses the specified string into a <code>Number</code>. This
675 * will be a <code>Long</code> if possible, otherwise it will be a
676 * <code>Double</code>. If no number can be parsed, an exception will be
677 * thrown.
679 * @param sourceStr The string to parse.
681 * @return The parsed <code>Number</code>
683 * @exception ParseException If no number can be parsed.
685 public Number parse (String sourceStr) throws ParseException
687 ParsePosition pp = new ParsePosition (0);
688 Number r = parse (sourceStr, pp);
689 if (r == null)
691 int index = pp.getErrorIndex();
692 if (index < 0)
693 index = pp.getIndex();
694 throw new ParseException ("couldn't parse number", index);
696 return r;
700 * This method parses the specified string into an <code>Object</code>. This
701 * will be a <code>Long</code> if possible, otherwise it will be a
702 * <code>Double</code>. If no number can be parsed, no exception is
703 * thrown. Instead, the parse position remains at its initial index.
705 * @param sourceStr The string to parse.
706 * @param pos The desired <code>ParsePosition</code>.
708 * @return The parsed <code>Object</code>
710 public final Object parseObject (String sourceStr, ParsePosition pos)
712 return parse (sourceStr, pos);
716 * This method sets the grouping behavior of this formatter. Grouping is
717 * a method of marking separations in numbers, such as thousand separators
718 * in the US English locale. The grouping positions and symbols are all
719 * locale specific. As an example, with grouping disabled, the number one
720 * million would appear as "1000000". With grouping enabled, this number
721 * might appear as "1,000,000". (Both of these assume the US English
722 * locale).
724 * @param newValue <code>true</code> to enable grouping,
725 * <code>false</code> to disable it.
727 public void setGroupingUsed (boolean newValue)
729 groupingUsed = newValue;
733 * This method sets the maximum number of digits allowed in the fraction
734 * portion of a number to the specified value. If this is less than the
735 * current minimum allowed digits, the minimum allowed digits value will
736 * be lowered to be equal to the new maximum allowed digits value.
738 * @param digits The new maximum fraction digits value.
740 public void setMaximumFractionDigits (int digits)
742 maximumFractionDigits = digits;
743 if (getMinimumFractionDigits () > maximumFractionDigits)
744 setMinimumFractionDigits (maximumFractionDigits);
748 * This method sets the maximum number of digits allowed in the integer
749 * portion of a number to the specified value. If this is less than the
750 * current minimum allowed digits, the minimum allowed digits value will
751 * be lowered to be equal to the new maximum allowed digits value.
753 * @param digits The new maximum integer digits value.
755 public void setMaximumIntegerDigits (int digits)
757 maximumIntegerDigits = digits;
758 if (getMinimumIntegerDigits () > maximumIntegerDigits)
759 setMinimumIntegerDigits (maximumIntegerDigits);
763 * This method sets the minimum number of digits allowed in the fraction
764 * portion of a number to the specified value. If this is greater than the
765 * current maximum allowed digits, the maximum allowed digits value will
766 * be raised to be equal to the new minimum allowed digits value.
768 * @param digits The new minimum fraction digits value.
770 public void setMinimumFractionDigits (int digits)
772 minimumFractionDigits = digits;
773 if (getMaximumFractionDigits () < minimumFractionDigits)
774 setMaximumFractionDigits (minimumFractionDigits);
778 * This method sets the minimum number of digits allowed in the integer
779 * portion of a number to the specified value. If this is greater than the
780 * current maximum allowed digits, the maximum allowed digits value will
781 * be raised to be equal to the new minimum allowed digits value.
783 * @param digits The new minimum integer digits value.
785 public void setMinimumIntegerDigits (int digits)
787 minimumIntegerDigits = digits;
788 if (getMaximumIntegerDigits () < minimumIntegerDigits)
789 setMaximumIntegerDigits (minimumIntegerDigits);
793 * This method sets the parsing behavior of this object to parse only
794 * integers or not.
796 * @param value <code>true</code> to parse only integers,
797 * <code>false</code> otherwise.
799 public void setParseIntegerOnly (boolean value)
801 parseIntegerOnly = value;
805 * This method is a specialization of the format method that performs
806 * a simple formatting of the specified <code>double</code> number.
808 * @param number The <code>double</code> to format.
810 * @return The formatted number
812 public final String format (double number)
814 StringBuffer sbuf = new StringBuffer(50);
815 FieldPosition position = new FieldPosition(0);
817 format (number, sbuf, position);
818 return sbuf.toString();
821 // These field names are fixed by the serialization spec.
822 boolean groupingUsed;
823 int maximumFractionDigits;
824 private byte maxFractionDigits;
825 int maximumIntegerDigits;
826 private byte maxIntegerDigits;
827 int minimumFractionDigits;
828 private byte minFractionDigits;
829 int minimumIntegerDigits;
830 private byte minIntegerDigits;
831 boolean parseIntegerOnly;
832 private int serialVersionOnStream;
833 private static final long serialVersionUID = -2308460125733713944L;
835 private void readObject(ObjectInputStream stream)
836 throws IOException, ClassNotFoundException
838 stream.defaultReadObject();
839 if (serialVersionOnStream < 1)
841 maximumFractionDigits = maxFractionDigits;
842 maximumIntegerDigits = maxIntegerDigits;
843 minimumFractionDigits = minFractionDigits;
844 minimumIntegerDigits = minIntegerDigits;
845 serialVersionOnStream = 1;
849 private void writeObject(ObjectOutputStream stream) throws IOException
851 maxFractionDigits = maximumFractionDigits < Byte.MAX_VALUE ?
852 (byte) maximumFractionDigits : Byte.MAX_VALUE;
853 maxIntegerDigits = maximumIntegerDigits < Byte.MAX_VALUE ?
854 (byte) maximumIntegerDigits : Byte.MAX_VALUE;
855 minFractionDigits = minimumFractionDigits < Byte.MAX_VALUE ?
856 (byte) minimumFractionDigits : Byte.MAX_VALUE;
857 minIntegerDigits = minimumIntegerDigits < Byte.MAX_VALUE ?
858 (byte) minimumIntegerDigits : Byte.MAX_VALUE;
859 serialVersionOnStream = 1;
860 stream.defaultWriteObject();
864 * Returns the currency used by this number format when formatting currency
865 * values.
867 * The default implementation throws UnsupportedOperationException.
869 * @return The used currency object, or null.
871 * @throws UnsupportedOperationException If the number format class doesn't
872 * implement currency formatting.
874 * @since 1.4
876 public Currency getCurrency()
878 throw new UnsupportedOperationException();
882 * Sets the currency used by this number format when formatting currency
883 * values.
885 * The default implementation throws UnsupportedOperationException.
887 * @param currency The new currency to be used by this number format.
889 * @throws NullPointerException If currenc is null.
890 * @throws UnsupportedOperationException If the number format class doesn't
891 * implement currency formatting.
893 * @since 1.4
895 public void setCurrency(Currency currency)
897 if (currency == null)
898 throw new NullPointerException("currency may not be null");
900 throw new UnsupportedOperationException();