public final class HashCodeUtil extends Object
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; }
Modifier and Type | Field and Description |
---|---|
static int |
SEED
An initial value for a
hashCode , to which is added contributions
from fields. |
Constructor and Description |
---|
HashCodeUtil() |
Modifier and Type | Method and Description |
---|---|
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
|
public static final int SEED
hashCode
, to which is added contributions
from fields. Using a non-zero value decreases collisons of hashCode
values.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 hashpublic 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 hashpublic 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 hashpublic 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 hashpublic 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 hashpublic 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 hashpublic 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