HashCodeUtil (fawkeZ - Developer's Documentation)

org.jcoderz.commons.util
Class HashCodeUtil

  extended by org.jcoderz.commons.util.HashCodeUtil

public final class HashCodeUtil
extends

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, mPrimitive);
    result = HashCodeUtil.hash(result, mObject);
    result = HashCodeUtil.hash(result, mArray);
    return result;
 }
 

Author:
Michael Griffel

Field Summary
static int SEED
          An initial value for a hashCode, to which is added contributions from fields.
 
Method Summary
static int hash(int aSeed, boolean aBoolean)
          Constructs a new seed using the given Boolean and the previous seed.
static int hash(int aSeed, char aChar)
          Constructs a new seed using the given boolean and the previous seed.
static int hash(int aSeed, double aDouble)
          Constructs a new seed using the given double and the previous seed.
static int hash(int aSeed, float aFloat)
          Constructs a new seed using the given float and the previous seed.
static int hash(int aSeed, int aInt)
          Constructs a new seed using the given integer and the previous seed.
static int hash(int aSeed, long aLong)
          Constructs a new seed using the given long and the previous seed.
static int hash(int aSeed,  aObject)
          Constructs a new seed using the given object and the previous seed.
 
Methods inherited from class java.lang.
, , , , , , , , , ,
 

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
Method Detail

hash

public static int hash(int aSeed,
                       boolean aBoolean)
Constructs a new seed using the given Boolean and the previous seed.

Parameters:
aSeed - the previous seed value.
aBoolean - the Boolean that should be added to the new seed.
Returns:
the new seed.

hash

public static int hash(int aSeed,
                       char aChar)
Constructs a new seed using the given boolean and the previous seed.

Parameters:
aSeed - the previous seed value.
aChar - the character that should be added to the new seed.
Returns:
the new seed.

hash

public static int hash(int aSeed,
                       int aInt)
Constructs a new seed using the given integer and the previous seed. Note that byte and short are handled by this method, through implicit conversion.

Parameters:
aSeed - the previous seed value.
aInt - the integer that should be added to the new seed.
Returns:
the new seed.

hash

public static int hash(int aSeed,
                       long aLong)
Constructs a new seed using the given long and the previous seed.

Parameters:
aSeed - the previous seed value.
aLong - the long value that should be added to the new seed.
Returns:
the new seed.

hash

public static int hash(int aSeed,
                       float aFloat)
Constructs a new seed using the given float and the previous seed.

Parameters:
aSeed - the previous seed value.
aFloat - the float that should be added to the new seed.
Returns:
the new seed.

hash

public static int hash(int aSeed,
                       double aDouble)
Constructs a new seed using the given double and the previous seed.

Parameters:
aSeed - the previous seed value.
aDouble - the double that should be added to the new seed.
Returns:
the new seed.

hash

public static int hash(int aSeed,
                        aObject)
Constructs a new seed using the given object and the previous seed. aObject is a possibly-null object field, and possibly an array. If aObject is an array, then each element may be a primitive or a possibly-null object.

Parameters:
aSeed - the previous seed value.
aObject - the integer that should be added to the new seed.
Returns:
the new seed.


Copyright 2007 The jCoderZ Project.