Class Numbers
java.lang.Object
org.apache.druid.java.util.common.Numbers
-
Method Summary
Modifier and TypeMethodDescriptionstatic 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 intParse the given object as aint.static longParse 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 Details
-
parseLong
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
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
- 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
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
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
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
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
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)
-