public class HashCodeUtils
extends java.lang.Object
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;
}
| 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 |
|---|
HashCodeUtils() |
| Modifier and Type | Method and Description |
|---|---|
static int |
hash(int aSeed,
boolean aBoolean)
booleans.
|
static int |
hash(int aSeed,
char aChar)
chars.
|
static int |
hash(int aSeed,
double aDouble)
doubles.
|
static int |
hash(int aSeed,
float aFloat)
floats.
|
static int |
hash(int aSeed,
int aInt)
ints.
|
static int |
hash(int aSeed,
long aLong)
longs.
|
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 - _more_aBoolean - _more_public static int hash(int aSeed,
char aChar)
aSeed - _more_aChar - _more_public static int hash(int aSeed,
int aInt)
aSeed - _more_aInt - _more_public static int hash(int aSeed,
long aLong)
aSeed - _more_aLong - _more_public static int hash(int aSeed,
float aFloat)
aSeed - _more_aFloat - _more_public static int hash(int aSeed,
double aDouble)
aSeed - _more_aDouble - _more_