Class Numbers


  • public final class Numbers
    extends java.lang.Object
    A set of utilities for numbers.
    • Method Summary

      Modifier and Type Method Description
      static long bytesToLong​(org.apache.lucene.util.BytesRef bytes)  
      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​(java.lang.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.
      static int toIntExact​(java.lang.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.
      static long toLong​(java.lang.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 toLongExact​(java.lang.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.
      static short toShortExact​(java.lang.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.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • 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

        public static long toLongExact​(java.lang.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.
      • toLong

        public static long toLong​(java.lang.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​(java.lang.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​(java.lang.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​(java.lang.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.