Class NumberInput
- java.lang.Object
 - 
- com.fasterxml.jackson.core.io.NumberInput
 
 
- 
public final class NumberInput extends java.lang.ObjectHelper class for efficient parsing of various JSON numbers.NOTE! Does NOT validate against maximum length limits: caller must do that if and as necessary.
 
- 
- 
Field Summary
Fields Modifier and Type Field Description static java.lang.StringNASTY_SMALL_DOUBLEDeprecated.Since 2.14 -- do not use 
- 
Constructor Summary
Constructors Constructor Description NumberInput() 
- 
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static booleaninLongRange(char[] ch, int off, int len, boolean negative)Helper method for determining if given String representation of an integral number would fit in 64-bit Java long or not.static booleaninLongRange(java.lang.String s, boolean negative)Similar toinLongRange(char[],int,int,boolean), but with String argumentstatic booleanlooksLikeValidNumber(java.lang.String s)Method called to check whether given pattern looks like a valid Java Number (which is bit looser definition than valid JSON Number).static doubleparseAsDouble(java.lang.String s, double def)static doubleparseAsDouble(java.lang.String s, double def, boolean useFastParser)static intparseAsInt(java.lang.String s, int def)static longparseAsLong(java.lang.String s, long def)static java.math.BigDecimalparseBigDecimal(char[] ch)Deprecated.Since 2.17 useparseBigDecimal(char[], boolean)insteadstatic java.math.BigDecimalparseBigDecimal(char[] ch, boolean useFastParser)static java.math.BigDecimalparseBigDecimal(char[] ch, int off, int len)Deprecated.Since 2.17 useparseBigDecimal(char[], int, int, boolean)insteadstatic java.math.BigDecimalparseBigDecimal(char[] ch, int off, int len, boolean useFastParser)static java.math.BigDecimalparseBigDecimal(java.lang.String s)Deprecated.Since 2.17 useparseBigDecimal(String, boolean)insteadstatic java.math.BigDecimalparseBigDecimal(java.lang.String s, boolean useFastParser)static java.math.BigIntegerparseBigInteger(java.lang.String s)Deprecated.Since 2.17 useparseBigInteger(String, boolean)insteadstatic java.math.BigIntegerparseBigInteger(java.lang.String s, boolean useFastParser)static java.math.BigIntegerparseBigIntegerWithRadix(java.lang.String s, int radix, boolean useFastParser)static doubleparseDouble(java.lang.String s)Deprecated.Since 2.17 useparseDouble(String, boolean)insteadstatic doubleparseDouble(java.lang.String s, boolean useFastParser)static floatparseFloat(java.lang.String s)Deprecated.Since 2.17 useparseFloat(String, boolean)insteadstatic floatparseFloat(java.lang.String s, boolean useFastParser)static intparseInt(char[] ch, int off, int len)Fast method for parsing unsigned integers that are known to fit into regular 32-bit signed int type.static intparseInt(java.lang.String s)Helper method to (more) efficiently parse integer numbers from String values.static longparseLong(char[] ch, int off, int len)static longparseLong(java.lang.String s)Similar toparseInt(String)but forlongvalues.static longparseLong19(char[] ch, int off, boolean negative)Parses an unsigned long made up of exactly 19 digits. 
 - 
 
- 
- 
Field Detail
- 
NASTY_SMALL_DOUBLE
@Deprecated public static final java.lang.String NASTY_SMALL_DOUBLE
Deprecated.Since 2.14 -- do not useFormerly used constant for a value that was problematic on certain pre-1.8 JDKs.- See Also:
 - Constant Field Values
 
 
 - 
 
- 
Method Detail
- 
parseInt
public static int parseInt(char[] ch, int off, int len)Fast method for parsing unsigned integers that are known to fit into regular 32-bit signed int type. This means that length is between 1 and 9 digits (inclusive) and there is no sign character.Note: public to let unit tests call it; not meant to be used by any code outside this package.
- Parameters:
 ch- Buffer that contains integer value to decodeoff- Offset of the first digit character in bufferlen- Length of the number to decode (in characters)- Returns:
 - Decoded 
intvalue 
 
- 
parseInt
public static int parseInt(java.lang.String s)
Helper method to (more) efficiently parse integer numbers from String values. Input String must be simple Java integer value. No range checks are made to verify that the value fits in 32-bit Javaint: caller is expected to only calls this in cases where this can be guaranteed (basically: number of digits does not exceed 9)NOTE: semantics differ significantly from
parseInt(char[], int, int).- Parameters:
 s- String that contains integer value to decode- Returns:
 - Decoded 
intvalue 
 
- 
parseLong
public static long parseLong(char[] ch, int off, int len) 
- 
parseLong19
public static long parseLong19(char[] ch, int off, boolean negative)Parses an unsigned long made up of exactly 19 digits.It is the callers responsibility to make sure the input is exactly 19 digits. and fits into a 64bit long by calling
inLongRange(char[], int, int, boolean)first.Note that input String must NOT contain leading minus sign (even if
negativeis set to true).- Parameters:
 ch- Buffer that contains integer value to decodeoff- Offset of the first digit character in buffernegative- Whether original number had a minus sign- Returns:
 - Decoded 
longvalue - Since:
 - 2.15.0
 
 
- 
parseLong
public static long parseLong(java.lang.String s)
Similar toparseInt(String)but forlongvalues.- Parameters:
 s- String that containslongvalue to decode- Returns:
 - Decoded 
longvalue 
 
- 
inLongRange
public static boolean inLongRange(char[] ch, int off, int len, boolean negative)Helper method for determining if given String representation of an integral number would fit in 64-bit Java long or not. Note that input String must NOT contain leading minus sign (even if 'negative' is set to true).- Parameters:
 ch- Buffer that contains long value to checkoff- Offset of the first digit character in bufferlen- Length of the number to decode (in characters)negative- Whether original number had a minus sign (which is NOT passed to this method) or not- Returns:
 Trueif specified String representation is within Javalongrange;falseif not.
 
- 
inLongRange
public static boolean inLongRange(java.lang.String s, boolean negative)Similar toinLongRange(char[],int,int,boolean), but with String argument- Parameters:
 s- String that containslongvalue to checknegative- Whether original number had a minus sign (which is NOT passed to this method) or not- Returns:
 Trueif specified String representation is within Javalongrange;falseif not.
 
- 
parseAsInt
public static int parseAsInt(java.lang.String s, int def) 
- 
parseAsLong
public static long parseAsLong(java.lang.String s, long def) 
- 
parseAsDouble
public static double parseAsDouble(java.lang.String s, double def)- Parameters:
 s- a string representing a number to parsedef- the default to return if `s` is not a parseable number- Returns:
 - closest matching double (or `def` if there is an issue with `s`) where useFastParser=false
 - See Also:
 parseAsDouble(String, double, boolean)
 
- 
parseAsDouble
public static double parseAsDouble(java.lang.String s, double def, boolean useFastParser)- Parameters:
 s- a string representing a number to parsedef- the default to return if `s` is not a parseable numberuseFastParser- whether to useFastDoubleParser- Returns:
 - closest matching double (or `def` if there is an issue with `s`)
 - Since:
 - 2.14
 
 
- 
parseDouble
@Deprecated public static double parseDouble(java.lang.String s) throws java.lang.NumberFormatExceptionDeprecated.Since 2.17 useparseDouble(String, boolean)instead- Parameters:
 s- a string representing a number to parse- Returns:
 - closest matching double
 - Throws:
 java.lang.NumberFormatException- if string cannot be represented by a double where useFastParser=false- See Also:
 parseDouble(String, boolean)
 
- 
parseDouble
public static double parseDouble(java.lang.String s, boolean useFastParser) throws java.lang.NumberFormatException- Parameters:
 s- a string representing a number to parseuseFastParser- whether to useFastDoubleParser- Returns:
 - closest matching double
 - Throws:
 java.lang.NumberFormatException- if string cannot be represented by a double- Since:
 - v2.14
 
 
- 
parseFloat
@Deprecated public static float parseFloat(java.lang.String s) throws java.lang.NumberFormatExceptionDeprecated.Since 2.17 useparseFloat(String, boolean)instead- Parameters:
 s- a string representing a number to parse- Returns:
 - closest matching float
 - Throws:
 java.lang.NumberFormatException- if string cannot be represented by a float where useFastParser=false- Since:
 - v2.14
 - See Also:
 parseFloat(String, boolean)
 
- 
parseFloat
public static float parseFloat(java.lang.String s, boolean useFastParser) throws java.lang.NumberFormatException- Parameters:
 s- a string representing a number to parseuseFastParser- whether to useFastDoubleParser- Returns:
 - closest matching float
 - Throws:
 java.lang.NumberFormatException- if string cannot be represented by a float- Since:
 - v2.14
 
 
- 
parseBigDecimal
@Deprecated public static java.math.BigDecimal parseBigDecimal(java.lang.String s) throws java.lang.NumberFormatExceptionDeprecated.Since 2.17 useparseBigDecimal(String, boolean)instead- Parameters:
 s- a string representing a number to parse- Returns:
 - a BigDecimal
 - Throws:
 java.lang.NumberFormatException- if the char array cannot be represented by a BigDecimal
 
- 
parseBigDecimal
public static java.math.BigDecimal parseBigDecimal(java.lang.String s, boolean useFastParser) throws java.lang.NumberFormatException- Parameters:
 s- a string representing a number to parseuseFastParser- whether to use custom fast parser (true) or JDK default (false) parser- Returns:
 - a BigDecimal
 - Throws:
 java.lang.NumberFormatException- if the char array cannot be represented by a BigDecimal- Since:
 - v2.15
 
 
- 
parseBigDecimal
@Deprecated public static java.math.BigDecimal parseBigDecimal(char[] ch, int off, int len) throws java.lang.NumberFormatExceptionDeprecated.Since 2.17 useparseBigDecimal(char[], int, int, boolean)instead- Parameters:
 ch- a char array with text that makes up a numberoff- the offset to apply when parsing the number in the char arraylen- the length of the number in the char array- Returns:
 - a BigDecimal
 - Throws:
 java.lang.NumberFormatException- if the char array cannot be represented by a BigDecimal
 
- 
parseBigDecimal
public static java.math.BigDecimal parseBigDecimal(char[] ch, int off, int len, boolean useFastParser) throws java.lang.NumberFormatException- Parameters:
 ch- a char array with text that makes up a numberoff- the offset to apply when parsing the number in the char arraylen- the length of the number in the char arrayuseFastParser- whether to use custom fast parser (true) or JDK default (false) parser- Returns:
 - a BigDecimal
 - Throws:
 java.lang.NumberFormatException- if the char array cannot be represented by a BigDecimal- Since:
 - v2.15
 
 
- 
parseBigDecimal
@Deprecated public static java.math.BigDecimal parseBigDecimal(char[] ch) throws java.lang.NumberFormatExceptionDeprecated.Since 2.17 useparseBigDecimal(char[], boolean)instead- Parameters:
 ch- a char array with text that makes up a number- Returns:
 - a BigDecimal
 - Throws:
 java.lang.NumberFormatException- if the char array cannot be represented by a BigDecimal
 
- 
parseBigDecimal
public static java.math.BigDecimal parseBigDecimal(char[] ch, boolean useFastParser) throws java.lang.NumberFormatException- Parameters:
 ch- a char array with text that makes up a numberuseFastParser- whether to use custom fast parser (true) or JDK default (false) parser- Returns:
 - a BigDecimal
 - Throws:
 java.lang.NumberFormatException- if the char array cannot be represented by a BigDecimal- Since:
 - v2.15
 
 
- 
parseBigInteger
@Deprecated public static java.math.BigInteger parseBigInteger(java.lang.String s) throws java.lang.NumberFormatExceptionDeprecated.Since 2.17 useparseBigInteger(String, boolean)instead- Parameters:
 s- a string representing a number to parse- Returns:
 - a BigInteger
 - Throws:
 java.lang.NumberFormatException- if string cannot be represented by a BigInteger- Since:
 - v2.14
 
 
- 
parseBigInteger
public static java.math.BigInteger parseBigInteger(java.lang.String s, boolean useFastParser) throws java.lang.NumberFormatException- Parameters:
 s- a string representing a number to parseuseFastParser- whether to use custom fast parser (true) or JDK default (false) parser- Returns:
 - a BigInteger
 - Throws:
 java.lang.NumberFormatException- if string cannot be represented by a BigInteger- Since:
 - v2.15
 
 
- 
parseBigIntegerWithRadix
public static java.math.BigInteger parseBigIntegerWithRadix(java.lang.String s, int radix, boolean useFastParser) throws java.lang.NumberFormatException- Parameters:
 s- a string representing a number to parseradix- for parseuseFastParser- whether to use custom fast parser (true) or JDK default (false) parser- Returns:
 - a BigInteger
 - Throws:
 java.lang.NumberFormatException- if string cannot be represented by a BigInteger- Since:
 - v2.15
 
 
- 
looksLikeValidNumber
public static boolean looksLikeValidNumber(java.lang.String s)
Method called to check whether given pattern looks like a valid Java Number (which is bit looser definition than valid JSON Number). Used as pre-parsing check when parsing "Stringified numbers".The differences to stricter JSON Number are:
- Positive sign is allowed
 - Leading zeroes are allowed
 
Note: no trimming (
String.trim()) nor null checks are performed on String passed.Note: this method returning
trueDOES NOT GUARANTEE String is valid number but just that it looks close enough.- Parameters:
 s- String to validate- Returns:
 - True if String looks like valid Java number; false otherwise.
 - Since:
 - 2.17
 
 
 - 
 
 -