Class Longs


  • public class Longs
    extends java.lang.Object
    Utilities for manipulating long objects.
    Author:
    Garret Wilson
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static long[] NO_LONGS
      The shared empty array of longs.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static int compare​(long l1, long l2)
      Compares two longs for order.
      static int hashCode​(long value)
      Returns a hash code for a long value.
      static java.lang.String toHexString​(long value, int length)
      Converts a long into a hex string with the specified number of digits.
      static int toInt​(long value)
      Converts a long value to an integer, checking for overflow.
      • Methods inherited from class java.lang.Object

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

      • NO_LONGS

        public static final long[] NO_LONGS
        The shared empty array of longs.
    • Method Detail

      • hashCode

        public static int hashCode​(long value)
        Returns a hash code for a long value. This implementation returns the same value used by Long.hashCode().
        Parameters:
        value - The value for which a hash code should be returned.
        Returns:
        The hash code of the long value.
      • toHexString

        public static java.lang.String toHexString​(long value,
                                                   int length)
        Converts a long into a hex string with the specified number of digits.
        Parameters:
        value - The value to convert.
        length - The number of digits the returned string should have.
        Returns:
        Lowercase hex version of the given value with the correct number of digits, using zeros to pad the left of the string to the correct length.
      • toInt

        public static int toInt​(long value)
        Converts a long value to an integer, checking for overflow.
        Parameters:
        value - The value to convert.
        Returns:
        The long value as an integer.
        Throws:
        java.lang.IllegalArgumentException - if the given value is smaller than Integer.MIN_VALUE or greater than Integer.MAX_VALUE.
      • compare

        public static int compare​(long l1,
                                  long l2)
        Compares two longs for order.
        Parameters:
        l1 - The first long to compare.
        l2 - The second long to compare.
        Returns:
        a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.