Class HashCode

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, java.lang.Comparable

    public final class HashCode
    extends java.lang.Object
    implements java.io.Serializable, java.lang.Cloneable, java.lang.Comparable
    A hash-code generator and a collection of static hash-code generation methods.
    Version:
    $Revision$
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static int FALSE_HASHCODE
      Hashcode for a 'false' boolean
      private static int NULL_HASHCODE
      Hashcode for a 'null' value.
      private static long serialVersionUID
      The serialVersionUID
      private static int TRUE_HASHCODE
      Hashcode for a 'true' boolean
      private int value
      The hash-code value.
    • Constructor Summary

      Constructors 
      Constructor Description
      HashCode()
      Construct a new HashCode.
      HashCode​(int value)
      Construct a new HashCode using the given int as the base value.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      HashCode add​(boolean b)
      Add the hash-code of the given value.
      HashCode add​(byte n)
      Add the hash-code of the given value.
      HashCode add​(char n)
      Add the hash-code of the given value.
      HashCode add​(double f)
      Add the hash-code of the given value.
      HashCode add​(float f)
      Add the hash-code of the given value.
      HashCode add​(int n)
      Add the hash-code of the given value.
      HashCode add​(long n)
      Add the hash-code of the given value.
      HashCode add​(short n)
      Add the hash-code of the given value.
      HashCode add​(java.lang.Object obj)
      Add the hash-code of the given object.
      java.lang.Object clone()
      Return a cloned copy of this HashCode.
      int compareTo​(int other)
      Compares this object with the specified int for order.
      int compareTo​(java.lang.Object obj)
      Compares this object with the specified object for order.
      boolean equals​(java.lang.Object obj)
      Test the equality of this HashCode and another object.
      static int generate​(boolean value)
      Generate a hash code for a boolean value.
      static int generate​(byte[] bytes)
      Generate a hash code for a byte array.
      static int generate​(double value)
      Generate a hash code for a double value.
      static int generate​(float value)
      Generate a hash code for a float value.
      static int generate​(long value)
      Generate a hash code for a long value.
      static int generate​(java.lang.Object obj)
      Generate a hash code for an object.
      static int generate​(java.lang.Object[] array)
      Generate a shallow hash code for an object array.
      static int generate​(java.lang.Object[] array, boolean deep)
      Generate a hash code for an object array.
      int hashCode()
      Get the hash-code.
      java.lang.String toString()
      Return a string representation of this HashCode.
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        The serialVersionUID
        See Also:
        Constant Field Values
      • NULL_HASHCODE

        private static final int NULL_HASHCODE
        Hashcode for a 'null' value.
        See Also:
        Constant Field Values
      • TRUE_HASHCODE

        private static final int TRUE_HASHCODE
        Hashcode for a 'true' boolean
        See Also:
        Constant Field Values
      • FALSE_HASHCODE

        private static final int FALSE_HASHCODE
        Hashcode for a 'false' boolean
        See Also:
        Constant Field Values
      • value

        private int value
        The hash-code value.
    • Constructor Detail

      • HashCode

        public HashCode​(int value)
        Construct a new HashCode using the given int as the base value.
        Parameters:
        value - int to use as the base value.
      • HashCode

        public HashCode()
        Construct a new HashCode.
    • Method Detail

      • add

        public HashCode add​(boolean b)
        Add the hash-code of the given value.
        Parameters:
        b - Value to get hash-code from.
        Returns:
        This HashCode.
      • add

        public HashCode add​(byte n)
        Add the hash-code of the given value.
        Parameters:
        n - Value to get hash-code from.
        Returns:
        This HashCode.
      • add

        public HashCode add​(char n)
        Add the hash-code of the given value.
        Parameters:
        n - Value to get hash-code from.
        Returns:
        This HashCode.
      • add

        public HashCode add​(short n)
        Add the hash-code of the given value.
        Parameters:
        n - Value to get hash-code from.
        Returns:
        This HashCode.
      • add

        public HashCode add​(int n)
        Add the hash-code of the given value.
        Parameters:
        n - Value to get hash-code from.
        Returns:
        This HashCode.
      • add

        public HashCode add​(long n)
        Add the hash-code of the given value.
        Parameters:
        n - Value to get hash-code from.
        Returns:
        This HashCode.
      • add

        public HashCode add​(float f)
        Add the hash-code of the given value.
        Parameters:
        f - Value to get hash-code from.
        Returns:
        This HashCode.
      • add

        public HashCode add​(double f)
        Add the hash-code of the given value.
        Parameters:
        f - Value to get hash-code from.
        Returns:
        This HashCode.
      • add

        public HashCode add​(java.lang.Object obj)
        Add the hash-code of the given object.
        Parameters:
        obj - Value to get hash-code from.
        Returns:
        This HashCode.
      • hashCode

        public int hashCode()
        Get the hash-code.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        Hash-code.
      • compareTo

        public int compareTo​(int other)
        Compares this object with the specified int for order.
        Parameters:
        other - Value to compare with.
        Returns:
        A negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
      • compareTo

        public int compareTo​(java.lang.Object obj)
                      throws java.lang.ClassCastException
        Compares this object with the specified object for order.
        Specified by:
        compareTo in interface java.lang.Comparable
        Parameters:
        obj - Value to compare with.
        Returns:
        A negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.
        Throws:
        java.lang.ClassCastException - Object is not a HashCode.
      • equals

        public boolean equals​(java.lang.Object obj)
        Test the equality of this HashCode and another object.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - Object to test equality with.
        Returns:
        True if object is equal.
      • toString

        public java.lang.String toString()
        Return a string representation of this HashCode.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string representation of this HashCode.
      • clone

        public java.lang.Object clone()
        Return a cloned copy of this HashCode.
        Overrides:
        clone in class java.lang.Object
        Returns:
        Cloned HashCode.
      • generate

        public static int generate​(boolean value)
        Generate a hash code for a boolean value.
        Parameters:
        value - Boolean value to generate hash code from.
        Returns:
        Hash code.
      • generate

        public static int generate​(long value)
        Generate a hash code for a long value.
        Parameters:
        value - Long value to generate hash code from.
        Returns:
        Hash code.
      • generate

        public static int generate​(double value)
        Generate a hash code for a double value.
        Parameters:
        value - Double value to generate hash code from.
        Returns:
        Hash code.
      • generate

        public static int generate​(float value)
        Generate a hash code for a float value.
        Parameters:
        value - Float value to generate hash code from.
        Returns:
        Hash code.
      • generate

        public static int generate​(byte[] bytes)
        Generate a hash code for a byte array.
        Parameters:
        bytes - An array of bytes to generate a hash code from.
        Returns:
        Hash code.
      • generate

        public static int generate​(java.lang.Object[] array,
                                   boolean deep)
        Generate a hash code for an object array.

        Does not handle nested primitive array elements.

        Parameters:
        array - Array to generate hashcode for.
        deep - True to traverse elements which are arrays to determine the elements hash code.
        Returns:
        Hash code.
      • generate

        public static int generate​(java.lang.Object[] array)
        Generate a shallow hash code for an object array.
        Parameters:
        array - Array to generate hashcode for.
        Returns:
        Hash code.
      • generate

        public static int generate​(java.lang.Object obj)
        Generate a hash code for an object.
        Parameters:
        obj - Object to generate hashcode for.
        Returns:
        Hash code.