anthill.types
Class SHADocumentId

java.lang.Object
  |
  +--anthill.util.SHADigest
        |
        +--anthill.types.SHADocumentId
All Implemented Interfaces:
Closeness, Comparable, Externalizable, Serializable

public class SHADocumentId
extends SHADigest

Probabilistic identifier for a document.

Version:
$Revision: 1.2 $
Author:
Alberto Montresor
See Also:
Serialized Form

Field Summary
protected  int length
          Length of the document
 
Fields inherited from class anthill.util.SHADigest
digest, DIGEST_SIZE, DIGEST_TYPE, hashcode, random, RANDOM_TYPE, rdigest
 
Constructor Summary
SHADocumentId()
          Default constructor for externalization.
 
Method Summary
protected  void computeHash()
          Computes the hash code for this SHADocumentId.
protected  void computeSHADocumentId(String urlPath)
          Computes a fake SHADocumentId based on the path component of the specified URL.
protected  void computeSHADocumentId(URL url)
          Reads data from the specified URL and computes the length and digest components that comprise the SHADocumentId.
 boolean equals(Object obj)
          Check whether this SHADocumentId is equal to the specified object.
 int getLength()
          Returns the length component of the SHADocumentId.
 void readExternal(ObjectInput in)
          Marshals this SHADocumentId to the specified output stream.
 String toString()
          Returns a string representation of the object.
 void writeExternal(ObjectOutput out)
          Marshals this SHADocumentId to the specified output stream.
 
Methods inherited from class anthill.util.SHADigest
compareTo, compareTo, computeDigest, computeRandomSHA, getBytes, hashCode, initRandom, isCloser
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

length

protected int length
Length of the document

Constructor Detail

SHADocumentId

public SHADocumentId()
Default constructor for externalization.

Method Detail

computeSHADocumentId

protected void computeSHADocumentId(URL url)
                             throws IOException
Reads data from the specified URL and computes the length and digest components that comprise the SHADocumentId.

Parameters:
url - the URL from which to read the data needed to compute the SHADocumentId.
Throws:
IOException - if an error occurs

computeSHADocumentId

protected void computeSHADocumentId(String urlPath)
Computes a fake SHADocumentId based on the path component of the specified URL. This is useful for simulation purposes only.

Parameters:
urlPath - the path component of a URL.

computeHash

protected void computeHash()
Computes the hash code for this SHADocumentId.

Note that we wish to avoid computing the hashcode of a big integer every time, so therefore we compute the hashcode prior to its use and store it for future calls to the hashcode method.

Overrides:
computeHash in class SHADigest

getLength

public int getLength()
Returns the length component of the SHADocumentId.

Returns:
the length component of the SHADocumentId.

equals

public boolean equals(Object obj)
Check whether this SHADocumentId is equal to the specified object.

Overrides:
equals in class SHADigest
Parameters:
obj - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.

toString

public String toString()
Returns a string representation of the object.

Overrides:
toString in class SHADigest

readExternal

public void readExternal(ObjectInput in)
                  throws IOException
Marshals this SHADocumentId to the specified output stream.

Specified by:
readExternal in interface Externalizable
Overrides:
readExternal in class SHADigest
Parameters:
in - an ObjectInput stream object
Throws:
IOException - if an error occurs

writeExternal

public void writeExternal(ObjectOutput out)
                   throws IOException
Marshals this SHADocumentId to the specified output stream.

Specified by:
writeExternal in interface Externalizable
Overrides:
writeExternal in class SHADigest
Parameters:
out - an ObjectOutput stream object
Throws:
IOException - if an error occurs