src/java.base/share/classes/java/text/NumberFormat.java
changeset 58242 94bb65cb37d3
parent 57956 e0b8b019d2f5
child 58288 48e480e56aad
equal deleted inserted replaced
58241:33de7752835c 58242:94bb65cb37d3
   257      *                   {@link NumberFormat#INTEGER_FIELD}, the begin index
   257      *                   {@link NumberFormat#INTEGER_FIELD}, the begin index
   258      *                   and end index of {@code fieldPosition} will be set
   258      *                   and end index of {@code fieldPosition} will be set
   259      *                   to 0 and 9, respectively for the output string
   259      *                   to 0 and 9, respectively for the output string
   260      *                   {@code 1,234,567.89}.
   260      *                   {@code 1,234,567.89}.
   261      * @return           the value passed in as <code>toAppendTo</code>
   261      * @return           the value passed in as <code>toAppendTo</code>
   262      * @exception        IllegalArgumentException if <code>number</code> is
   262      * @throws           IllegalArgumentException if <code>number</code> is
   263      *                   null or not an instance of <code>Number</code>.
   263      *                   null or not an instance of <code>Number</code>.
   264      * @exception        NullPointerException if <code>toAppendTo</code> or
   264      * @throws           NullPointerException if <code>toAppendTo</code> or
   265      *                   <code>pos</code> is null
   265      *                   <code>pos</code> is null
   266      * @exception        ArithmeticException if rounding is needed with rounding
   266      * @throws           ArithmeticException if rounding is needed with rounding
   267      *                   mode being set to RoundingMode.UNNECESSARY
   267      *                   mode being set to RoundingMode.UNNECESSARY
   268      * @see              java.text.FieldPosition
   268      * @see              java.text.FieldPosition
   269      */
   269      */
   270     @Override
   270     @Override
   271     public StringBuffer format(Object number,
   271     public StringBuffer format(Object number,
   316    /**
   316    /**
   317      * Specialization of format.
   317      * Specialization of format.
   318      *
   318      *
   319      * @param number the double number to format
   319      * @param number the double number to format
   320      * @return the formatted String
   320      * @return the formatted String
   321      * @exception        ArithmeticException if rounding is needed with rounding
   321      * @throws           ArithmeticException if rounding is needed with rounding
   322      *                   mode being set to RoundingMode.UNNECESSARY
   322      *                   mode being set to RoundingMode.UNNECESSARY
   323      * @see java.text.Format#format
   323      * @see java.text.Format#format
   324      */
   324      */
   325     public final String format(double number) {
   325     public final String format(double number) {
   326         // Use fast-path for double result if that works
   326         // Use fast-path for double result if that works
   341    /**
   341    /**
   342      * Specialization of format.
   342      * Specialization of format.
   343      *
   343      *
   344      * @param number the long number to format
   344      * @param number the long number to format
   345      * @return the formatted String
   345      * @return the formatted String
   346      * @exception        ArithmeticException if rounding is needed with rounding
   346      * @throws           ArithmeticException if rounding is needed with rounding
   347      *                   mode being set to RoundingMode.UNNECESSARY
   347      *                   mode being set to RoundingMode.UNNECESSARY
   348      * @see java.text.Format#format
   348      * @see java.text.Format#format
   349      */
   349      */
   350     public final String format(long number) {
   350     public final String format(long number) {
   351         return format(number, new StringBuffer(),
   351         return format(number, new StringBuffer(),
   365      *                   {@link NumberFormat#INTEGER_FIELD}, the begin index
   365      *                   {@link NumberFormat#INTEGER_FIELD}, the begin index
   366      *                   and end index of {@code fieldPosition} will be set
   366      *                   and end index of {@code fieldPosition} will be set
   367      *                   to 0 and 9, respectively for the output string
   367      *                   to 0 and 9, respectively for the output string
   368      *                   {@code 1,234,567.89}.
   368      *                   {@code 1,234,567.89}.
   369      * @return the formatted StringBuffer
   369      * @return the formatted StringBuffer
   370      * @exception        ArithmeticException if rounding is needed with rounding
   370      * @throws           ArithmeticException if rounding is needed with rounding
   371      *                   mode being set to RoundingMode.UNNECESSARY
   371      *                   mode being set to RoundingMode.UNNECESSARY
   372      * @see java.text.Format#format
   372      * @see java.text.Format#format
   373      */
   373      */
   374     public abstract StringBuffer format(double number,
   374     public abstract StringBuffer format(double number,
   375                                         StringBuffer toAppendTo,
   375                                         StringBuffer toAppendTo,
   388      *                   {@link NumberFormat#INTEGER_FIELD}, the begin index
   388      *                   {@link NumberFormat#INTEGER_FIELD}, the begin index
   389      *                   and end index of {@code fieldPosition} will be set
   389      *                   and end index of {@code fieldPosition} will be set
   390      *                   to 0 and 11, respectively for the output string
   390      *                   to 0 and 11, respectively for the output string
   391      *                   {@code 123,456,789}.
   391      *                   {@code 123,456,789}.
   392      * @return the formatted StringBuffer
   392      * @return the formatted StringBuffer
   393      * @exception        ArithmeticException if rounding is needed with rounding
   393      * @throws           ArithmeticException if rounding is needed with rounding
   394      *                   mode being set to RoundingMode.UNNECESSARY
   394      *                   mode being set to RoundingMode.UNNECESSARY
   395      * @see java.text.Format#format
   395      * @see java.text.Format#format
   396      */
   396      */
   397     public abstract StringBuffer format(long number,
   397     public abstract StringBuffer format(long number,
   398                                         StringBuffer toAppendTo,
   398                                         StringBuffer toAppendTo,
   422      * See the {@link #parse(String, ParsePosition)} method for more information
   422      * See the {@link #parse(String, ParsePosition)} method for more information
   423      * on number parsing.
   423      * on number parsing.
   424      *
   424      *
   425      * @param source A <code>String</code> whose beginning should be parsed.
   425      * @param source A <code>String</code> whose beginning should be parsed.
   426      * @return A <code>Number</code> parsed from the string.
   426      * @return A <code>Number</code> parsed from the string.
   427      * @exception ParseException if the beginning of the specified string
   427      * @throws    ParseException if the beginning of the specified string
   428      *            cannot be parsed.
   428      *            cannot be parsed.
   429      */
   429      */
   430     public Number parse(String source) throws ParseException {
   430     public Number parse(String source) throws ParseException {
   431         ParsePosition parsePosition = new ParsePosition(0);
   431         ParsePosition parsePosition = new ParsePosition(0);
   432         Number result = parse(source, parsePosition);
   432         Number result = parse(source, parsePosition);
   889      * <p>
   889      * <p>
   890      * The default implementation throws
   890      * The default implementation throws
   891      * <code>UnsupportedOperationException</code>.
   891      * <code>UnsupportedOperationException</code>.
   892      *
   892      *
   893      * @return the currency used by this number format, or <code>null</code>
   893      * @return the currency used by this number format, or <code>null</code>
   894      * @exception UnsupportedOperationException if the number format class
   894      * @throws    UnsupportedOperationException if the number format class
   895      * doesn't implement currency formatting
   895      * doesn't implement currency formatting
   896      * @since 1.4
   896      * @since 1.4
   897      */
   897      */
   898     public Currency getCurrency() {
   898     public Currency getCurrency() {
   899         throw new UnsupportedOperationException();
   899         throw new UnsupportedOperationException();
   906      * <p>
   906      * <p>
   907      * The default implementation throws
   907      * The default implementation throws
   908      * <code>UnsupportedOperationException</code>.
   908      * <code>UnsupportedOperationException</code>.
   909      *
   909      *
   910      * @param currency the new currency to be used by this number format
   910      * @param currency the new currency to be used by this number format
   911      * @exception UnsupportedOperationException if the number format class
   911      * @throws    UnsupportedOperationException if the number format class
   912      * doesn't implement currency formatting
   912      * doesn't implement currency formatting
   913      * @exception NullPointerException if <code>currency</code> is null
   913      * @throws    NullPointerException if <code>currency</code> is null
   914      * @since 1.4
   914      * @since 1.4
   915      */
   915      */
   916     public void setCurrency(Currency currency) {
   916     public void setCurrency(Currency currency) {
   917         throw new UnsupportedOperationException();
   917         throw new UnsupportedOperationException();
   918     }
   918     }
   922      * The default implementation of this method in NumberFormat
   922      * The default implementation of this method in NumberFormat
   923      * always throws {@link java.lang.UnsupportedOperationException}.
   923      * always throws {@link java.lang.UnsupportedOperationException}.
   924      * Subclasses which handle different rounding modes should override
   924      * Subclasses which handle different rounding modes should override
   925      * this method.
   925      * this method.
   926      *
   926      *
   927      * @exception UnsupportedOperationException The default implementation
   927      * @throws    UnsupportedOperationException The default implementation
   928      *     always throws this exception
   928      *     always throws this exception
   929      * @return The <code>RoundingMode</code> used for this NumberFormat.
   929      * @return The <code>RoundingMode</code> used for this NumberFormat.
   930      * @see #setRoundingMode(RoundingMode)
   930      * @see #setRoundingMode(RoundingMode)
   931      * @since 1.6
   931      * @since 1.6
   932      */
   932      */
   939      * The default implementation of this method in NumberFormat always
   939      * The default implementation of this method in NumberFormat always
   940      * throws {@link java.lang.UnsupportedOperationException}.
   940      * throws {@link java.lang.UnsupportedOperationException}.
   941      * Subclasses which handle different rounding modes should override
   941      * Subclasses which handle different rounding modes should override
   942      * this method.
   942      * this method.
   943      *
   943      *
   944      * @exception UnsupportedOperationException The default implementation
   944      * @throws    UnsupportedOperationException The default implementation
   945      *     always throws this exception
   945      *     always throws this exception
   946      * @exception NullPointerException if <code>roundingMode</code> is null
   946      * @throws    NullPointerException if <code>roundingMode</code> is null
   947      * @param roundingMode The <code>RoundingMode</code> to be used
   947      * @param roundingMode The <code>RoundingMode</code> to be used
   948      * @see #getRoundingMode()
   948      * @see #getRoundingMode()
   949      * @since 1.6
   949      * @since 1.6
   950      */
   950      */
   951     public void setRoundingMode(RoundingMode roundingMode) {
   951     public void setRoundingMode(RoundingMode roundingMode) {