Package org.cip4.jdflib.util
Class HashUtil
- java.lang.Object
-
- org.cip4.jdflib.util.HashUtil
-
public class HashUtil extends java.lang.ObjectThis class provides some hashCode calculation utilities. Use the static methods of this class to generatehashCode()
values in data objects. For example, to calculate the hashCode of a data object, use the methods of this class as follows:int myIntField; Object myObject; public int hashCode() { // int hash = super.hashCode(); // use when not extending Object int hash = 0; // use when extending Object hash = HashUtil.hashCode(hash, myIntField); hash = HashUtil.hashCode(hash, myObject); return hash; }
Hint: Start your hashCode calculation depending on the object your data object extends. If you extend Object initialize your hash value to 0. Otherwise initialize hash to super.hashCode(). See the example code.
-
-
Field Summary
Fields Modifier and Type Field Description static intPRIME
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static inthashCode(int source, boolean x)static inthashCode(int source, double x)static inthashCode(int source, float x)static inthashCode(int source, int x)static inthashCode(int source, long x)static inthashCode(int source, java.lang.Object x)static inthashCode(int source, java.lang.Object[] x)static inthashCode(int source, java.util.Collection<?> c)
-
-
-
Field Detail
-
PRIME
public static final int PRIME
- See Also:
- Constant Field Values
-
-
Method Detail
-
hashCode
public static final int hashCode(int source, boolean x)- Parameters:
source-x-- Returns:
-
hashCode
public static final int hashCode(int source, int x)- Parameters:
source-x-- Returns:
-
hashCode
public static final int hashCode(int source, long x)- Parameters:
source-x-- Returns:
-
hashCode
public static final int hashCode(int source, float x)- Parameters:
source-x-- Returns:
-
hashCode
public static final int hashCode(int source, double x)- Parameters:
source-x-- Returns:
-
hashCode
public static final int hashCode(int source, java.lang.Object x)- Parameters:
source-x-- Returns:
-
hashCode
public static final int hashCode(int source, java.util.Collection<?> c)- Parameters:
source-c-- Returns:
-
hashCode
public static final int hashCode(int source, java.lang.Object[] x)- Parameters:
source-x-- Returns:
-
-