public final class HashCodeUtil extends Object
http://www.javapractices.com/Topic28.cjp
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 |
---|
HashCodeUtil() |
Modifier and Type | Method and Description |
---|---|
static int |
hash(int seed,
boolean b) |
static int |
hash(int seed,
char c) |
static int |
hash(int seed,
double d) |
static int |
hash(int seed,
float f) |
static int |
hash(int seed,
int i) |
static int |
hash(int seed,
long l) |
static int |
hash(int seed,
Object o)
aObject is a possibly-null object field, and possibly an array. |
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 seed, boolean b)
public static int hash(int seed, char c)
public static int hash(int seed, int i)
public static int hash(int seed, long l)
public static int hash(int seed, float f)
public static int hash(int seed, double d)
public static int hash(int seed, Object o)
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.
seed
- the seedo
- the objectCopyright © 2006–2018 MyBatis.org. All rights reserved.