|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectorg.opensubsystems.core.util.HashCodeUtils
public final class HashCodeUtils
Collection of methods making implementation of hashcode easier. Example how hashCode can be implemented using this method: public int hashCode() { int iResult = HashCodeUtils.SEED; iResult = HashCodeUtils.hash(iResult, primitiveValue); iResult = HashCodeUtils.hash(iResult, object); iResult = HashCodeUtils.hash(iResult, array); return iResult; } This code was inspired by class published at http://www.javapractices.com/Topic28.cjp
| Field Summary | |
|---|---|
static int |
ODD_PRIME_NUMBER
Constant to add to seed or previous term. |
static int |
SEED
An initial value to decreases collisons of computed values. |
| Method Summary | |
|---|---|
protected static int |
firstTerm(int iSeed)
Compute first term for hashcode |
static int |
hash(int iSeed,
boolean bValue)
Hash for booleans. |
static int |
hash(int iSeed,
char cValue)
Hash for chars. |
static int |
hash(int iSeed,
double dValue)
Hash for doubles. |
static int |
hash(int iSeed,
float fValue)
Hash for floats. |
static int |
hash(int iSeed,
int iValue)
Hash for ints. |
static int |
hash(int iSeed,
long lValue)
Hash for longs. |
static int |
hash(int iSeed,
java.lang.Object oValue)
Hash for objects . |
protected static boolean |
isArray(java.lang.Object oObject)
Test if 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 SEED
public static final int ODD_PRIME_NUMBER
| Method Detail |
|---|
public static int hash(int iSeed,
boolean bValue)
iSeed - - previous hashcode contributor or seed valuebValue - - value contributing to hashcode
public static int hash(int iSeed,
char cValue)
iSeed - - previous hashcode contributor or seed valuecValue - - value contributing to hashcode
public static int hash(int iSeed,
int iValue)
iSeed - - previous hashcode contributor or seed valueiValue - - value contributing to hashcode
public static int hash(int iSeed,
long lValue)
iSeed - - previous hashcode contributor or seed valuelValue - - value contributing to hashcode
public static int hash(int iSeed,
float fValue)
iSeed - - previous hashcode contributor or seed valuefValue - - value contributing to hashcode
public static int hash(int iSeed,
double dValue)
iSeed - - previous hashcode contributor or seed valuedValue - - value contributing to hashcode
public static int hash(int iSeed,
java.lang.Object oValue)
iSeed - - previous hashcode contributor or seed valueoValue - - value contributing to hashcode. It is a possibly null
object field, and possibly an array. If it is an array,
then each element may be a primitive or a possibly null
object.
protected static int firstTerm(int iSeed)
iSeed - - value to use to compute first temr
protected static boolean isArray(java.lang.Object oObject)
oObject - - object to test
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||