Package org.elasticsearch.common
Class Numbers
java.lang.Object
org.elasticsearch.common.Numbers
A set of utilities for numbers.
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
bytesToInt(byte[] bytes, int offset)
static long
bytesToLong(byte[] bytes, int offset)
static long
bytesToLong(org.apache.lucene.util.BytesRef bytes)
static short
bytesToShort(byte[] bytes, int offset)
static byte[]
doubleToBytes(double val)
Converts a double to a byte array.static byte[]
intToBytes(int val)
static boolean
isValidDouble(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 byte
toByteExact(Number n)
Return the byte thatn
stores, or throws an exception if the stored value cannot be converted to a byte that stores the exact same value.static int
toIntExact(Number n)
Return the int thatn
stores, or throws an exception if the stored value cannot be converted to an int that stores the exact same value.static long
Return the long thatstringValue
stores or throws an exception if the stored value cannot be converted to a long that stores the exact same value andcoerce
is false.static long
toLongExact(Number n)
Return the long thatn
stores, or throws an exception if the stored value cannot be converted to a long that stores the exact same value.static short
toShortExact(Number n)
Return the short thatn
stores, or throws an exception if the stored value cannot be converted to a short that stores the exact same value.
-
Method Details
-
bytesToShort
public static short bytesToShort(byte[] bytes, int offset) -
bytesToInt
public static int bytesToInt(byte[] bytes, int offset) -
bytesToLong
public static long bytesToLong(byte[] bytes, int offset) -
bytesToLong
public static long bytesToLong(org.apache.lucene.util.BytesRef bytes) -
intToBytes
public static byte[] intToBytes(int val) -
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
-
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
Return the long thatn
stores, or throws an exception if the stored value cannot be converted to a long that stores the exact same value. -
toLong
Return the long thatstringValue
stores or throws an exception if the stored value cannot be converted to a long that stores the exact same value andcoerce
is false. -
toIntExact
Return the int thatn
stores, or throws an exception if the stored value cannot be converted to an int that stores the exact same value. -
toShortExact
Return the short thatn
stores, or throws an exception if the stored value cannot be converted to a short that stores the exact same value. -
toByteExact
Return the byte thatn
stores, or throws an exception if the stored value cannot be converted to a byte that stores the exact same value.
-