src/java.base/share/classes/java/text/DecimalFormat.java
changeset 58242 94bb65cb37d3
parent 57956 e0b8b019d2f5
child 58603 2312d1a04c49
equal deleted inserted replaced
58241:33de7752835c 58242:94bb65cb37d3
   423      * on NumberFormat such as getNumberInstance. These factories will
   423      * on NumberFormat such as getNumberInstance. These factories will
   424      * return the most appropriate sub-class of NumberFormat for a given
   424      * return the most appropriate sub-class of NumberFormat for a given
   425      * locale.
   425      * locale.
   426      *
   426      *
   427      * @param pattern a non-localized pattern string.
   427      * @param pattern a non-localized pattern string.
   428      * @exception NullPointerException if {@code pattern} is null
   428      * @throws    NullPointerException if {@code pattern} is null
   429      * @exception IllegalArgumentException if the given pattern is invalid.
   429      * @throws    IllegalArgumentException if the given pattern is invalid.
   430      * @see java.text.NumberFormat#getInstance
   430      * @see java.text.NumberFormat#getInstance
   431      * @see java.text.NumberFormat#getNumberInstance
   431      * @see java.text.NumberFormat#getNumberInstance
   432      * @see java.text.NumberFormat#getCurrencyInstance
   432      * @see java.text.NumberFormat#getCurrencyInstance
   433      * @see java.text.NumberFormat#getPercentInstance
   433      * @see java.text.NumberFormat#getPercentInstance
   434      */
   434      */
   450      * to a standard format, you can modify the format returned by
   450      * to a standard format, you can modify the format returned by
   451      * a NumberFormat factory method.
   451      * a NumberFormat factory method.
   452      *
   452      *
   453      * @param pattern a non-localized pattern string
   453      * @param pattern a non-localized pattern string
   454      * @param symbols the set of symbols to be used
   454      * @param symbols the set of symbols to be used
   455      * @exception NullPointerException if any of the given arguments is null
   455      * @throws    NullPointerException if any of the given arguments is null
   456      * @exception IllegalArgumentException if the given pattern is invalid
   456      * @throws    IllegalArgumentException if the given pattern is invalid
   457      * @see java.text.NumberFormat#getInstance
   457      * @see java.text.NumberFormat#getInstance
   458      * @see java.text.NumberFormat#getNumberInstance
   458      * @see java.text.NumberFormat#getNumberInstance
   459      * @see java.text.NumberFormat#getCurrencyInstance
   459      * @see java.text.NumberFormat#getCurrencyInstance
   460      * @see java.text.NumberFormat#getPercentInstance
   460      * @see java.text.NumberFormat#getPercentInstance
   461      * @see java.text.DecimalFormatSymbols
   461      * @see java.text.DecimalFormatSymbols
   484      *                   {@link NumberFormat#INTEGER_FIELD}, the begin index
   484      *                   {@link NumberFormat#INTEGER_FIELD}, the begin index
   485      *                   and end index of {@code fieldPosition} will be set
   485      *                   and end index of {@code fieldPosition} will be set
   486      *                   to 0 and 9, respectively for the output string
   486      *                   to 0 and 9, respectively for the output string
   487      *                   {@code 1,234,567.89}.
   487      *                   {@code 1,234,567.89}.
   488      * @return           the value passed in as {@code toAppendTo}
   488      * @return           the value passed in as {@code toAppendTo}
   489      * @exception        IllegalArgumentException if {@code number} is
   489      * @throws           IllegalArgumentException if {@code number} is
   490      *                   null or not an instance of {@code Number}.
   490      *                   null or not an instance of {@code Number}.
   491      * @exception        NullPointerException if {@code toAppendTo} or
   491      * @throws           NullPointerException if {@code toAppendTo} or
   492      *                   {@code pos} is null
   492      *                   {@code pos} is null
   493      * @exception        ArithmeticException if rounding is needed with rounding
   493      * @throws           ArithmeticException if rounding is needed with rounding
   494      *                   mode being set to RoundingMode.UNNECESSARY
   494      *                   mode being set to RoundingMode.UNNECESSARY
   495      * @see              java.text.FieldPosition
   495      * @see              java.text.FieldPosition
   496      */
   496      */
   497     @Override
   497     @Override
   498     public final StringBuffer format(Object number,
   498     public final StringBuffer format(Object number,
   526      *                         locale, if the given {@code fieldPosition} is
   526      *                         locale, if the given {@code fieldPosition} is
   527      *                         {@link NumberFormat#INTEGER_FIELD}, the begin index
   527      *                         {@link NumberFormat#INTEGER_FIELD}, the begin index
   528      *                         and end index of {@code fieldPosition} will be set
   528      *                         and end index of {@code fieldPosition} will be set
   529      *                         to 0 and 9, respectively for the output string
   529      *                         to 0 and 9, respectively for the output string
   530      *                         {@code 1,234,567.89}.
   530      *                         {@code 1,234,567.89}.
   531      * @exception NullPointerException if {@code result} or
   531      * @throws    NullPointerException if {@code result} or
   532      *            {@code fieldPosition} is {@code null}
   532      *            {@code fieldPosition} is {@code null}
   533      * @exception ArithmeticException if rounding is needed with rounding
   533      * @throws    ArithmeticException if rounding is needed with rounding
   534      *            mode being set to RoundingMode.UNNECESSARY
   534      *            mode being set to RoundingMode.UNNECESSARY
   535      * @return The formatted number string
   535      * @return The formatted number string
   536      * @see java.text.FieldPosition
   536      * @see java.text.FieldPosition
   537      */
   537      */
   538     @Override
   538     @Override
   563     /**
   563     /**
   564      * Formats a double to produce a string.
   564      * Formats a double to produce a string.
   565      * @param number    The double to format
   565      * @param number    The double to format
   566      * @param result    where the text is to be appended
   566      * @param result    where the text is to be appended
   567      * @param delegate notified of locations of sub fields
   567      * @param delegate notified of locations of sub fields
   568      * @exception       ArithmeticException if rounding is needed with rounding
   568      * @throws          ArithmeticException if rounding is needed with rounding
   569      *                  mode being set to RoundingMode.UNNECESSARY
   569      *                  mode being set to RoundingMode.UNNECESSARY
   570      * @return The formatted number string
   570      * @return The formatted number string
   571      */
   571      */
   572     StringBuffer format(double number, StringBuffer result,
   572     StringBuffer format(double number, StringBuffer result,
   573                                 FieldDelegate delegate) {
   573                                 FieldDelegate delegate) {
   696      *                         locale, if the given {@code fieldPosition} is
   696      *                         locale, if the given {@code fieldPosition} is
   697      *                         {@link NumberFormat#INTEGER_FIELD}, the begin index
   697      *                         {@link NumberFormat#INTEGER_FIELD}, the begin index
   698      *                         and end index of {@code fieldPosition} will be set
   698      *                         and end index of {@code fieldPosition} will be set
   699      *                         to 0 and 11, respectively for the output string
   699      *                         to 0 and 11, respectively for the output string
   700      *                         {@code 123,456,789}.
   700      *                         {@code 123,456,789}.
   701      * @exception       NullPointerException if {@code result} or
   701      * @throws          NullPointerException if {@code result} or
   702      *                  {@code fieldPosition} is {@code null}
   702      *                  {@code fieldPosition} is {@code null}
   703      * @exception       ArithmeticException if rounding is needed with rounding
   703      * @throws          ArithmeticException if rounding is needed with rounding
   704      *                  mode being set to RoundingMode.UNNECESSARY
   704      *                  mode being set to RoundingMode.UNNECESSARY
   705      * @return The formatted number string
   705      * @return The formatted number string
   706      * @see java.text.FieldPosition
   706      * @see java.text.FieldPosition
   707      */
   707      */
   708     @Override
   708     @Override
   718      * Format a long to produce a string.
   718      * Format a long to produce a string.
   719      * @param number    The long to format
   719      * @param number    The long to format
   720      * @param result    where the text is to be appended
   720      * @param result    where the text is to be appended
   721      * @param delegate notified of locations of sub fields
   721      * @param delegate notified of locations of sub fields
   722      * @return The formatted number string
   722      * @return The formatted number string
   723      * @exception        ArithmeticException if rounding is needed with rounding
   723      * @throws           ArithmeticException if rounding is needed with rounding
   724      *                   mode being set to RoundingMode.UNNECESSARY
   724      *                   mode being set to RoundingMode.UNNECESSARY
   725      * @see java.text.FieldPosition
   725      * @see java.text.FieldPosition
   726      */
   726      */
   727     StringBuffer format(long number, StringBuffer result,
   727     StringBuffer format(long number, StringBuffer result,
   728                                FieldDelegate delegate) {
   728                                FieldDelegate delegate) {
   793      *                         {@link NumberFormat#INTEGER_FIELD}, the begin index
   793      *                         {@link NumberFormat#INTEGER_FIELD}, the begin index
   794      *                         and end index of {@code fieldPosition} will be set
   794      *                         and end index of {@code fieldPosition} will be set
   795      *                         to 0 and 9, respectively for the output string
   795      *                         to 0 and 9, respectively for the output string
   796      *                         {@code 1,234,567.89}.
   796      *                         {@code 1,234,567.89}.
   797      * @return The formatted number string
   797      * @return The formatted number string
   798      * @exception        ArithmeticException if rounding is needed with rounding
   798      * @throws           ArithmeticException if rounding is needed with rounding
   799      *                   mode being set to RoundingMode.UNNECESSARY
   799      *                   mode being set to RoundingMode.UNNECESSARY
   800      * @see java.text.FieldPosition
   800      * @see java.text.FieldPosition
   801      */
   801      */
   802     private StringBuffer format(BigDecimal number, StringBuffer result,
   802     private StringBuffer format(BigDecimal number, StringBuffer result,
   803                                 FieldPosition fieldPosition) {
   803                                 FieldPosition fieldPosition) {
   809     /**
   809     /**
   810      * Formats a BigDecimal to produce a string.
   810      * Formats a BigDecimal to produce a string.
   811      * @param number    The BigDecimal to format
   811      * @param number    The BigDecimal to format
   812      * @param result    where the text is to be appended
   812      * @param result    where the text is to be appended
   813      * @param delegate notified of locations of sub fields
   813      * @param delegate notified of locations of sub fields
   814      * @exception        ArithmeticException if rounding is needed with rounding
   814      * @throws           ArithmeticException if rounding is needed with rounding
   815      *                   mode being set to RoundingMode.UNNECESSARY
   815      *                   mode being set to RoundingMode.UNNECESSARY
   816      * @return The formatted number string
   816      * @return The formatted number string
   817      */
   817      */
   818     StringBuffer format(BigDecimal number, StringBuffer result,
   818     StringBuffer format(BigDecimal number, StringBuffer result,
   819                                 FieldDelegate delegate) {
   819                                 FieldDelegate delegate) {
   852      *                         {@link NumberFormat#INTEGER_FIELD}, the begin index
   852      *                         {@link NumberFormat#INTEGER_FIELD}, the begin index
   853      *                         and end index of {@code fieldPosition} will be set
   853      *                         and end index of {@code fieldPosition} will be set
   854      *                         to 0 and 11, respectively for the output string
   854      *                         to 0 and 11, respectively for the output string
   855      *                         {@code 123,456,789}.
   855      *                         {@code 123,456,789}.
   856      * @return The formatted number string
   856      * @return The formatted number string
   857      * @exception        ArithmeticException if rounding is needed with rounding
   857      * @throws           ArithmeticException if rounding is needed with rounding
   858      *                   mode being set to RoundingMode.UNNECESSARY
   858      *                   mode being set to RoundingMode.UNNECESSARY
   859      * @see java.text.FieldPosition
   859      * @see java.text.FieldPosition
   860      */
   860      */
   861     private StringBuffer format(BigInteger number, StringBuffer result,
   861     private StringBuffer format(BigInteger number, StringBuffer result,
   862                                FieldPosition fieldPosition) {
   862                                FieldPosition fieldPosition) {
   870      * Format a BigInteger to produce a string.
   870      * Format a BigInteger to produce a string.
   871      * @param number    The BigInteger to format
   871      * @param number    The BigInteger to format
   872      * @param result    where the text is to be appended
   872      * @param result    where the text is to be appended
   873      * @param delegate notified of locations of sub fields
   873      * @param delegate notified of locations of sub fields
   874      * @return The formatted number string
   874      * @return The formatted number string
   875      * @exception        ArithmeticException if rounding is needed with rounding
   875      * @throws           ArithmeticException if rounding is needed with rounding
   876      *                   mode being set to RoundingMode.UNNECESSARY
   876      *                   mode being set to RoundingMode.UNNECESSARY
   877      * @see java.text.FieldPosition
   877      * @see java.text.FieldPosition
   878      */
   878      */
   879     StringBuffer format(BigInteger number, StringBuffer result,
   879     StringBuffer format(BigInteger number, StringBuffer result,
   880                                FieldDelegate delegate, boolean formatLong) {
   880                                FieldDelegate delegate, boolean formatLong) {
   921      * <p>
   921      * <p>
   922      * Each attribute key of the AttributedCharacterIterator will be of type
   922      * Each attribute key of the AttributedCharacterIterator will be of type
   923      * {@code NumberFormat.Field}, with the attribute value being the
   923      * {@code NumberFormat.Field}, with the attribute value being the
   924      * same as the attribute key.
   924      * same as the attribute key.
   925      *
   925      *
   926      * @exception NullPointerException if obj is null.
   926      * @throws    NullPointerException if obj is null.
   927      * @exception IllegalArgumentException when the Format cannot format the
   927      * @throws    IllegalArgumentException when the Format cannot format the
   928      *            given object.
   928      *            given object.
   929      * @exception        ArithmeticException if rounding is needed with rounding
   929      * @throws           ArithmeticException if rounding is needed with rounding
   930      *                   mode being set to RoundingMode.UNNECESSARY
   930      *                   mode being set to RoundingMode.UNNECESSARY
   931      * @param obj The object to format
   931      * @param obj The object to format
   932      * @return AttributedCharacterIterator describing the formatted value.
   932      * @return AttributedCharacterIterator describing the formatted value.
   933      * @since 1.4
   933      * @since 1.4
   934      */
   934      */
  2128      *
  2128      *
  2129      * @param text the string to be parsed
  2129      * @param text the string to be parsed
  2130      * @param pos  A {@code ParsePosition} object with index and error
  2130      * @param pos  A {@code ParsePosition} object with index and error
  2131      *             index information as described above.
  2131      *             index information as described above.
  2132      * @return     the parsed value, or {@code null} if the parse fails
  2132      * @return     the parsed value, or {@code null} if the parse fails
  2133      * @exception  NullPointerException if {@code text} or
  2133      * @throws     NullPointerException if {@code text} or
  2134      *             {@code pos} is null.
  2134      *             {@code pos} is null.
  2135      */
  2135      */
  2136     @Override
  2136     @Override
  2137     public Number parse(String text, ParsePosition pos) {
  2137     public Number parse(String text, ParsePosition pos) {
  2138         // special case NaN
  2138         // special case NaN
  3252      * parentheses.
  3252      * parentheses.
  3253      * <p>In negative patterns, the minimum and maximum counts are ignored;
  3253      * <p>In negative patterns, the minimum and maximum counts are ignored;
  3254      * these are presumed to be set in the positive pattern.
  3254      * these are presumed to be set in the positive pattern.
  3255      *
  3255      *
  3256      * @param pattern a new pattern
  3256      * @param pattern a new pattern
  3257      * @exception NullPointerException if {@code pattern} is null
  3257      * @throws    NullPointerException if {@code pattern} is null
  3258      * @exception IllegalArgumentException if the given pattern is invalid.
  3258      * @throws    IllegalArgumentException if the given pattern is invalid.
  3259      */
  3259      */
  3260     public void applyPattern(String pattern) {
  3260     public void applyPattern(String pattern) {
  3261         applyPattern(pattern, false);
  3261         applyPattern(pattern, false);
  3262     }
  3262     }
  3263 
  3263 
  3279      * parentheses.
  3279      * parentheses.
  3280      * <p>In negative patterns, the minimum and maximum counts are ignored;
  3280      * <p>In negative patterns, the minimum and maximum counts are ignored;
  3281      * these are presumed to be set in the positive pattern.
  3281      * these are presumed to be set in the positive pattern.
  3282      *
  3282      *
  3283      * @param pattern a new pattern
  3283      * @param pattern a new pattern
  3284      * @exception NullPointerException if {@code pattern} is null
  3284      * @throws    NullPointerException if {@code pattern} is null
  3285      * @exception IllegalArgumentException if the given pattern is invalid.
  3285      * @throws    IllegalArgumentException if the given pattern is invalid.
  3286      */
  3286      */
  3287     public void applyLocalizedPattern(String pattern) {
  3287     public void applyLocalizedPattern(String pattern) {
  3288         applyPattern(pattern, true);
  3288         applyPattern(pattern, true);
  3289     }
  3289     }
  3290 
  3290 
  3780      * The currency is set by calling
  3780      * The currency is set by calling
  3781      * {@link DecimalFormatSymbols#setCurrency DecimalFormatSymbols.setCurrency}
  3781      * {@link DecimalFormatSymbols#setCurrency DecimalFormatSymbols.setCurrency}
  3782      * on this number format's symbols.
  3782      * on this number format's symbols.
  3783      *
  3783      *
  3784      * @param currency the new currency to be used by this decimal format
  3784      * @param currency the new currency to be used by this decimal format
  3785      * @exception NullPointerException if {@code currency} is null
  3785      * @throws    NullPointerException if {@code currency} is null
  3786      * @since 1.4
  3786      * @since 1.4
  3787      */
  3787      */
  3788     @Override
  3788     @Override
  3789     public void setCurrency(Currency currency) {
  3789     public void setCurrency(Currency currency) {
  3790         if (currency != symbols.getCurrency()) {
  3790         if (currency != symbols.getCurrency()) {
  3811     /**
  3811     /**
  3812      * Sets the {@link java.math.RoundingMode} used in this DecimalFormat.
  3812      * Sets the {@link java.math.RoundingMode} used in this DecimalFormat.
  3813      *
  3813      *
  3814      * @param roundingMode The {@code RoundingMode} to be used
  3814      * @param roundingMode The {@code RoundingMode} to be used
  3815      * @see #getRoundingMode()
  3815      * @see #getRoundingMode()
  3816      * @exception NullPointerException if {@code roundingMode} is null.
  3816      * @throws    NullPointerException if {@code roundingMode} is null.
  3817      * @since 1.6
  3817      * @since 1.6
  3818      */
  3818      */
  3819     @Override
  3819     @Override
  3820     public void setRoundingMode(RoundingMode roundingMode) {
  3820     public void setRoundingMode(RoundingMode roundingMode) {
  3821         if (roundingMode == null) {
  3821         if (roundingMode == null) {