/** * Create a default number format. The default number format is based on * {@link NumberFormat#getInstance()} with the only customizing that the * maximum number of fraction digits is set to 2. * @return the default number format. */ protected static NumberFormat getDefaultNumberFormat() { return getDefaultNumberFormat(Locale.getDefault()); }
/** * Parses <code>source</code> until a non-whitespace character is found. * * @param source the string to parse * @param pos input/ouput parsing parameter. On output, <code>pos</code> * holds the index of the next non-whitespace character. */ protected void parseAndIgnoreWhitespace(final String source, final ParsePosition pos) { parseNextCharacter(source, pos); pos.setIndex(pos.getIndex() - 1); }
/** * Parses <code>source</code> for a number. This method can parse normal, * numeric values as well as special values. These special values include * Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY. * * @param source the string to parse * @param format the number format used to parse normal, numeric values. * @param pos input/ouput parsing parameter. * @return the parsed number. */ protected Number parseNumber(final String source, final NumberFormat format, final ParsePosition pos) { final int startIndex = pos.getIndex(); Number number = format.parse(source, pos); final int endIndex = pos.getIndex(); // check for error parsing number if (startIndex == endIndex) { // try parsing special numbers final double[] special = { Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY }; for (int i = 0; i < special.length; ++i) { number = parseNumber(source, special[i], pos); if (number != null) { break; } } } return number; }
/** * Parses <code>source</code> for a number. This method can parse normal, * numeric values as well as special values. These special values include * Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY. * * @param source the string to parse * @param format the number format used to parse normal, numeric values. * @param pos input/ouput parsing parameter. * @return the parsed number. */ protected Number parseNumber(final String source, final NumberFormat format, final ParsePosition pos) { final int startIndex = pos.getIndex(); Number number = format.parse(source, pos); final int endIndex = pos.getIndex(); // check for error parsing number if (startIndex == endIndex) { // try parsing special numbers final double[] special = { Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY }; for (int i = 0; i < special.length; ++i) { number = parseNumber(source, special[i], pos); if (number != null) { break; } } } return number; }
/** * Parses <code>source</code> until a non-whitespace character is found. * * @param source the string to parse * @param pos input/ouput parsing parameter. On output, <code>pos</code> * holds the index of the next non-whitespace character. */ protected void parseAndIgnoreWhitespace(final String source, final ParsePosition pos) { parseNextCharacter(source, pos); pos.setIndex(pos.getIndex() - 1); }
/** * Create a default number format. The default number format is based on * {@link NumberFormat#getInstance()} with the only customizing that the * maximum number of fraction digits is set to 2. * @return the default number format. */ protected static NumberFormat getDefaultNumberFormat() { return getDefaultNumberFormat(Locale.getDefault()); }