public final class NumberInput extends Object
Modifier and Type | Field and Description |
---|---|
static 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 and Description |
---|
NumberInput() |
Modifier and Type | Method and 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(String s,
boolean negative)
Similar to
inLongRange(char[],int,int,boolean) , but
with String argument |
static double |
parseAsDouble(String s,
double def) |
static int |
parseAsInt(String s,
int def) |
static long |
parseAsLong(String s,
long def) |
static BigDecimal |
parseBigDecimal(char[] b) |
static BigDecimal |
parseBigDecimal(char[] b,
int off,
int len) |
static BigDecimal |
parseBigDecimal(String s) |
static double |
parseDouble(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(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(String s)
Similar to
parseInt(String) but for long values. |
public static final String NASTY_SMALL_DOUBLE
public static int parseInt(char[] ch, int off, int len)
Note: public to let unit tests call it; not meant to be used by any code outside this package.
ch
- Buffer that contains integer value to decodeoff
- Offset of the first digit character in bufferlen
- Length of the number to decode (in characters)int
valuepublic static int parseInt(String s)
int
:
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)
.
s
- String that contains integer value to decodeint
valuepublic static long parseLong(char[] ch, int off, int len)
public static long parseLong(String s)
parseInt(String)
but for long
values.s
- String that contains long
value to decodelong
valuepublic static boolean inLongRange(char[] ch, int off, int len, boolean negative)
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 notTrue
if specified String representation is within Java
long
range; false
if not.public static boolean inLongRange(String s, boolean negative)
inLongRange(char[],int,int,boolean)
, but
with String arguments
- String that contains long
value to checknegative
- Whether original number had a minus sign (which is
NOT passed to this method) or notTrue
if specified String representation is within Java
long
range; false
if not.public static int parseAsInt(String s, int def)
public static long parseAsLong(String s, long def)
public static double parseAsDouble(String s, double def)
public static double parseDouble(String s) throws NumberFormatException
NumberFormatException
public static BigDecimal parseBigDecimal(String s) throws NumberFormatException
NumberFormatException
public static BigDecimal parseBigDecimal(char[] b) throws NumberFormatException
NumberFormatException
public static BigDecimal parseBigDecimal(char[] b, int off, int len) throws NumberFormatException
NumberFormatException
Copyright © 2008–2022 FasterXML. All rights reserved.