Package org.elasticsearch.common
Class Numbers
- java.lang.Object
-
- org.elasticsearch.common.Numbers
-
public final class Numbers extends java.lang.ObjectA set of utilities for numbers.
-
-
Method Summary
Modifier and Type Method Description static doublebytesToDouble(byte[] arr)Converts a byte array to double.static doublebytesToDouble(org.apache.lucene.util.BytesRef bytes)static floatbytesToFloat(byte[] arr)Converts a byte array to float.static floatbytesToFloat(org.apache.lucene.util.BytesRef bytes)static intbytesToInt(byte[] arr)Converts a byte array to an int.static intbytesToInt(org.apache.lucene.util.BytesRef bytes)static longbytesToLong(byte[] arr)Converts a byte array to a long.static longbytesToLong(org.apache.lucene.util.BytesRef bytes)static shortbytesToShort(byte[] arr)Converts a byte array to an short.static shortbytesToShort(org.apache.lucene.util.BytesRef bytes)static byte[]doubleToBytes(double val)Converts a double to a byte array.static byte[]floatToBytes(float val)Converts a float to a byte array.static byte[]intToBytes(int val)Converts an int to a byte array.static booleanisValidDouble(double value)Returns true if value is neither NaN nor infinite.static byte[]longToBytes(long val)Converts a long to a byte array.static byte[]shortToBytes(int val)Converts an int to a byte array.static bytetoByteExact(java.lang.Number n)Return the byte thatnstores, or throws an exception if the stored value cannot be converted to a byte that stores the exact same value.static inttoIntExact(java.lang.Number n)Return the int thatnstores, or throws an exception if the stored value cannot be converted to an int that stores the exact same value.static longtoLong(java.lang.String stringValue, boolean coerce)Return the long thatstringValuestores or throws an exception if the stored value cannot be converted to a long that stores the exact same value andcoerceis false.static longtoLongExact(java.lang.Number n)Return the long thatnstores, or throws an exception if the stored value cannot be converted to a long that stores the exact same value.static shorttoShortExact(java.lang.Number n)Return the short thatnstores, or throws an exception if the stored value cannot be converted to a short that stores the exact same value.
-
-
-
Method Detail
-
bytesToShort
public static short bytesToShort(byte[] arr)
Converts a byte array to an short.- Parameters:
arr- The byte array to convert to an short- Returns:
- The int converted
-
bytesToShort
public static short bytesToShort(org.apache.lucene.util.BytesRef bytes)
-
bytesToInt
public static int bytesToInt(byte[] arr)
Converts a byte array to an int.- Parameters:
arr- The byte array to convert to an int- Returns:
- The int converted
-
bytesToInt
public static int bytesToInt(org.apache.lucene.util.BytesRef bytes)
-
bytesToLong
public static long bytesToLong(byte[] arr)
Converts a byte array to a long.- Parameters:
arr- The byte array to convert to a long- Returns:
- The long converter
-
bytesToLong
public static long bytesToLong(org.apache.lucene.util.BytesRef bytes)
-
bytesToFloat
public static float bytesToFloat(byte[] arr)
Converts a byte array to float.- Parameters:
arr- The byte array to convert to a float- Returns:
- The float converted
-
bytesToFloat
public static float bytesToFloat(org.apache.lucene.util.BytesRef bytes)
-
bytesToDouble
public static double bytesToDouble(byte[] arr)
Converts a byte array to double.- Parameters:
arr- The byte array to convert to a double- Returns:
- The double converted
-
bytesToDouble
public static double bytesToDouble(org.apache.lucene.util.BytesRef bytes)
-
intToBytes
public static byte[] intToBytes(int val)
Converts an int to a byte array.- Parameters:
val- The int to convert to a byte array- Returns:
- The byte array converted
-
shortToBytes
public static byte[] shortToBytes(int val)
Converts an int to a byte array.- Parameters:
val- The int to convert to a byte array- Returns:
- The byte array converted
-
longToBytes
public static byte[] longToBytes(long val)
Converts a long to a byte array.- Parameters:
val- The long to convert to a byte array- Returns:
- The byte array converted
-
floatToBytes
public static byte[] floatToBytes(float val)
Converts a float to a byte array.- Parameters:
val- The float to convert to a byte array- Returns:
- The byte array converted
-
doubleToBytes
public static byte[] doubleToBytes(double val)
Converts a double to a byte array.- Parameters:
val- The double to convert to a byte array- Returns:
- The byte array converted
-
isValidDouble
public static boolean isValidDouble(double value)
Returns true if value is neither NaN nor infinite.
-
toLongExact
public static long toLongExact(java.lang.Number n)
Return the long thatnstores, or throws an exception if the stored value cannot be converted to a long that stores the exact same value.
-
toLong
public static long toLong(java.lang.String stringValue, boolean coerce)Return the long thatstringValuestores or throws an exception if the stored value cannot be converted to a long that stores the exact same value andcoerceis false.
-
toIntExact
public static int toIntExact(java.lang.Number n)
Return the int thatnstores, or throws an exception if the stored value cannot be converted to an int that stores the exact same value.
-
toShortExact
public static short toShortExact(java.lang.Number n)
Return the short thatnstores, or throws an exception if the stored value cannot be converted to a short that stores the exact same value.
-
toByteExact
public static byte toByteExact(java.lang.Number n)
Return the byte thatnstores, or throws an exception if the stored value cannot be converted to a byte that stores the exact same value.
-
-