|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.deduced.utilities.HashCodeUtilities
public final class HashCodeUtilities

Collected methods which allow easy implementation of hashCode.
Example use case:
public int hashCode()
{
int result = HashCodeUtilities.SEED;
//collect the contributions of various fields
result = HashCodeUtilities.hash(result, fPrimitive);
result = HashCodeUtilities.hash(result, fObject);
result = HashCodeUtilities.hash(result, fArray);
return result;
}
| Field Summary | |
|---|---|
private static int |
INITIAL_PRIME_NUMBER
a random prime number to use when merging hash codes |
static int |
INTEGER_BIT_COUNT
bit count of a Integer |
static int |
SEED
An initial value for a hashCode, to which is added
contributions from fields. |
| Constructor Summary | |
|---|---|
HashCodeUtilities()
|
|
| Method Summary | |
|---|---|
private static int |
firstTerm(int aSeed)
modify the hash code for merging |
static int |
hash(int aSeed,
boolean aBoolean)
merge hash code with a boolean. |
static int |
hash(int aSeed,
char aChar)
merge hash code with a char. |
static int |
hash(int aSeed,
double aDouble)
merge hash code with a double. |
static int |
hash(int aSeed,
float aFloat)
merge hash code with a float. |
static int |
hash(int aSeed,
int aInt)
merge hash code with a int. |
static int |
hash(int aSeed,
long aLong)
merge hash code with a long. |
static int |
hash(int aSeed,
java.lang.Object aObject)
merge hash code with a java object. |
private static boolean |
isArray(java.lang.Object aObject)
test if an object is an array |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int INTEGER_BIT_COUNT
public static final int SEED
hashCode, to which is added
contributions from fields. Using a non-zero value decreases collisions of
hashCode values.
private static final int INITIAL_PRIME_NUMBER
| Constructor Detail |
|---|
public HashCodeUtilities()
| Method Detail |
|---|
public static int hash(int aSeed,
boolean aBoolean)
aSeed - the seed hash codeaBoolean - the boolean value
public static int hash(int aSeed,
char aChar)
aSeed - the seed hash codeaChar - the char value
public static int hash(int aSeed,
int aInt)
aSeed - the seed hash codeaInt - the int value
public static int hash(int aSeed,
long aLong)
aSeed - the seed hash codeaLong - the long value
public static int hash(int aSeed,
float aFloat)
aSeed - the seed hash codeaFloat - the float value
public static int hash(int aSeed,
double aDouble)
aSeed - the seed hash codeaDouble - the double value
public static int hash(int aSeed,
java.lang.Object aObject)
aObject is a
possibly-null object field, and possibly an array. If
aObject is an array, then each element may be a primitive or
a possibly-null object.
aSeed - the seed hash codeaObject - the object
private static int firstTerm(int aSeed)
aSeed - the current hash code
private static boolean isArray(java.lang.Object aObject)
aObject - the object to test
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||