Package org.opensearch.common
Class Numbers
java.lang.Object
org.opensearch.common.Numbers
A set of utilities for numbers.
- Opensearch.internal:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final BigIntegerstatic final longstatic final BigIntegerstatic final long -
Method Summary
Modifier and TypeMethodDescriptionstatic 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 BigIntegerReturn theBigIntegerthatnstores, or throws an exception if the stored value cannot be converted to aBigIntegerthat stores the exact same value.static byteReturn 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 longReturn the long thatnstores, or throws an exception if the stored value cannot be converted to a long that stores the exact same value.static shortReturn the short thatnstores, or throws an exception if the stored value cannot be converted to a short that stores the exact same value.static BigIntegertoUnsignedBigInteger(long i) Return a BigInteger equal to the unsigned value of the argument.static BigIntegertoUnsignedLong(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 BigIntegertoUnsignedLongExact(Number value) Return the unsigned long (asBigInteger) thatnstores, or throws an exception if the stored value cannot be converted to an unsigned long that stores the exact same value.static doubleunsignedLongToDouble(long value) Convert unsigned long to double value (see please Guava's com.google.common.primitives.UnsignedLong), this is faster then going throughtoUnsignedBigInteger(long)conversion.
-
Field Details
-
MAX_UNSIGNED_LONG_VALUE
-
MIN_UNSIGNED_LONG_VALUE
-
MIN_UNSIGNED_LONG_VALUE_AS_LONG
public static final long MIN_UNSIGNED_LONG_VALUE_AS_LONG -
MAX_UNSIGNED_LONG_VALUE_AS_LONG
public static final long MAX_UNSIGNED_LONG_VALUE_AS_LONG
-
-
Method Details
-
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
-
isValidDouble
public static boolean isValidDouble(double value) Returns true if value is neither NaN nor infinite. -
toLongExact
Return the long thatnstores, or throws an exception if the stored value cannot be converted to a long that stores the exact same value. -
toBigIntegerExact
Return theBigIntegerthatnstores, or throws an exception if the stored value cannot be converted to aBigIntegerthat stores the exact same value. -
toUnsignedLongExact
Return the unsigned long (asBigInteger) thatnstores, or throws an exception if the stored value cannot be converted to an unsigned long that stores the exact same value. -
toLong
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. -
toUnsignedLong
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
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
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
Return the byte thatnstores, or throws an exception if the stored value cannot be converted to a byte that stores the exact same value. -
toUnsignedBigInteger
Return a BigInteger equal to the unsigned value of the argument. -
unsignedLongToDouble
public static double unsignedLongToDouble(long value) Convert unsigned long to double value (see please Guava's com.google.common.primitives.UnsignedLong), this is faster then going throughtoUnsignedBigInteger(long)conversion.
-