Class Numbers

java.lang.Object
org.opensearch.common.Numbers

public final class Numbers extends Object
A set of utilities for numbers.
Opensearch.internal:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final BigInteger
     
    static final long
     
    static final BigInteger
     
    static final long
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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 BigInteger
    Return the BigInteger that n stores, or throws an exception if the stored value cannot be converted to a BigInteger that stores the exact same value.
    static byte
    Return the byte that n stores, or throws an exception if the stored value cannot be converted to a byte that stores the exact same value.
    static int
    Return the int that n stores, or throws an exception if the stored value cannot be converted to an int that stores the exact same value.
    static long
    toLong(String stringValue, boolean coerce)
    Return the long that stringValue stores or throws an exception if the stored value cannot be converted to a long that stores the exact same value and coerce is false.
    static long
    Return the long that n stores, or throws an exception if the stored value cannot be converted to a long that stores the exact same value.
    static short
    Return the short that n stores, or throws an exception if the stored value cannot be converted to a short that stores the exact same value.
    static BigInteger
    Return a BigInteger equal to the unsigned value of the argument.
    static BigInteger
    toUnsignedLong(String stringValue, boolean coerce)
    Return the long that stringValue stores or throws an exception if the stored value cannot be converted to a long that stores the exact same value and coerce is false.
    static BigInteger
    Return the unsigned long (as BigInteger) that n stores, or throws an exception if the stored value cannot be converted to an unsigned long that stores the exact same value.
    static double
    Convert unsigned long to double value (see please Guava's com.google.common.primitives.UnsignedLong), this is faster then going through toUnsignedBigInteger(long) conversion.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • MAX_UNSIGNED_LONG_VALUE

      public static final BigInteger MAX_UNSIGNED_LONG_VALUE
    • MIN_UNSIGNED_LONG_VALUE

      public static final BigInteger 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

      public static long toLongExact(Number n)
      Return the long that n stores, or throws an exception if the stored value cannot be converted to a long that stores the exact same value.
    • toBigIntegerExact

      public static BigInteger toBigIntegerExact(Number n)
      Return the BigInteger that n stores, or throws an exception if the stored value cannot be converted to a BigInteger that stores the exact same value.
    • toUnsignedLongExact

      public static BigInteger toUnsignedLongExact(Number value)
      Return the unsigned long (as BigInteger) that n stores, or throws an exception if the stored value cannot be converted to an unsigned long that stores the exact same value.
    • toLong

      public static long toLong(String stringValue, boolean coerce)
      Return the long that stringValue stores or throws an exception if the stored value cannot be converted to a long that stores the exact same value and coerce is false.
    • toUnsignedLong

      public static BigInteger toUnsignedLong(String stringValue, boolean coerce)
      Return the long that stringValue stores or throws an exception if the stored value cannot be converted to a long that stores the exact same value and coerce is false.
    • toIntExact

      public static int toIntExact(Number n)
      Return the int that n stores, 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(Number n)
      Return the short that n stores, 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(Number n)
      Return the byte that n stores, or throws an exception if the stored value cannot be converted to a byte that stores the exact same value.
    • toUnsignedBigInteger

      public static BigInteger toUnsignedBigInteger(long i)
      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 through toUnsignedBigInteger(long) conversion.