org.cip4.jdflib.util
Class HashUtil
java.lang.Object
org.cip4.jdflib.util.HashUtil
public class HashUtil
- extends Object
This class provides some hashCode calculation utilities. Use the static methods of this class to generate
hashCode()
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.
- Author:
- Manfred Steinbach
|
Field Summary |
static int |
PRIME
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
PRIME
public static final int PRIME
- See Also:
- Constant Field Values
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,
Object x)
- Parameters:
source - x -
- Returns:
hashCode
public static final int hashCode(int source,
Collection<?> c)
- Parameters:
source - c -
- Returns:
hashCode
public static final int hashCode(int source,
Object[] x)
- Parameters:
source - x -
- Returns:
Copyright © 2013. All Rights Reserved.