|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.jcoderz.commons.util.HashCodeUtil
public final class HashCodeUtil
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, mPrimitive);
result = HashCodeUtil.hash(result, mObject);
result = HashCodeUtil.hash(result, mArray);
return result;
}
| Field Summary | |
|---|---|
static int |
SEED
An initial value for a hashCode, to which is added
contributions from fields. |
| Method Summary | |
|---|---|
static int |
hash(int aSeed,
boolean aBoolean)
Constructs a new seed using the given Boolean and the previous seed. |
static int |
hash(int aSeed,
char aChar)
Constructs a new seed using the given boolean and the previous seed. |
static int |
hash(int aSeed,
double aDouble)
Constructs a new seed using the given double and the previous seed. |
static int |
hash(int aSeed,
float aFloat)
Constructs a new seed using the given float and the previous seed. |
static int |
hash(int aSeed,
int aInt)
Constructs a new seed using the given integer and the previous seed. |
static int |
hash(int aSeed,
long aLong)
Constructs a new seed using the given long and the previous seed. |
static int |
hash(int aSeed,
Object aObject)
Constructs a new seed using the given object and the previous seed. |
| 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.
| Method Detail |
|---|
public static int hash(int aSeed,
boolean aBoolean)
aSeed - the previous seed value.aBoolean - the Boolean that should be added to the new seed.
public static int hash(int aSeed,
char aChar)
aSeed - the previous seed value.aChar - the character that should be added to the new seed.
public static int hash(int aSeed,
int aInt)
aSeed - the previous seed value.aInt - the integer that should be added to the new seed.
public static int hash(int aSeed,
long aLong)
aSeed - the previous seed value.aLong - the long value that should be added to the new seed.
public static int hash(int aSeed,
float aFloat)
aSeed - the previous seed value.aFloat - the float that should be added to the new seed.
public static int hash(int aSeed,
double aDouble)
aSeed - the previous seed value.aDouble - the double that should be added to the new seed.
public static int hash(int aSeed,
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 previous seed value.aObject - the integer that should be added to the new seed.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||