Package org.elasticsearch.common
Class Numbers
java.lang.Object
org.elasticsearch.common.Numbers
A set of utilities for numbers.
- 
Method SummaryModifier and TypeMethodDescriptionstatic intbytesToInt(byte[] bytes, int offset)static longbytesToLong(byte[] bytes, int offset)static longbytesToLong(org.apache.lucene.util.BytesRef bytes)static shortbytesToShort(byte[] bytes, int offset)static byte[]doubleToBytes(double val)Converts a double to a byte array.static byte[]intToBytes(int val)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(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(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 longReturn 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(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(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 Details- 
bytesToShortpublic static short bytesToShort(byte[] bytes, int offset)
- 
bytesToIntpublic static int bytesToInt(byte[] bytes, int offset)
- 
bytesToLongpublic static long bytesToLong(byte[] bytes, int offset)
- 
bytesToLongpublic static long bytesToLong(org.apache.lucene.util.BytesRef bytes)
- 
intToBytespublic static byte[] intToBytes(int val)
- 
shortToBytespublic 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
 
- 
longToBytespublic 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
 
- 
doubleToBytespublic 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
 
- 
isValidDoublepublic static boolean isValidDouble(double value)Returns true if value is neither NaN nor infinite.
- 
toLongExactReturn the long thatnstores, or throws an exception if the stored value cannot be converted to a long that stores the exact same value.
- 
toLongReturn 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.
- 
toIntExactReturn the int thatnstores, or throws an exception if the stored value cannot be converted to an int that stores the exact same value.
- 
toShortExactReturn the short thatnstores, or throws an exception if the stored value cannot be converted to a short that stores the exact same value.
- 
toByteExactReturn the byte thatnstores, or throws an exception if the stored value cannot be converted to a byte that stores the exact same value.
 
-