2004.04.29


com.jdc.lang
Class HashCode

java.lang.Object
  |
  +--com.jdc.lang.Object
        |
        +--com.jdc.lang.HashCode

public class HashCode
extends Object

HashCode is a convenience class used to generate a hash code based on the principles in Effective Java Programming Language Guide by Joshua Bloch. Refer to the algorithm discussed in Item 8 on pages 36 thru 41.

Reference: Effective Java Programming Language Guide

Note: The implementation of this class is incomplete. Specifically, Steps 2.a.vi and 2.a.vii on Pages 38-39 are not currently implemented in this class.

Version:
1.0
Author:
Jay Damon

Field Summary
 
Fields inherited from class com.jdc.lang.Object
string
 
Constructor Summary
HashCode()
          Constructs a new HashCode object.
 
Method Summary
 HashCode compute(boolean value)
          Computes an int hash code for this boolean value.
 HashCode compute(byte value)
          Computes an int hash code for this byte value.
 HashCode compute(char value)
          Computes an int hash code for this char value.
 HashCode compute(double value)
          Computes an int hash code for this double value.
 HashCode compute(float value)
          Computes an int hash code for this float value.
 HashCode compute(int value)
          Computes an int hash code for this int value.
 HashCode compute(long value)
          Computes an int hash code for this long value.
 HashCode compute(Object object)
          Computes an int hash code for this Object.
 HashCode compute(short value)
          Computes an int hash code for this short value.
 HashCode compute(String value)
          Computes an int hash code for this String value.
 int result()
          Returns the int hash code result.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HashCode

public HashCode()
Constructs a new HashCode object.

Method Detail

compute

public HashCode compute(boolean value)
Computes an int hash code for this boolean value. The value is computed as described on Page 38, Step 2.a.i: Compute an int for the field.

Returns:
This HashCode object.

compute

public HashCode compute(byte value)
Computes an int hash code for this byte value. The value is computed as described on Page 38, Step 2.a.ii: Compute an int for the field.

Returns:
This HashCode object.

compute

public HashCode compute(char value)
Computes an int hash code for this char value. The value is computed as described on Page 38, Step 2.a.ii: Compute an int for the field.

Returns:
This HashCode object.

compute

public HashCode compute(double value)
Computes an int hash code for this double value. The value is computed as described on Page 38, Step 2.a.v: Compute an int for the field.

Returns:
This HashCode object.

compute

public HashCode compute(float value)
Computes an int hash code for this float value. The value is computed as described on Page 38, Step 2.a.iv: Compute an int for the field.

Returns:
This HashCode object.

compute

public HashCode compute(int value)
Computes an int hash code for this int value. The value is computed as described on Page 38, Step 2.a.ii: Compute an int for the field.

Returns:
This HashCode object.

compute

public HashCode compute(long value)
Computes an int hash code for this long value. The value is computed as described on Page 38, Step 2.a.iii: Compute an int for the field.

Returns:
This HashCode object.

compute

public HashCode compute(short value)
Computes an int hash code for this short value. The value is computed as described on Page 38, Step 2.a.ii: Compute an int for the field.

Returns:
This HashCode object.

compute

public HashCode compute(Object object)
Computes an int hash code for this Object.

Returns:
This HashCode object.

compute

public HashCode compute(String value)
Computes an int hash code for this String value.

Returns:
This HashCode object.

result

public int result()
Returns the int hash code result. The result is computed as described on Page 39, Step 3: Return the result.

Returns:
The hash code result value.

2004.04.29



Copyright © 2004 J. Damon & Co.; All Rights Reserved WorldWide.