src/share/classes/java/text/NumberFormat.java

Print this page




 266      * on number parsing.
 267      *
 268      * @param source A <code>String</code>, part of which should be parsed.
 269      * @param pos A <code>ParsePosition</code> object with index and error
 270      *            index information as described above.
 271      * @return A <code>Number</code> parsed from the string. In case of
 272      *         error, returns null.
 273      * @exception NullPointerException if <code>pos</code> is null.
 274      */
 275     public final Object parseObject(String source, ParsePosition pos) {
 276         return parse(source, pos);
 277     }
 278 
 279    /**
 280      * Specialization of format.
 281      * @exception        ArithmeticException if rounding is needed with rounding
 282      *                   mode being set to RoundingMode.UNNECESSARY
 283      * @see java.text.Format#format
 284      */
 285     public final String format(double number) {




 286         return format(number, new StringBuffer(),
 287                       DontCareFieldPosition.INSTANCE).toString();
 288     }
 289 






 290    /**
 291      * Specialization of format.
 292      * @exception        ArithmeticException if rounding is needed with rounding
 293      *                   mode being set to RoundingMode.UNNECESSARY
 294      * @see java.text.Format#format
 295      */
 296     public final String format(long number) {
 297         return format(number, new StringBuffer(),
 298                       DontCareFieldPosition.INSTANCE).toString();
 299     }
 300 
 301    /**
 302      * Specialization of format.
 303      * @exception        ArithmeticException if rounding is needed with rounding
 304      *                   mode being set to RoundingMode.UNNECESSARY
 305      * @see java.text.Format#format
 306      */
 307     public abstract StringBuffer format(double number,
 308                                         StringBuffer toAppendTo,
 309                                         FieldPosition pos);




 266      * on number parsing.
 267      *
 268      * @param source A <code>String</code>, part of which should be parsed.
 269      * @param pos A <code>ParsePosition</code> object with index and error
 270      *            index information as described above.
 271      * @return A <code>Number</code> parsed from the string. In case of
 272      *         error, returns null.
 273      * @exception NullPointerException if <code>pos</code> is null.
 274      */
 275     public final Object parseObject(String source, ParsePosition pos) {
 276         return parse(source, pos);
 277     }
 278 
 279    /**
 280      * Specialization of format.
 281      * @exception        ArithmeticException if rounding is needed with rounding
 282      *                   mode being set to RoundingMode.UNNECESSARY
 283      * @see java.text.Format#format
 284      */
 285     public final String format(double number) {
 286         // Use fast-path for double result if that works
 287         String result = fastFormat(number);
 288         if (result != null) return result;
 289 
 290         return format(number, new StringBuffer(),
 291                       DontCareFieldPosition.INSTANCE).toString();
 292     }
 293 
 294     /*
 295      * fastFormat() is supposed to be implemented in concrete subclasses only.
 296      * Default implem always returns null.
 297      */
 298     String fastFormat(double number) { return null; }
 299 
 300    /**
 301      * Specialization of format.
 302      * @exception        ArithmeticException if rounding is needed with rounding
 303      *                   mode being set to RoundingMode.UNNECESSARY
 304      * @see java.text.Format#format
 305      */
 306     public final String format(long number) {
 307         return format(number, new StringBuffer(),
 308                       DontCareFieldPosition.INSTANCE).toString();
 309     }
 310 
 311    /**
 312      * Specialization of format.
 313      * @exception        ArithmeticException if rounding is needed with rounding
 314      *                   mode being set to RoundingMode.UNNECESSARY
 315      * @see java.text.Format#format
 316      */
 317     public abstract StringBuffer format(double number,
 318                                         StringBuffer toAppendTo,
 319                                         FieldPosition pos);