Package org.biojava.nbio.core.util
Class Hashcoder
- java.lang.Object
- 
- org.biojava.nbio.core.util.Hashcoder
 
- 
 public class Hashcoder extends Object 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 intpublic int hashCode() { int result = Hashcoder.SEED; result = Hashcoder.hash(result, this.getName()); result = Hashcoder.hash(result, this.getAge()); return result; }- Author:
- ayates
 
- 
- 
Field SummaryFields Modifier and Type Field Description static intPRIMEThe prime number used to multiply any calculated hashcode seed by i.e. result = PRIME*result + c Where result is the result of the previous calculation (at first this will be seed) and c is the calculated int to add to resultstatic intSEEDAn initial value for ahashCode, to which we add contributions from fields.
 - 
Constructor SummaryConstructors Constructor Description Hashcoder()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static inthash(int seed, boolean b)static inthash(int seed, char c)static inthash(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 inthash(int seed, float f)float support done viaFloat.floatToIntBits(float)which allows the encoding of a float as an int.static inthash(int seed, int i)Used for ints, bytes and shortsstatic inthash(int seed, long l)long support done by shifting by 32 (using unsigned shift)static inthash(int seed, Object o)ois a possibly-null object field, and possibly an array.
 
- 
- 
- 
Field Detail- 
SEEDpublic static final int SEED An initial value for ahashCode, to which we add contributions from fields. Using a non-zero value decreases collisions ofhashCodevalues.- See Also:
- Constant Field Values
 
 - 
PRIMEpublic static final int PRIME The prime number used to multiply any calculated hashcode seed by i.e. result = PRIME*result + c Where result is the result of the previous calculation (at first this will be seed) and c is the calculated int to add to result- See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
Hashcoderpublic Hashcoder() 
 
- 
 - 
Method Detail- 
hashpublic static int hash(int seed, boolean b) 
 - 
hashpublic static int hash(int seed, char c) 
 - 
hashpublic static int hash(int seed, int i) Used for ints, bytes and shorts
 - 
hashpublic static int hash(int seed, long l) long support done by shifting by 32 (using unsigned shift)
 - 
hashpublic static int hash(int seed, float f) float support done viaFloat.floatToIntBits(float)which allows the encoding of a float as an int. We can then hash as normal.
 - 
hashpublic 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.
 
- 
 
-