public final class Numbers extends Object
| Modifier and Type | Method and Description |
|---|---|
static boolean |
parseBoolean(Object val)
Parse the given object as a
boolean. |
static Double |
parseDoubleObject(String val)
Like
tryParseDouble(java.lang.Object, double), but does not produce a primitive and will explode if unable to produce a Double
similar to Double.parseDouble(java.lang.String) |
static int |
parseInt(Object val)
Parse the given object as a
int. |
static long |
parseLong(Object val)
Parse the given object as a
long. |
static Long |
parseLongObject(String val)
Like
tryParseLong(java.lang.Object, long) but does not produce a primitive and will explode if unable to produce a Long
similar to Long.parseLong(java.lang.String, int) |
static double |
tryParseDouble(Object val,
double nullValue)
Try parsing the given Number or String object val as double.
|
static float |
tryParseFloat(Object val,
float nullValue)
Try parsing the given Number or String object val as float.
|
static long |
tryParseLong(Object val,
long nullValue)
Try parsing the given Number or String object val as long.
|
public static long parseLong(Object val)
long. The input object can be a String or one of the implementations of
Number. You may want to use GuavaUtils.tryParseLong() instead if the input is a nullable string and
you want to avoid any exceptions.NumberFormatException - if the input is an unparseable string.NullPointerException - if the input is null.ISE - if the input is not a string or a number.public static int parseInt(Object val)
int. The input object can be a String or one of the implementations of
Number.NumberFormatException - if the input is an unparseable string.NullPointerException - if the input is null.ISE - if the input is not a string or a number.public static boolean parseBoolean(Object val)
true only if the input is a Boolean representing true or a String of
"true".NullPointerException - if the input is null.ISE - if the input is not a string or a number.public static double tryParseDouble(@Nullable Object val, double nullValue)
val - nullValue - value to return when input was string type but not parseable into double valuepublic static long tryParseLong(@Nullable Object val, long nullValue)
val - nullValue - value to return when input was string type but not parseable into long valuepublic static float tryParseFloat(@Nullable Object val, float nullValue)
val - nullValue - value to return when input was string type but not parseable into float value@Nullable public static Double parseDoubleObject(@Nullable String val)
tryParseDouble(java.lang.Object, double), but does not produce a primitive and will explode if unable to produce a Double
similar to Double.parseDouble(java.lang.String)@Nullable public static Long parseLongObject(@Nullable String val)
tryParseLong(java.lang.Object, long) but does not produce a primitive and will explode if unable to produce a Long
similar to Long.parseLong(java.lang.String, int)Copyright © 2011–2023 The Apache Software Foundation. All rights reserved.