com.bbn.openmap.util
Class HashCodeUtil

java.lang.Object
  extended by com.bbn.openmap.util.HashCodeUtil

public final class HashCodeUtil
extends java.lang.Object

Collected methods which allow easy implementation of hashCode. Algorithm from Effective Java by Joshua Bloch. Implementation found at http://www.javapractices.com. 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)
          hash booleans.
static int hash(int aSeed, char aChar)
          hash chars.
static int hash(int aSeed, double aDouble)
          hash for doubles
static int hash(int aSeed, float aFloat)
          hash floats.
static int hash(int aSeed, int aInt)
          hash ints.
static int hash(int aSeed, long aLong)
          hash longs.
static int hash(int aSeed, java.lang.Object aObject)
          aObject is a possibly-null object field, and possibly an array.
 
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)
hash booleans.

Parameters:
aSeed - seeding int to start with
aBoolean - object to hash
Returns:
hash for boolean

hash

public static int hash(int aSeed,
                       char aChar)
hash chars.

Parameters:
aSeed - seeding int to start with
aChar - object to hash
Returns:
hash for char

hash

public static int hash(int aSeed,
                       int aInt)
hash ints.

Parameters:
aSeed - seeding int to start with
aInt - object to hash
Returns:
hash for int

hash

public static int hash(int aSeed,
                       long aLong)
hash longs.

Parameters:
aSeed - seeding int to start with
aLong - object to hash
Returns:
hash for long

hash

public static int hash(int aSeed,
                       float aFloat)
hash floats.

Parameters:
aSeed - seeding int to start with
aFloat - object to hash
Returns:
hash for float

hash

public static int hash(int aSeed,
                       double aDouble)
hash for doubles

Parameters:
aSeed - seeding int to start with
aDouble - to hash
Returns:
hash for double

hash

public static int hash(int aSeed,
                       java.lang.Object aObject)
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 - seeding int to start with
aObject - object to hash
Returns:
hash for aObject


Copyright (C) BBNT Solutions LLC; See http://openmap.bbn.com/ for details