/** * file : Word.java * desc : Implements a Word, which is a Hashable String * Words are automatically stored in lowercase */ import HashTable.Hashable; public class Word implements Hashable { /** post : initializes this word to have the value v, * in lowercase */ public Word( String v ) { word = v.toLowerCase(); } /** post : returns the String value of this word */ public String toString() { return word; } /** post : returns the length of the word */ public int length() { return word.length(); } /** post : Returns the hashed value of this String as an integer. * Hashed value in the range: * [0 .. Integer.MAX_VALUE] */ public int hashFunction() { // NOTE : This is hash function performs poorly // Replace it with your own if( word.length() == 0 ) return 0; int c = word.charAt(0) - 'a'; if( c < 0 ) c = -c; return c; } /** * pre : o poitns to a valid Word * post : returns true <==> string values are equal */ public boolean equals( Object o ) { Word wo = (Word)o; return word.equals(wo.word); } private String word; } // eof