ants.utils
Class DocumentKey

java.lang.Object
  |
  +--anthill.util.SHADigest
        |
        +--ants.utils.DocumentKey
All Implemented Interfaces:
Closeness, Comparable, Externalizable, Serializable

public class DocumentKey
extends SHADigest

Probabilistic identifier for a document.

Version:
$Revision: 1.2 $
Author:
Hein Meling
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
DocumentKey()
          Default constructor for externalization.
DocumentKey(String urlPath)
          Creates a deterministic DocumentKey instance for simulation purposes.
DocumentKey(URL url)
          Creates a DocumentKey instance for real deployment purposes.
 
Method Summary
 void computeDocumentKey(String urlPath)
          Computes a fake DocumentKey based on the path component of the specified URL.
 void computeDocumentKey(URL url)
          Reads data from the specified URL and computes the length and digest components that comprise the DocumentKey.
 void computeHash()
          Computes the hash code for this DocumentKey.
 boolean equals(Object obj)
          Check whether this DocumentKey is equal to the specified object.
 int getLength()
          Returns the length component of the DocumentKey.
 void readExternal(ObjectInput in)
          Marshals this DocumentKey to the specified output stream.
 String toString()
          Returns a string representation of the object.
 void writeExternal(ObjectOutput out)
          Marshals this DocumentKey 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

DocumentKey

public DocumentKey()
Default constructor for externalization.


DocumentKey

public DocumentKey(URL url)
            throws IOException
Creates a DocumentKey instance for real deployment purposes. It will read the content of the given URL and compute the digest and length components comprising the DocumentKey.

Parameters:
url - the URL for which we wish to compute a DocumentKey.

DocumentKey

public DocumentKey(String urlPath)
Creates a deterministic DocumentKey instance for simulation purposes. The URL path string is used to compute the digest and length, which comprises the document key. This computation is done deterministically.

Parameters:
urlPath - the URL path; can be fake since no checks are made.
Method Detail

computeDocumentKey

public void computeDocumentKey(URL url)
                        throws IOException
Reads data from the specified URL and computes the length and digest components that comprise the DocumentKey.

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

computeDocumentKey

public void computeDocumentKey(String urlPath)
Computes a fake DocumentKey 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

public void computeHash()
Computes the hash code for this DocumentKey.

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 DocumentKey.

Returns:
the length component of the DocumentKey.

equals

public boolean equals(Object obj)
Check whether this DocumentKey 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 DocumentKey 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 DocumentKey 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