|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--anthill.util.SHADigest
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.
Field Summary | |
protected static MessageDigest |
digest
Message digest generator used to produce hash values for strings |
static int |
DIGEST_SIZE
Byte size of the digest values |
static 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 Random |
random
Proxy for obtaining random numbers. |
static String |
RANDOM_TYPE
Name of the random function to be used |
protected 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(Object obj)
|
int |
compareTo(SHADigest kwHash)
|
protected void |
computeDigest(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(Object obj)
Check whether this SHADigest is equal to the specified object. |
byte[] |
getBytes()
Returns the bytes representing the hashed value of the keyword. |
int |
hashCode()
Returns a hash code value for the object. |
protected void |
initRandom(boolean secure)
Initialize a random generator. |
int |
isCloser(Object x,
Object y)
Compares this object against the provided objects for
closeness. |
void |
readExternal(ObjectInput in)
Marshals this SHADigest to the specified input stream. |
String |
toString()
Returns a string representation of the object. |
void |
writeExternal(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 |
protected BigInteger rdigest
protected int hashcode
public static final String RANDOM_TYPE
public static final String DIGEST_TYPE
public static final int DIGEST_SIZE
protected static Random random
protected static MessageDigest digest
Constructor Detail |
public SHADigest()
public SHADigest(boolean secure)
SHADigest
instance based on a randomly
generated SHA hash.
secure
- if true, the secure random generator will be used;
otherwise the standard random generator is used.Method Detail |
public byte[] getBytes()
protected void computeDigest(String str)
str
- The string for which to compute a SHA-1 hash.protected void computeRandomSHA()
protected void computeHash()
protected void initRandom(boolean secure)
secure
- if true, the secure random generator will be used;
otherwise the standard random generator is used.public int isCloser(Object x, Object y)
Closeness
this
object against the provided objects for
closeness. An implementation of this method must return an
int
according to the following rules:
-1 is returned if the value of x is considered closer to this object than the value of y. +1 is returned if the value of y is considered closer to this object than the value of x. 0 is returned if the values of x and y are equally close to this object.
isCloser
in interface Closeness
public int compareTo(Object obj) throws ClassCastException
compareTo
in interface Comparable
ClassCastException
public int compareTo(SHADigest kwHash)
public boolean equals(Object obj)
SHADigest
is equal to the specified object.
equals
in class Object
public int hashCode()
hashCode
in class Object
public String toString()
toString
in class Object
public void readExternal(ObjectInput in) throws IOException
SHADigest
to the specified input stream.
readExternal
in interface Externalizable
in
- an ObjectInput
stream object
IOException
- if an error occurspublic void writeExternal(ObjectOutput out) throws IOException
SHADigest
to the specified output stream.
writeExternal
in interface Externalizable
out
- an ObjectOutput
stream object
IOException
- if an error occurs
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |