jodd.util
Class HashCode

java.lang.Object
  extended by jodd.util.HashCode

public class HashCode
extends java.lang.Object

Collected methods which allow easy implementation of hashCode(). Based on items #7 and #8 from "Effective Java" book.

Usage scenario:

 int result = HashCodeUtil.SEED;
 result = HashCodeUtil.hash(result, fIsDecrepit);
 ...
 return result;
 


Field Summary
static int PRIME
           
static int SEED
          An initial hash code value to which is added contributions from fields.
 
Constructor Summary
HashCode()
           
 
Method Summary
static int hash(int seed, boolean aBoolean)
          Calculates hash code for booleans.
static int hash(int seed, boolean[] booleanArray)
          Calculates hash code for boolean array.
static int hash(int seed, byte[] byteArray)
          Calculates hash code for byte array.
static int hash(int seed, char aChar)
          Calculates hash code for chars.
static int hash(int seed, char[] charArray)
          Calculates hash code for char array.
static int hash(int seed, double aDouble)
          Calculates hash code for doubles.
static int hash(int seed, double[] doubleArray)
          Calculates hash code for double array.
static int hash(int seed, float aFloat)
          Calculates hash code for floats.
static int hash(int seed, float[] floatArray)
          Calculates hash code for float array.
static int hash(int seed, int anInt)
          Calculates hash code for ints.
static int hash(int seed, int[] intArray)
          Calculates hash code for int array.
static int hash(int seed, long aLong)
          Calculates hash code for longs.
static int hash(int seed, long[] longArray)
          Calculates hash code for long array.
static int hash(int seed, java.lang.Object aObject)
          Calculates hash code for Objects.
static int hash(int seed, short[] shortArray)
          Calculates hash code for short array.
static int hashBooleanArray(int seed, boolean... booleanArray)
          Calculates hash code for boolean array.
static int hashByteArray(int seed, byte... byteArray)
          Calculates hash code for byte array.
static int hashCharArray(int seed, char... charArray)
          Calculates hash code for char array.
static int hashDoubleArray(int seed, double... doubleArray)
          Calculates hash code for double array.
static int hashFloatArray(int seed, float... floatArray)
          Calculates hash code for float array.
static int hashIntArray(int seed, int... intArray)
          Calculates hash code for int array.
static int hashLongArray(int seed, long... longArray)
          Calculates hash code for long array.
static int hashShortArray(int seed, short... shortArray)
          Calculates hash code for short 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 hash code value to which is added contributions from fields. Using a non-zero value decreases collisions of hash code values.

See Also:
Constant Field Values

PRIME

public static final int PRIME
See Also:
Constant Field Values
Constructor Detail

HashCode

public HashCode()
Method Detail

hash

public static int hash(int seed,
                       boolean aBoolean)
Calculates hash code for booleans.


hash

public static int hash(int seed,
                       boolean[] booleanArray)
Calculates hash code for boolean array.


hashBooleanArray

public static int hashBooleanArray(int seed,
                                   boolean... booleanArray)
Calculates hash code for boolean array.


hash

public static int hash(int seed,
                       char aChar)
Calculates hash code for chars.


hash

public static int hash(int seed,
                       char[] charArray)
Calculates hash code for char array.


hashCharArray

public static int hashCharArray(int seed,
                                char... charArray)
Calculates hash code for char array.


hash

public static int hash(int seed,
                       int anInt)
Calculates hash code for ints.


hash

public static int hash(int seed,
                       int[] intArray)
Calculates hash code for int array.


hashIntArray

public static int hashIntArray(int seed,
                               int... intArray)
Calculates hash code for int array.


hash

public static int hash(int seed,
                       short[] shortArray)
Calculates hash code for short array.


hashShortArray

public static int hashShortArray(int seed,
                                 short... shortArray)
Calculates hash code for short array.


hash

public static int hash(int seed,
                       byte[] byteArray)
Calculates hash code for byte array.


hashByteArray

public static int hashByteArray(int seed,
                                byte... byteArray)
Calculates hash code for byte array.


hash

public static int hash(int seed,
                       long aLong)
Calculates hash code for longs.


hash

public static int hash(int seed,
                       long[] longArray)
Calculates hash code for long array.


hashLongArray

public static int hashLongArray(int seed,
                                long... longArray)
Calculates hash code for long array.


hash

public static int hash(int seed,
                       float aFloat)
Calculates hash code for floats.


hash

public static int hash(int seed,
                       float[] floatArray)
Calculates hash code for float array.


hashFloatArray

public static int hashFloatArray(int seed,
                                 float... floatArray)
Calculates hash code for float array.


hash

public static int hash(int seed,
                       double aDouble)
Calculates hash code for doubles.


hash

public static int hash(int seed,
                       double[] doubleArray)
Calculates hash code for double array.


hashDoubleArray

public static int hashDoubleArray(int seed,
                                  double... doubleArray)
Calculates hash code for double array.


hash

public static int hash(int seed,
                       java.lang.Object aObject)
Calculates hash code for Objects. Object 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.



Copyright © 2003-2012 Jodd Team