edu.bsu.cs.jive.util
Class HashUtils
java.lang.Object
edu.bsu.cs.jive.util.HashUtils
public final class HashUtils
- extends Object
Collected methods which allow easy implementation of hashCode
.
This is based on Joshua Bloch's recommendations from his
Effective Java textbook.
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. |
Method Summary |
static int |
hash(int aSeed,
boolean aBoolean)
|
static int |
hash(int aSeed,
char aChar)
|
static int |
hash(int aSeed,
double aDouble)
|
static int |
hash(int aSeed,
float aFloat)
|
static int |
hash(int aSeed,
int aInt)
|
static int |
hash(int aSeed,
long aLong)
|
static int |
hash(int aSeed,
Object aObject)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
SEED
public static final int SEED
- An initial value for a
hashCode
, to which is added contributions
from fields. Using a non-zero value decreases collisons of hashCode
values.
- See Also:
- Constant Field Values
HashUtils
public HashUtils()
hash
public static int hash(int aSeed,
boolean aBoolean)
hash
public static int hash(int aSeed,
char aChar)
hash
public static int hash(int aSeed,
int aInt)
hash
public static int hash(int aSeed,
long aLong)
hash
public static int hash(int aSeed,
float aFloat)
hash
public static int hash(int aSeed,
double aDouble)
hash
public static int hash(int aSeed,
Object aObject)