java.lang.Object
io.github.mmm.scanner.number.CharScannerNumberParserBase
io.github.mmm.scanner.number.CharScannerNumberParserLang
- All Implemented Interfaces:
CharScannerNumberParser,CharScannerRadixHandler
-
Nested Class Summary
Nested classes/interfaces inherited from class io.github.mmm.scanner.number.CharScannerNumberParserBase
CharScannerNumberParserBase.CharScannerNumberSpecial, CharScannerNumberParserBase.CharScannerNumberSpecialDelimiter, CharScannerNumberParserBase.CharScannerNumberSpecialNonNumber -
Field Summary
Fields inherited from class io.github.mmm.scanner.number.CharScannerNumberParserBase
builder, digitsLeadingZeros, digitsTotal, digitsTrailingZeros, dotPosition, error, exponentDigitsLeadingZeros, exponentDigitsTotal, exponentSign, exponentSymbol, INFINITY, NAN, openDelimiter, radix, radixChar, sign -
Constructor Summary
ConstructorsConstructorDescriptionCharScannerNumberParserLang(CharScannerRadixHandler radixMode, NumberType<?> numberType) The constructor.CharScannerNumberParserLang(CharScannerRadixHandler radixMode, NumberType<?> numberType, String delimiters) The constructor.CharScannerNumberParserLang(CharScannerRadixHandler radixMode, NumberType<?> numberType, String delimiters, long maxNonDecimal) The constructor. -
Method Summary
Modifier and TypeMethodDescriptionasDouble()asLong()protected StringBuilderbuilder()booleandigit(int digit, char digitChar) protected booleanprotected voidResets the trailing zeros if a non zero digit was found for mantissa.booleansign(char signChar) This method will only be called if the first character if the number is '+' or '-'.voidtoString()Methods inherited from class io.github.mmm.scanner.number.CharScannerNumberParserBase
appendExponent, appendRadix, dot, exponent, isDigit, isValidDelimiterPosition, radix, special, specials
-
Constructor Details
-
CharScannerNumberParserLang
The constructor.- Parameters:
radixMode- theCharScannerRadixHandlerforCharScannerNumberParserBase.radix(int, char).numberType- theNumberType.
-
CharScannerNumberParserLang
public CharScannerNumberParserLang(CharScannerRadixHandler radixMode, NumberType<?> numberType, String delimiters) The constructor.- Parameters:
radixMode- theCharScannerRadixHandlerforCharScannerNumberParserBase.radix(int, char).numberType- theNumberType.delimiters- the accepteddelimitercharacters.
-
CharScannerNumberParserLang
public CharScannerNumberParserLang(CharScannerRadixHandler radixMode, NumberType<?> numberType, String delimiters, long maxNonDecimal) The constructor.- Parameters:
radixMode- theCharScannerRadixHandlerforCharScannerNumberParserBase.radix(int, char).numberType- theNumberType.delimiters- the accepteddelimitercharacters.maxNonDecimal- the maximum allowed number (e.g.Integer.MAX_VALUEto parse anIntegervalue).
-
-
Method Details
-
isDecimal
protected boolean isDecimal()- Specified by:
isDecimalin classCharScannerNumberParserBase- Returns:
truein case decimal numbers withCharScannerNumberParserBase.dot()and/orexponentare accepted,falseotherwise.
-
sign
public boolean sign(char signChar) Description copied from interface:CharScannerNumberParserThis method will only be called if the first character if the number is '+' or '-'.- Specified by:
signin interfaceCharScannerNumberParser- Overrides:
signin classCharScannerNumberParserBase- Parameters:
signChar- '+' for positive number and '-' for negative number. If no sign is present this method will never be called.- Returns:
trueif the sign shall be accepted and further characters shall be received,falseto prevent consuming the sign or any further characters and abort the process (e.g. to parse only positive numbers without any sign).
-
special
- Specified by:
specialin interfaceCharScannerNumberParser- Overrides:
specialin classCharScannerNumberParserBase- Parameters:
special- the specialStringthat was found and consumed.- See Also:
-
builder
- Overrides:
builderin classCharScannerNumberParserBase- Returns:
- the
StringBuilderto build the number. Ensures initialization in case of lazy-init.
-
digit
public boolean digit(int digit, char digitChar) - Specified by:
digitin interfaceCharScannerNumberParser- Overrides:
digitin classCharScannerNumberParserBase- Parameters:
digit- the parseddigitCharas numeric digit to "append". Will never be negative but may be greater or equal to the radix returned byCharScannerRadixHandler.radix(int, char)asNumberFormatExceptionhas to be handled inside the receiver.digitChar- the original digit character. In case the number shall be received asStringthis makes your life simpler and allows to preserve the case.- Returns:
trueif the given digit is accepted,falseotherwise (exceeds the range of the number to parse and the digit should not be consumed). Typical implementations should always returntrue.
-
resetTrailingZeros
protected void resetTrailingZeros()Description copied from class:CharScannerNumberParserBaseResets the trailing zeros if a non zero digit was found for mantissa.- Overrides:
resetTrailingZerosin classCharScannerNumberParserBase
-
asInteger
- Returns:
- the parsed value as
Integer. - Throws:
NumberFormatException- if parsing failed.
-
asLong
- Returns:
- the parsed value as
Long. - Throws:
NumberFormatException- if parsing failed.
-
asDouble
- Returns:
- the parsed value as
Double. - Throws:
NumberFormatException- if parsing failed.
-
toString
- Overrides:
toStringin classCharScannerNumberParserBase
-