anthill.types
Class SimpleHashedKeyword

java.lang.Object
  |
  +--anthill.types.SimpleHashedKeyword
All Implemented Interfaces:
Closeness, Comparable, HashedKeyword

public class SimpleHashedKeyword
extends Object
implements HashedKeyword

In this simple implementation of the HashedKeyword interface, keywords are hashed using the hashCode method of Java string. The main advantage of this implementation with respect to more robust hashing functions like SHA are its small memory footprint and its performance.

Version:
$Revision: 1.4 $
Author:
Alberto Montresor (montresor@cs.unibo.it)

Field Summary
 
Fields inherited from interface anthill.types.HashedKeyword
NAME
 
Constructor Summary
SimpleHashedKeyword(Factory factory, String name)
          Default constructor for externalization.
SimpleHashedKeyword(String keyword)
          Constructs a new hashed keyword starting from a plaintext keyword.
 
Method Summary
 int compareTo(Object obj)
          Compares this object with the specified object for order.
 boolean equals(Object obj)
          Check whether this hashed keyword is equal to the specified object.
 byte[] getBytes()
          Returns the bytes representing the hashed value of the keyword.
 String getKeyword()
          Returns the keyword associated with this hashed keyword.
 int hashCode()
          Returns a hash code value for the object.
 void init(String keyword)
          Initializes a new hashed keyword starting from a plaintext keyword.
 int isCloser(Object x, Object y)
          Compares this object against the provided objects for closeness.
 String toString()
          Returns a string representation of the object.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SimpleHashedKeyword

public SimpleHashedKeyword(Factory factory,
                           String name)
Default constructor for externalization.


SimpleHashedKeyword

public SimpleHashedKeyword(String keyword)
Constructs a new hashed keyword starting from a plaintext keyword. If the plaintext keyword is null, a random integer is generated and it is used as a keyword.

Method Detail

init

public void init(String keyword)
Initializes a new hashed keyword starting from a plaintext keyword. If the plaintext keyword is null, a random integer is generated and it is used as a keyword.

Specified by:
init in interface HashedKeyword

getKeyword

public String getKeyword()
Returns the keyword associated with this hashed keyword.

Specified by:
getKeyword in interface HashedKeyword

getBytes

public byte[] getBytes()
Returns the bytes representing the hashed value of the keyword.

Specified by:
getBytes in interface HashedKeyword

toString

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

Overrides:
toString in class Object

equals

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

Overrides:
equals in class Object

hashCode

public int hashCode()
Returns a hash code value for the object.

Overrides:
hashCode in class Object

compareTo

public int compareTo(Object obj)
              throws ClassCastException
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Specified by:
compareTo in interface Comparable
Parameters:
obj - the object to be compared
ClassCastException

isCloser

public int isCloser(Object x,
                    Object y)
Compares 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.
  

Specified by:
isCloser in interface Closeness
Throws:
ClassCastException - if x or y are not SimpleHashedKeyword objects