Class ParsedNumber

java.lang.Object
com.ibm.icu.impl.number.parse.ParsedNumber

public class ParsedNumber extends Object
Struct-like class to hold the results of a parsing routine.
  • Field Details

    • quantity

      The numerical value that was parsed.
    • charEnd

      public int charEnd
      The index of the last char consumed during parsing. If parsing started at index 0, this is equal to the number of chars consumed. This is NOT necessarily the same as the StringSegment offset; "weak" chars, like whitespace, change the offset, but the charsConsumed is not touched until a "strong" char is encountered.
    • flags

      public int flags
      Boolean flags (see constants below).
    • prefix

      public String prefix
      The pattern string corresponding to the prefix that got consumed.
    • suffix

      public String suffix
      The pattern string corresponding to the suffix that got consumed.
    • currencyCode

      public String currencyCode
      The currency that got consumed.
    • FLAG_NEGATIVE

      public static final int FLAG_NEGATIVE
      See Also:
    • FLAG_PERCENT

      public static final int FLAG_PERCENT
      See Also:
    • FLAG_PERMILLE

      public static final int FLAG_PERMILLE
      See Also:
    • FLAG_HAS_EXPONENT

      public static final int FLAG_HAS_EXPONENT
      See Also:
    • FLAG_HAS_DECIMAL_SEPARATOR

      public static final int FLAG_HAS_DECIMAL_SEPARATOR
      See Also:
    • FLAG_NAN

      public static final int FLAG_NAN
      See Also:
    • FLAG_INFINITY

      public static final int FLAG_INFINITY
      See Also:
    • FLAG_FAIL

      public static final int FLAG_FAIL
      See Also:
    • COMPARATOR

      public static final Comparator<ParsedNumber> COMPARATOR
      A Comparator that favors ParsedNumbers with the most chars consumed.
  • Constructor Details

    • ParsedNumber

      public ParsedNumber()
  • Method Details

    • clear

      public void clear()
      Clears the data from this ParsedNumber, in effect failing the current parse.
    • copyFrom

      public void copyFrom(ParsedNumber other)
    • setCharsConsumed

      public void setCharsConsumed(StringSegment segment)
      Call this method to register that a "strong" char was consumed. This should be done after calling StringSegment.setOffset(int) or StringSegment.adjustOffset(int) except when the char is "weak", like whitespace.

      What is a strong versus weak char? The behavior of number parsing is to "stop" after reading the number, even if there is other content following the number. For example, after parsing the string "123 " (123 followed by a space), the cursor should be set to 3, not 4, even though there are matchers that accept whitespace. In this example, the digits are strong, whereas the whitespace is weak. Grouping separators are weak, whereas decimal separators are strong. Most other chars are strong.

      Parameters:
      segment - The current StringSegment, usually immediately following a call to setOffset.
    • postProcess

      public void postProcess()
      Apply certain number-related flags to the DecimalQuantity.
    • success

      public boolean success()
      Returns whether this the parse was successful. To be successful, at least one char must have been consumed, and the failure flag must not be set.
    • seenNumber

      public boolean seenNumber()
    • getNumber

      public Number getNumber()
    • getNumber

      public Number getNumber(int parseFlags)
      Parameters:
      parseFlags - Configuration settings from ParsingUtils.java
    • isBetterThan

      boolean isBetterThan(ParsedNumber other)