public final class HashCodeUtil extends Object
This class provides utility functions for generating good hash codes. Hash codes generated with these methods should have a reasonably good distribution when placed in a hash structure such as Hashtable, HashSet, or HashMap.
General usage is something like:
public int hashCode() { int hc = 0; // or = super.hashCode(); hc = HashCodeUtil.hashCode(hc, intField); hc = HashCodeUtil.hashCode(hc, objectField); // etc, etc return hc; }
Constructor and Description |
---|
HashCodeUtil() |
Modifier and Type | Method and Description |
---|---|
static int |
expHashCode(CharSequence x) |
static int |
expHashCode(CharSequence x,
boolean caseSensitive) |
static int |
expHashCode(int previous,
Collection<?> x)
Compute a hash code on a large collection by walking the list
and combining the hash code at every exponential index:
1, 2, 4, 8, ...
|
static int |
expHashCode(int previous,
Object[] x)
Compute a hash code on a large array by walking the list
and combining the hash code at every exponential index:
1, 2, 4, 8, ...
|
static int |
hashCode(int previous,
boolean x) |
static int |
hashCode(int previous,
double x) |
static int |
hashCode(int previous,
float x) |
static int |
hashCode(int previous,
int x) |
static int |
hashCode(int previous,
long x) |
static int |
hashCode(int previous,
Object... x) |
public static final int hashCode(int previous, boolean x)
public static final int hashCode(int previous, int x)
public static final int hashCode(int previous, long x)
public static final int hashCode(int previous, float x)
public static final int hashCode(int previous, double x)
public static final int hashCode(int previous, Object... x)
public static final int expHashCode(int previous, Object[] x)
public static final int expHashCode(int previous, Collection<?> x)
public static final int expHashCode(CharSequence x)
public static final int expHashCode(CharSequence x, boolean caseSensitive)
Copyright © 2019. All rights reserved.