Class ParsedNumber


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

      • 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 java.lang.String prefix
        The pattern string corresponding to the prefix that got consumed.
      • suffix

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

        public java.lang.String currencyCode
        The currency that got consumed.
      • FLAG_HAS_DECIMAL_SEPARATOR

        public static final int FLAG_HAS_DECIMAL_SEPARATOR
        See Also:
        Constant Field Values
      • COMPARATOR

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

      • ParsedNumber

        public ParsedNumber()
    • Method Detail

      • clear

        public void clear()
        Clears the data from this ParsedNumber, in effect failing the current parse.
      • 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 java.lang.Number getNumber()
      • getNumber

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

        boolean isBetterThan​(ParsedNumber other)