Class Numbers
- java.lang.Object
-
- org.apache.druid.java.util.common.Numbers
-
public final class Numbers extends Object
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanparseBoolean(Object val)Parse the given object as aboolean.static DoubleparseDoubleObject(String val)LiketryParseDouble(java.lang.Object, double), but does not produce a primitive and will explode if unable to produce a Double similar toDouble.parseDouble(java.lang.String)static intparseInt(Object val)Parse the given object as aint.static longparseLong(Object val)Parse the given object as along.static LongparseLongObject(String val)LiketryParseLong(java.lang.Object, long)but does not produce a primitive and will explode if unable to produce a Long similar toLong.parseLong(java.lang.String, int)static doubletryParseDouble(Object val, double nullValue)Try parsing the given Number or String object val as double.static floattryParseFloat(Object val, float nullValue)Try parsing the given Number or String object val as float.static longtryParseLong(Object val, long nullValue)Try parsing the given Number or String object val as long.
-
-
-
Method Detail
-
parseLong
public static long parseLong(Object val)
Parse the given object as along. The input object can be aStringor one of the implementations ofNumber. You may want to useGuavaUtils.tryParseLong()instead if the input is a nullable string and you want to avoid any exceptions.- Throws:
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.
-
parseInt
public static int parseInt(Object val)
Parse the given object as aint. The input object can be aStringor one of the implementations ofNumber.- Throws:
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.
-
parseBoolean
public static boolean parseBoolean(Object val)
- Returns:
trueonly if the input is aBooleanrepresentingtrueor aStringof"true".- Throws:
NullPointerException- if the input is null.ISE- if the input is not a string or a number.
-
tryParseDouble
public static double tryParseDouble(@Nullable Object val, double nullValue)
Try parsing the given Number or String object val as double.- Parameters:
val-nullValue- value to return when input was string type but not parseable into double value- Returns:
- parsed double value
-
tryParseLong
public static long tryParseLong(@Nullable Object val, long nullValue)
Try parsing the given Number or String object val as long.- Parameters:
val-nullValue- value to return when input was string type but not parseable into long value- Returns:
- parsed long value
-
tryParseFloat
public static float tryParseFloat(@Nullable Object val, float nullValue)
Try parsing the given Number or String object val as float.- Parameters:
val-nullValue- value to return when input was string type but not parseable into float value- Returns:
- parsed float value
-
parseDoubleObject
@Nullable public static Double parseDoubleObject(@Nullable String val)
LiketryParseDouble(java.lang.Object, double), but does not produce a primitive and will explode if unable to produce a Double similar toDouble.parseDouble(java.lang.String)
-
parseLongObject
@Nullable public static Long parseLongObject(@Nullable String val)
LiketryParseLong(java.lang.Object, long)but does not produce a primitive and will explode if unable to produce a Long similar toLong.parseLong(java.lang.String, int)
-
-