Package com.fasterxml.jackson.core.io
Class NumberInput
- java.lang.Object
-
- com.fasterxml.jackson.core.io.NumberInput
-
public final class NumberInput extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
NASTY_SMALL_DOUBLE
Textual representation of a double constant that can cause nasty problems with JDK (see http://www.exploringbinary.com/java-hangs-when-converting-2-2250738585072012e-308).
-
Constructor Summary
Constructors Constructor Description NumberInput()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description 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.static boolean
inLongRange(java.lang.String s, boolean negative)
Similar toinLongRange(char[],int,int,boolean)
, but with String argumentstatic double
parseAsDouble(java.lang.String s, double def)
static int
parseAsInt(java.lang.String s, int def)
static long
parseAsLong(java.lang.String s, long def)
static java.math.BigDecimal
parseBigDecimal(char[] ch)
static java.math.BigDecimal
parseBigDecimal(char[] ch, int off, int len)
static java.math.BigDecimal
parseBigDecimal(java.lang.String s)
static double
parseDouble(java.lang.String s)
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.static int
parseInt(java.lang.String s)
Helper method to (more) efficiently parse integer numbers from String values.static long
parseLong(char[] ch, int off, int len)
static long
parseLong(java.lang.String s)
Similar toparseInt(String)
but forlong
values.
-
-
-
Field Detail
-
NASTY_SMALL_DOUBLE
public static final java.lang.String NASTY_SMALL_DOUBLE
Textual representation of a double constant that can cause nasty problems with JDK (see http://www.exploringbinary.com/java-hangs-when-converting-2-2250738585072012e-308).- 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
int
value
-
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
int
value
-
parseLong
public static long parseLong(char[] ch, int off, int len)
-
parseLong
public static long parseLong(java.lang.String s)
Similar toparseInt(String)
but forlong
values.- Parameters:
s
- String that containslong
value to decode- Returns:
- Decoded
long
value
-
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:
True
if specified String representation is within Javalong
range;false
if 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 containslong
value to checknegative
- Whether original number had a minus sign (which is NOT passed to this method) or not- Returns:
True
if specified String representation is within Javalong
range;false
if 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)
-
parseDouble
public static double parseDouble(java.lang.String s) throws java.lang.NumberFormatException
- Throws:
java.lang.NumberFormatException
-
parseBigDecimal
public static java.math.BigDecimal parseBigDecimal(java.lang.String s) throws java.lang.NumberFormatException
- Throws:
java.lang.NumberFormatException
-
parseBigDecimal
public static java.math.BigDecimal parseBigDecimal(char[] ch, int off, int len) throws java.lang.NumberFormatException
- Throws:
java.lang.NumberFormatException
-
parseBigDecimal
public static java.math.BigDecimal parseBigDecimal(char[] ch) throws java.lang.NumberFormatException
- Throws:
java.lang.NumberFormatException
-
-