public class Hashcoder extends Object
public int hashCode() { int result = Hashcoder.SEED; result = Hashcoder.hash(result, this.getName()); result = Hashcoder.hash(result, this.getAge()); return result; }
Modifier and Type | Field and Description |
---|---|
static int |
PRIME
The prime number used to multiply any calculated hashcode seed by
i.e.
|
static int |
SEED
An initial value for a
hashCode , to which we add
contributions from fields. |
Constructor and Description |
---|
Hashcoder() |
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)
double support which is done using the same techinque as float hashing
except we convert to a long not to an int.
|
static int |
hash(int seed,
float f)
float support done via
Float.floatToIntBits(float) which allows
the encoding of a float as an int. |
static int |
hash(int seed,
int i)
Used for ints, bytes and shorts
|
static int |
hash(int seed,
long l)
long support done by shifting by 32 (using unsigned shift)
|
static int |
hash(int seed,
Object o)
o is a possibly-null object field, and possibly an
array. |
public static final int SEED
hashCode
, to which we add
contributions from fields. Using a non-zero value decreases collisions of
hashCode
values.public static final int PRIME
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)
Float.floatToIntBits(float)
which allows
the encoding of a float as an int. We can then hash as normal.public static int hash(int seed, double d)
public static int hash(int seed, Object o)
o
is a possibly-null object field, and possibly an
array.
If o
is an array, then each element may be a primitive
or a possibly-null object.Copyright © 2000–2016 BioJava. All rights reserved.