org.jboss.util
Class HashCode

java.lang.Object
  extended byorg.jboss.util.HashCode
All Implemented Interfaces:
java.lang.Cloneable, java.lang.Comparable, java.io.Serializable

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.

See Also:
Serialized Form

Constructor Summary
HashCode()
          Construct a new HashCode.
HashCode(int value)
          Construct a new HashCode using the given int as the base value.
 
Method Summary
 HashCode (src) add(boolean b)
          Add the hash-code of the given value.
 HashCode (src) add(byte n)
          Add the hash-code of the given value.
 HashCode (src) add(char n)
          Add the hash-code of the given value.
 HashCode (src) add(double f)
          Add the hash-code of the given value.
 HashCode (src) add(float f)
          Add the hash-code of the given value.
 HashCode (src) add(int n)
          Add the hash-code of the given value.
 HashCode (src) add(long n)
          Add the hash-code of the given value.
 HashCode (src) add(java.lang.Object obj)
          Add the hash-code of the given object.
 HashCode (src) add(short n)
          Add the hash-code of the given value.
 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
 

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 (src)  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 (src)  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 (src)  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 (src)  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 (src)  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 (src)  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 (src)  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 (src)  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 (src)  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.

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
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.

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.

Returns:
A string representation of this HashCode.

clone

public java.lang.Object clone()
Return a cloned copy of this HashCode.

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.