anthill.util
Class SHADigest

java.lang.Object
  |
  +--anthill.util.SHADigest
All Implemented Interfaces:
java.lang.Comparable, java.io.Externalizable, java.io.Serializable
Direct Known Subclasses:
KeyHash

public class SHADigest
extends java.lang.Object
implements java.lang.Comparable, java.io.Externalizable

The class SHADigest computes the digest (or hash) of the specified content, and enables various other classes to compare the digests and store them in a HashMap or other collections in need of a hashCode method.

Version:
$Revision$
Author:
Hein Meling
See Also:
Serialized Form

Field Summary
protected static java.security.MessageDigest digest
          Message digest generator used to produce hash values for strings
static int DIGEST_SIZE
          Byte size of the digest values
static java.lang.String DIGEST_TYPE
          Name of the digest function to be used
protected  int hashcode
          To avoid recomputing the hash of a big integer we save it
protected static java.util.Random random
          Proxy for obtaining random numbers.
static java.lang.String RANDOM_TYPE
          Name of the random function to be used
protected  java.math.BigInteger rdigest
          A big integer for the hash code of the specified keyword.
 
Constructor Summary
SHADigest()
          Default constructor for externalization.
SHADigest(boolean secure)
          Creates a new SHADigest instance based on a randomly generated SHA hash.
 
Method Summary
 int compareTo(java.lang.Object obj)
           
 int compareTo(SHADigest kwHash)
           
protected  void computeDigest(java.lang.String str)
          Compute a SHA-1 hash value for the specified string
protected  void computeHash()
          Computes the hash code for the object.
protected  void computeRandomSHA()
          Compute a random SHA-1 hash value for a simulated hash.
 boolean equals(java.lang.Object obj)
          Check whether this SHADigest is equal to the specified object.
 int hashCode()
          Returns a hash code value for the object.
protected  void initRandom(boolean secure)
          Initialize a random generator.
 void readExternal(java.io.ObjectInput in)
          Marshals this SHADigest to the specified input stream.
 java.lang.String toString()
          Returns a string representation of the object.
 void writeExternal(java.io.ObjectOutput out)
          Marshals this SHADigest to the specified output stream.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

rdigest

protected java.math.BigInteger rdigest
A big integer for the hash code of the specified keyword.

hashcode

protected int hashcode
To avoid recomputing the hash of a big integer we save it

RANDOM_TYPE

public static final java.lang.String RANDOM_TYPE
Name of the random function to be used

DIGEST_TYPE

public static final java.lang.String DIGEST_TYPE
Name of the digest function to be used

DIGEST_SIZE

public static final int DIGEST_SIZE
Byte size of the digest values

random

protected static java.util.Random random
Proxy for obtaining random numbers.

digest

protected static java.security.MessageDigest digest
Message digest generator used to produce hash values for strings
Constructor Detail

SHADigest

public SHADigest()
Default constructor for externalization.

SHADigest

public SHADigest(boolean secure)
Creates a new SHADigest instance based on a randomly generated SHA hash.
Parameters:
secure - if true, the secure random generator will be used; otherwise the standard random generator is used.
Method Detail

computeDigest

protected void computeDigest(java.lang.String str)
Compute a SHA-1 hash value for the specified string
Parameters:
str - The string for which to compute a SHA-1 hash.

computeRandomSHA

protected void computeRandomSHA()
Compute a random SHA-1 hash value for a simulated hash.

computeHash

protected void computeHash()
Computes the hash code for the object.

initRandom

protected void initRandom(boolean secure)
Initialize a random generator.
Parameters:
secure - if true, the secure random generator will be used; otherwise the standard random generator is used.

compareTo

public int compareTo(java.lang.Object obj)
              throws java.lang.ClassCastException
Specified by:
compareTo in interface java.lang.Comparable

compareTo

public int compareTo(SHADigest kwHash)

equals

public boolean equals(java.lang.Object obj)
Check whether this SHADigest is equal to the specified object.
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Returns a hash code value for the object.
Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Returns a string representation of the object.
Overrides:
toString in class java.lang.Object

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException
Marshals this SHADigest to the specified input stream.
Specified by:
readExternal in interface java.io.Externalizable
Parameters:
in - an ObjectInput stream object
Throws:
java.io.IOException - if an error occurs

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Marshals this SHADigest to the specified output stream.
Specified by:
writeExternal in interface java.io.Externalizable
Parameters:
out - an ObjectOutput stream object
Throws:
java.io.IOException - if an error occurs