|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.webmethods.caf.wsclient.util.HashCodeUtil
public final class HashCodeUtil
The following utility class allows simple construction of an effective
hashCode method. It is based on the recommendations of Effective Java,
by Joshua Bloch.
Collected methods which allow easy implementation of hashCode
.
Example use case:
public int hashCode(){ int result = HashCodeUtil.SEED; //collect the contributions of various fields result = HashCodeUtil.hash(result, fPrimitive); result = HashCodeUtil.hash(result, fObject); result = HashCodeUtil.hash(result, fArray); return result; }
Field Summary | |
---|---|
static int |
SEED
An initial value for a hashCode , to which is added contributions
from fields. |
Constructor Summary | |
---|---|
HashCodeUtil()
|
Method Summary | |
---|---|
static int |
hash(int aSeed,
boolean aBoolean)
Generate a hash for a boolean value |
static int |
hash(int aSeed,
char aChar)
Generate a hash for a char value |
static int |
hash(int aSeed,
double aDouble)
Generate a hash for a double value |
static int |
hash(int aSeed,
float aFloat)
Generate a hash for a float value |
static int |
hash(int aSeed,
int aInt)
Generate a hash for an integer value Note: byte and short are handled by this method, through implicit conversion. |
static int |
hash(int aSeed,
long aLong)
Generate a hash for a long value |
static int |
hash(int aSeed,
Object aObject)
Generate a hash for an Object instance |
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
hashCode
, to which is added contributions
from fields. Using a non-zero value decreases collisons of hashCode
values.
Constructor Detail |
---|
public HashCodeUtil()
Method Detail |
---|
public static int hash(int aSeed, boolean aBoolean)
aSeed
- the initial hash value seed, used to aggregate a hash for multiple objects (see class description)aBoolean
- boolean value to hash
public static int hash(int aSeed, char aChar)
aSeed
- the initial hash value seed, used to aggregate a hash for multiple objects (see class description)aChar
- char value to hash
public static int hash(int aSeed, int aInt)
aSeed
- the initial hash value seed, used to aggregate a hash for multiple objects (see class description)aInt
- integer value to hash
public static int hash(int aSeed, long aLong)
aSeed
- the initial hash value seed, used to aggregate a hash for multiple objects (see class description)aLong
- long value to hash
public static int hash(int aSeed, float aFloat)
aSeed
- the initial hash value seed, used to aggregate a hash for multiple objects (see class description)aFloat
- float value to hash
public static int hash(int aSeed, double aDouble)
aSeed
- the initial hash value seed, used to aggregate a hash for multiple objects (see class description)aDouble
- double value to hash
public static int hash(int aSeed, Object aObject)
aSeed
- the initial hash value seed, used to aggregate a hash for multiple objects (see class description)aObject
- the Object instance to hash, this can include a null object or an array of objects
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |