com.webmethods.caf.wsclient.util
Class HashCodeUtil

java.lang.Object
  extended by com.webmethods.caf.wsclient.util.HashCodeUtil

public final class HashCodeUtil
extends Object

The following utility class allows simple construction of an effective hashCode method. It is based on the recommendations of Effective Java, by Joshua Bloch. Collected methods which allow easy implementation of hashCode. 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
static int SEED
          An initial value for a hashCode, to which is added contributions from fields.
 
Constructor Summary
HashCodeUtil()
           
 
Method Summary
static int hash(int aSeed, boolean aBoolean)
          Generate a hash for a boolean value
static int hash(int aSeed, char aChar)
          Generate a hash for a char value
static int hash(int aSeed, double aDouble)
          Generate a hash for a double value
static int hash(int aSeed, float aFloat)
          Generate a hash for a float value
static int hash(int aSeed, int aInt)
          Generate a hash for an integer value Note: byte and short are handled by this method, through implicit conversion.
static int hash(int aSeed, long aLong)
          Generate a hash for a long value
static int hash(int aSeed, Object aObject)
          Generate a hash for an Object instance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SEED

public static final int SEED
An initial value for a hashCode, to which is added contributions from fields. Using a non-zero value decreases collisons of hashCode values.

See Also:
Constant Field Values
Constructor Detail

HashCodeUtil

public HashCodeUtil()
Method Detail

hash

public static int hash(int aSeed,
                       boolean aBoolean)
Generate a hash for a boolean value

Parameters:
aSeed - the initial hash value seed, used to aggregate a hash for multiple objects (see class description)
aBoolean - boolean value to hash
Returns:
the aggregated hash code

hash

public static int hash(int aSeed,
                       char aChar)
Generate a hash for a char value

Parameters:
aSeed - the initial hash value seed, used to aggregate a hash for multiple objects (see class description)
aChar - char value to hash
Returns:
the aggregated hash code

hash

public static int hash(int aSeed,
                       int aInt)
Generate a hash for an integer value Note: byte and short are handled by this method, through implicit conversion.

Parameters:
aSeed - the initial hash value seed, used to aggregate a hash for multiple objects (see class description)
aInt - integer value to hash
Returns:
the aggregated hash code

hash

public static int hash(int aSeed,
                       long aLong)
Generate a hash for a long value

Parameters:
aSeed - the initial hash value seed, used to aggregate a hash for multiple objects (see class description)
aLong - long value to hash
Returns:
the aggregated hash code

hash

public static int hash(int aSeed,
                       float aFloat)
Generate a hash for a float value

Parameters:
aSeed - the initial hash value seed, used to aggregate a hash for multiple objects (see class description)
aFloat - float value to hash
Returns:
the aggregated hash code

hash

public static int hash(int aSeed,
                       double aDouble)
Generate a hash for a double value

Parameters:
aSeed - the initial hash value seed, used to aggregate a hash for multiple objects (see class description)
aDouble - double value to hash
Returns:
the aggregated hash code

hash

public static int hash(int aSeed,
                       Object aObject)
Generate a hash for an Object instance

Parameters:
aSeed - the initial hash value seed, used to aggregate a hash for multiple objects (see class description)
aObject - the Object instance to hash, this can include a null object or an array of objects
Returns:
the aggregated hash code