Package net.sf.okapi.common
Class HashCodeUtil
- java.lang.Object
-
- net.sf.okapi.common.HashCodeUtil
-
public final class HashCodeUtil extends Object
Collected methods which allow easy implementation ofhashCode. 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; }
-
-
Field Summary
Fields Modifier and Type Field Description static intSEEDAn initial value for ahashCode, to which is added contributions from fields.
-
Constructor Summary
Constructors Constructor Description HashCodeUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static inthash(int aSeed, boolean aBoolean)static inthash(int aSeed, char aChar)static inthash(int aSeed, double aDouble)static inthash(int aSeed, float aFloat)static inthash(int aSeed, int aInt)static inthash(int aSeed, long aLong)static inthash(int aSeed, Object aObject)aObjectis a possibly-null object field, and possibly an array.
-
-
-
Field Detail
-
SEED
public static final int SEED
An initial value for ahashCode, to which is added contributions from fields. Using a non-zero value decreases collisions ofhashCodevalues.- See Also:
- Constant Field Values
-
-
Method Detail
-
hash
public static int hash(int aSeed, boolean aBoolean)- Parameters:
aSeed- initial value of thehashCodeaBoolean- value to contribute to thehashCode- Returns:
- hash code for a boolean.
-
hash
public static int hash(int aSeed, char aChar)- Parameters:
aSeed- initial value of thehashCodeaChar- value to contribute to thehashCode- Returns:
- has code for a char value.
-
hash
public static int hash(int aSeed, int aInt)- Parameters:
aSeed- initial value of thehashCodeaInt- value to contribute to thehashCode- Returns:
- hash code for int.
-
hash
public static int hash(int aSeed, long aLong)- Parameters:
aSeed- initial value of thehashCodeaLong- value to contribute to thehashCode- Returns:
- hash code for a long value.
-
hash
public static int hash(int aSeed, float aFloat)- Parameters:
aSeed- initial value of thehashCodeaFloat- value to contribute to thehashCode- Returns:
- a hash code for a float value.
-
hash
public static int hash(int aSeed, double aDouble)- Parameters:
aSeed- initial value of thehashCodeaDouble- value to contribute to thehashCode- Returns:
- a hash code for a double value.
-
hash
public static int hash(int aSeed, Object aObject)aObjectis a possibly-null object field, and possibly an array. IfaObjectis an array, then each element may be a primitive or a possibly-null object.
-
-