Class NumberFormatJDK

All Implemented Interfaces:
Serializable, Cloneable

public class NumberFormatJDK extends NumberFormat
NumberFormatJDK is an adapter class which wraps java.text.NumberFormat and implements ICU4J NumberFormat APIs.
See Also:
  • Field Details

  • Constructor Details

    • NumberFormatJDK

      private NumberFormatJDK(NumberFormat jdkNfmt)
  • Method Details

    • wrap

      public static NumberFormat wrap(NumberFormat jdkNfmt)
    • unwrap

      public NumberFormat unwrap()
    • clone

      public Object clone()
      Description copied from class: NumberFormat
      Overrides clone.
      Overrides:
      clone in class NumberFormat
    • equals

      public boolean equals(Object obj)
      Description copied from class: NumberFormat
      Overrides equals. Two NumberFormats are equal they are of the same class and the user-specified values for settings (groupingUsed, parseIntegerOnly, maximumIntegerDigits, etc.) are equal.
      Overrides:
      equals in class NumberFormat
      Parameters:
      obj - the object to compare against
      Returns:
      true if the object is equal to this.
    • format

      public StringBuffer format(BigDecimal number, StringBuffer toAppendTo, FieldPosition pos)
      Description copied from class: NumberFormat
      Formats a BigDecimal. Specialization of format.
      Specified by:
      format in class NumberFormat
      See Also:
    • format

      public StringBuffer format(BigDecimal number, StringBuffer toAppendTo, FieldPosition pos)
      Description copied from class: NumberFormat
      Formats an ICU BigDecimal. Specialization of format.
      Specified by:
      format in class NumberFormat
      See Also:
    • format

      public StringBuffer format(BigInteger number, StringBuffer toAppendTo, FieldPosition pos)
      Description copied from class: NumberFormat
      Formats a BigInteger. Specialization of format.
      Specified by:
      format in class NumberFormat
      See Also:
    • format

      public StringBuffer format(CurrencyAmount currAmt, StringBuffer toAppendTo, FieldPosition pos)
      Description copied from class: NumberFormat
      Formats a CurrencyAmount. Specialization of format.
      Overrides:
      format in class NumberFormat
      See Also:
    • format

      public StringBuffer format(double number, StringBuffer toAppendTo, FieldPosition pos)
      Description copied from class: NumberFormat
      Specialization of format.
      Specified by:
      format in class NumberFormat
      See Also:
    • format

      public StringBuffer format(long number, StringBuffer toAppendTo, FieldPosition pos)
      Description copied from class: NumberFormat
      Specialization of format.
      Specified by:
      format in class NumberFormat
      See Also:
    • format

      public StringBuffer format(Object number, StringBuffer toAppendTo, FieldPosition pos)
      Description copied from class: NumberFormat
      Formats a number and appends the resulting text to the given string buffer. recognizes BigInteger and BigDecimal objects.
      Overrides:
      format in class NumberFormat
      See Also:
    • getCurrency

      public Currency getCurrency()
      Description copied from class: NumberFormat
      Returns the Currency object used to display currency amounts. This may be null.
      Overrides:
      getCurrency in class NumberFormat
    • getMaximumFractionDigits

      public int getMaximumFractionDigits()
      Description copied from class: NumberFormat
      Returns the maximum number of digits allowed in the fraction portion of a number. The default value is 3, which subclasses can override. When formatting, the exact behavior when this value is exceeded is subclass-specific. When parsing, this has no effect.
      Overrides:
      getMaximumFractionDigits in class NumberFormat
      Returns:
      the maximum number of fraction digits
      See Also:
    • getMaximumIntegerDigits

      public int getMaximumIntegerDigits()
      Description copied from class: NumberFormat
      Returns the maximum number of digits allowed in the integer portion of a number. The default value is 40, which subclasses can override. When formatting, if the number of digits exceeds this value, the highest- significance digits are truncated until the limit is reached, in accordance with UTS#35. This setting has no effect on parsing.
      Overrides:
      getMaximumIntegerDigits in class NumberFormat
      Returns:
      the maximum number of integer digits
      See Also:
    • getMinimumFractionDigits

      public int getMinimumFractionDigits()
      Description copied from class: NumberFormat
      Returns the minimum number of digits allowed in the fraction portion of a number. The default value is 0, which subclasses can override. When formatting, if this value is not reached, numbers are padded on the right with the locale-specific '0' character to ensure at least this number of fraction digits. When parsing, this has no effect.
      Overrides:
      getMinimumFractionDigits in class NumberFormat
      Returns:
      the minimum number of fraction digits
      See Also:
    • getMinumumIntegerDigits

      public int getMinumumIntegerDigits()
    • getRoundingMode

      public int getRoundingMode()
      Description copied from class: NumberFormat
      Returns the rounding mode used in this NumberFormat. The default implementation of tis method in NumberFormat always throws UnsupportedOperationException.
      Overrides:
      getRoundingMode in class NumberFormat
      Returns:
      A rounding mode, between BigDecimal.ROUND_UP and BigDecimal.ROUND_UNNECESSARY.
      See Also:
    • hashCode

      public int hashCode()
      Description copied from class: NumberFormat
      Overrides:
      hashCode in class NumberFormat
    • isGroupingUsed

      public boolean isGroupingUsed()
      Description copied from class: NumberFormat
      Returns true if grouping is used in this format. For example, in the en_US locale, with grouping on, the number 1234567 will be formatted as "1,234,567". The grouping separator as well as the size of each group is locale-dependent and is determined by subclasses of NumberFormat. Grouping affects both parsing and formatting.
      Overrides:
      isGroupingUsed in class NumberFormat
      Returns:
      true if grouping is used
      See Also:
    • isParseIntegerOnly

      public boolean isParseIntegerOnly()
      Description copied from class: NumberFormat
      Returns true if this format will parse numbers as integers only. For example in the English locale, with ParseIntegerOnly true, the string "1234." would be parsed as the integer value 1234 and parsing would stop at the "." character. The decimal separator accepted by the parse operation is locale-dependent and determined by the subclass.
      Overrides:
      isParseIntegerOnly in class NumberFormat
      Returns:
      true if this will parse integers only
    • isParseStrict

      public boolean isParseStrict()
      Description copied from class: NumberFormat
      Returns whether strict parsing is in effect.
      Overrides:
      isParseStrict in class NumberFormat
      Returns:
      true if strict parsing is in effect
      See Also:
    • parse

      public Number parse(String text) throws ParseException
      Description copied from class: NumberFormat
      Parses text from the beginning of the given string to produce a number. The method might not use the entire text of the given string.
      Overrides:
      parse in class NumberFormat
      Parameters:
      text - A String whose beginning should be parsed.
      Returns:
      A Number parsed from the string.
      Throws:
      ParseException - if the beginning of the specified string cannot be parsed.
      See Also:
    • parse

      public Number parse(String text, ParsePosition parsePosition)
      Description copied from class: NumberFormat
      Returns a Long if possible (e.g., within the range [Long.MIN_VALUE, Long.MAX_VALUE] and with no decimals); otherwise, returns another type, such as a BigDecimal, BigInteger, or Double. The return type is not guaranteed other than for the Long case.

      If IntegerOnly is set, will stop at a decimal point (or equivalent; e.g., for rational numbers "1 2/3", will stop after the 1).

      Does not throw an exception; if no object can be parsed, index is unchanged!

      For more detail on parsing, see the "Parsing" header in the class documentation of DecimalFormat.

      Specified by:
      parse in class NumberFormat
      See Also:
    • setCurrency

      public void setCurrency(Currency theCurrency)
      Description copied from class: NumberFormat
      Sets the Currency object used to display currency amounts. This takes effect immediately, if this format is a currency format. If this format is not a currency format, then the currency object is used if and when this object becomes a currency format.
      Overrides:
      setCurrency in class NumberFormat
      Parameters:
      theCurrency - new currency object to use. May be null for some subclasses.
    • setGroupingUsed

      public void setGroupingUsed(boolean newValue)
      Description copied from class: NumberFormat
      Sets whether or not grouping will be used in this format. Grouping affects both parsing and formatting.
      Overrides:
      setGroupingUsed in class NumberFormat
      Parameters:
      newValue - true to use grouping.
      See Also:
    • setMaximumFractionDigits

      public void setMaximumFractionDigits(int newValue)
      Description copied from class: NumberFormat
      Sets the maximum number of digits allowed in the fraction portion of a number. This must be >= minimumFractionDigits. If the new value for maximumFractionDigits is less than the current value of minimumFractionDigits, then minimumFractionDigits will also be set to the new value.
      Overrides:
      setMaximumFractionDigits in class NumberFormat
      Parameters:
      newValue - the maximum number of fraction digits to be shown; if less than zero, then zero is used. The concrete subclass may enforce an upper limit to this value appropriate to the numeric type being formatted.
      See Also:
    • setMaximumIntegerDigits

      public void setMaximumIntegerDigits(int newValue)
      Description copied from class: NumberFormat
      Sets the maximum number of digits allowed in the integer portion of a number. This must be >= minimumIntegerDigits. If the new value for maximumIntegerDigits is less than the current value of minimumIntegerDigits, then minimumIntegerDigits will also be set to the new value.
      Overrides:
      setMaximumIntegerDigits in class NumberFormat
      Parameters:
      newValue - the maximum number of integer digits to be shown; if less than zero, then zero is used. Subclasses might enforce an upper limit to this value appropriate to the numeric type being formatted.
      See Also:
    • setMinimumFractionDigits

      public void setMinimumFractionDigits(int newValue)
      Description copied from class: NumberFormat
      Sets the minimum number of digits allowed in the fraction portion of a number. This must be <= maximumFractionDigits. If the new value for minimumFractionDigits exceeds the current value of maximumFractionDigits, then maximumFractionDigits will also be set to the new value.
      Overrides:
      setMinimumFractionDigits in class NumberFormat
      Parameters:
      newValue - the minimum number of fraction digits to be shown; if less than zero, then zero is used. Subclasses might enforce an upper limit to this value appropriate to the numeric type being formatted.
      See Also:
    • setMinimumIntegerDigits

      public void setMinimumIntegerDigits(int newValue)
      Description copied from class: NumberFormat
      Sets the minimum number of digits allowed in the integer portion of a number. This must be <= maximumIntegerDigits. If the new value for minimumIntegerDigits is more than the current value of maximumIntegerDigits, then maximumIntegerDigits will also be set to the new value.
      Overrides:
      setMinimumIntegerDigits in class NumberFormat
      Parameters:
      newValue - the minimum number of integer digits to be shown; if less than zero, then zero is used. Subclasses might enforce an upper limit to this value appropriate to the numeric type being formatted.
      See Also:
    • setParseIntegerOnly

      public void setParseIntegerOnly(boolean value)
      Description copied from class: NumberFormat
      Sets whether to ignore the fraction part of a number when parsing (defaults to false). If a string contains a decimal point, parsing will stop before the decimal point. Note that determining whether a character is a decimal point depends on the locale.

      For example, in en-US, parsing the string "123.45" will return the number 123 and parse position 3.

      Overrides:
      setParseIntegerOnly in class NumberFormat
      Parameters:
      value - true if this should parse integers only
      See Also:
    • setParseStrict

      public void setParseStrict(boolean value)
      Description copied from class: NumberFormat
      Sets whether strict parsing is in effect. When this is true, the string is required to be a stronger match to the pattern than when lenient parsing is in effect. More specifically, the following conditions cause a parse failure relative to lenient mode (examples use the pattern "#,##0.#"):
      • The presence and position of special symbols, including currency, must match the pattern.
        '+123' fails (there is no plus sign in the pattern)
      • Leading or doubled grouping separators
        ',123' and '1,,234" fail
      • Groups of incorrect length when grouping is used
        '1,23' and '1234,567' fail, but '1234' passes
      • Grouping separators used in numbers followed by exponents
        '1,234E5' fails, but '1234E5' and '1,234E' pass ('E' is not an exponent when not followed by a number)
      When strict parsing is off, all grouping separators are ignored. This is the default behavior.
      Overrides:
      setParseStrict in class NumberFormat
      Parameters:
      value - True to enable strict parsing. Default is false.
      See Also:
    • setRoundingMode

      public void setRoundingMode(int roundingMode)
      Description copied from class: NumberFormat
      Set the rounding mode used in this NumberFormat. The default implementation of tis method in NumberFormat always throws UnsupportedOperationException.
      Overrides:
      setRoundingMode in class NumberFormat
      Parameters:
      roundingMode - A rounding mode, between BigDecimal.ROUND_UP and BigDecimal.ROUND_UNNECESSARY.
      See Also: