cmsc433.p3
Class Dictionary

java.lang.Object
  extended by cmsc433.p3.Dictionary
All Implemented Interfaces:
java.lang.Iterable<java.lang.String>

public class Dictionary
extends java.lang.Object
implements java.lang.Iterable<java.lang.String>

The Dictionary is a set of words used to determine whether a given solution for a grid is legal. The score for a given word depends on its length and its frequency in the dictionary. This class is immutable, so it is thread-safe.


Field Summary
 int MAX_WORD_LEN
           
 
Method Summary
 int getScore(int wordLength)
          Returns the score that a word would have gotten based only on it's length.
 java.util.Iterator<java.lang.String> iterator()
           
static Dictionary makeDict(java.lang.String file)
          Constructs a dictionary from an input file.
 boolean member(java.lang.String word)
          Determines whether a given word is in the dictionary.
 int score(java.lang.String word)
          Computes the score for the given word, based on its length and the distribution of words having that length in the dictionary.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_WORD_LEN

public final int MAX_WORD_LEN
See Also:
Constant Field Values
Method Detail

makeDict

public static Dictionary makeDict(java.lang.String file)
Constructs a dictionary from an input file. The file should contain one word per line. Duplicate words are discarded.

Parameters:
file - - contains the words for the dictionary
Returns:
a dictionary object representing these words

member

public boolean member(java.lang.String word)
Determines whether a given word is in the dictionary.

Parameters:
word -
Returns:
whether it appears in the dictionary

score

public int score(java.lang.String word)
Computes the score for the given word, based on its length and the distribution of words having that length in the dictionary.

Parameters:
word -
Returns:
the score for the word

getScore

public int getScore(int wordLength)
Returns the score that a word would have gotten based only on it's length.

Parameters:
wordLength -
Returns:
the score for the word

iterator

public java.util.Iterator<java.lang.String> iterator()
Specified by:
iterator in interface java.lang.Iterable<java.lang.String>