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) |
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)
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 collisions of
hashCode values.public static int hash(int aSeed,
boolean aBoolean)
aSeed - initial value of the hashCodeaBoolean - value to contribute to the hashCodepublic static int hash(int aSeed,
char aChar)
aSeed - initial value of the hashCodeaChar - value to contribute to the hashCodepublic static int hash(int aSeed,
int aInt)
aSeed - initial value of the hashCodeaInt - value to contribute to the hashCodepublic static int hash(int aSeed,
long aLong)
aSeed - initial value of the hashCodeaLong - value to contribute to the hashCodepublic static int hash(int aSeed,
float aFloat)
aSeed - initial value of the hashCodeaFloat - value to contribute to the hashCodepublic static int hash(int aSeed,
double aDouble)
aSeed - initial value of the hashCodeaDouble - value to contribute to the hashCodepublic 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.Copyright © 2022. All rights reserved.