Package org.jboss.util
Class HashCode
- java.lang.Object
-
- org.jboss.util.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.ComparableA 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 intFALSE_HASHCODEHashcode for a 'false' booleanprivate static intNULL_HASHCODEHashcode for a 'null' value.private static longserialVersionUIDThe serialVersionUIDprivate static intTRUE_HASHCODEHashcode for a 'true' booleanprivate intvalueThe hash-code value.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description HashCodeadd(boolean b)Add the hash-code of the given value.HashCodeadd(byte n)Add the hash-code of the given value.HashCodeadd(char n)Add the hash-code of the given value.HashCodeadd(double f)Add the hash-code of the given value.HashCodeadd(float f)Add the hash-code of the given value.HashCodeadd(int n)Add the hash-code of the given value.HashCodeadd(long n)Add the hash-code of the given value.HashCodeadd(short n)Add the hash-code of the given value.HashCodeadd(java.lang.Object obj)Add the hash-code of the given object.java.lang.Objectclone()Return a cloned copy of this HashCode.intcompareTo(int other)Compares this object with the specified int for order.intcompareTo(java.lang.Object obj)Compares this object with the specified object for order.booleanequals(java.lang.Object obj)Test the equality of this HashCode and another object.static intgenerate(boolean value)Generate a hash code for a boolean value.static intgenerate(byte[] bytes)Generate a hash code for a byte array.static intgenerate(double value)Generate a hash code for a double value.static intgenerate(float value)Generate a hash code for a float value.static intgenerate(long value)Generate a hash code for a long value.static intgenerate(java.lang.Object obj)Generate a hash code for an object.static intgenerate(java.lang.Object[] array)Generate a shallow hash code for an object array.static intgenerate(java.lang.Object[] array, boolean deep)Generate a hash code for an object array.inthashCode()Get the hash-code.java.lang.StringtoString()Return a string representation of this HashCode.
-
-
-
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.
-
-
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:
hashCodein classjava.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.ClassCastExceptionCompares this object with the specified object for order.- Specified by:
compareToin interfacejava.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:
equalsin classjava.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:
toStringin classjava.lang.Object- Returns:
- A string representation of this HashCode.
-
clone
public java.lang.Object clone()
Return a cloned copy of this HashCode.- Overrides:
clonein classjava.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.
-
-