|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.biojava3.core.util.Hashcoder
public class Hashcoder
Contains helper methods for generating a HashCode without having to resort to the commons lang hashcode builders. Example where the property name is a String and the property age is an int
public int hashCode() { int result = Hashcoder.SEED; result = Hashcoder.hash(result, this.getName()); result = Hashcoder.hash(result, this.getAge()); return result; }
Field Summary | |
---|---|
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 Summary | |
---|---|
Hashcoder()
|
Method Summary | |
---|---|
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. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
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
Constructor Detail |
---|
public Hashcoder()
Method Detail |
---|
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.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |