bill.apps.wordutil
Class WordList

java.lang.Object
  |
  +--bill.apps.wordutil.WordList

public class WordList
extends Object

This class holds the list of words to search for. In order to speed up searches it also maintains a list of all the possible 2-x character combinations which can be used to start a word. When creating words, this list can be checked to see whether we should continue along this path.


Constructor Summary
WordList(String fileName)
          Creator.
WordList(String fileName, int charNum)
          Creator.
 
Method Summary
 boolean addWord(String word)
          Adds a word to the word list.
 boolean containsChar(String word)
          Checks if the first x characters are used in any words I know.
 boolean containsWord(String word)
          Checks is a word is contained in the word list.
 void dumpWords()
          Dumps all the words in the word set to standard out as plain text.
 void dumpWords(PrintStream stream)
          Dumps all the words in the word set to the specified stream as plain text.
 void dumpWords(String fileName)
          Dumps all the words in the word set to the specified file name as plain text.
 String getFileName()
          Getter for the name of the file associated with this word set.
 int getNumberOfWords()
          Determines the number of words that are contained in the word list.
 void initialize()
          Initializes the class instance by validating the input file and reading its contents.
 boolean removeWord(String word)
          Removes a word from the word list.
 void saveWords()
          Saves the word list to a file.
 void setFileName(String newName)
          Setter for the name of the file associated with this word set.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WordList

public WordList(String fileName)
         throws FileNotFoundException,
                IOException,
                WordGamesException
Creator.
Parameters:
fileName - Name of the file words are stored in.
Throws:
FileNotFoundException - Indicates the file name passed in does not exist or cannot be accessed.
IOException - File was found but an error occurred while reading it.
WordGamesException - Thrown when the specified file name is not null and cannot be successfully read. Typically caused by a corrupt file.

WordList

public WordList(String fileName,
                int charNum)
         throws FileNotFoundException,
                IOException,
                WordGamesException
Creator.
Parameters:
fileName - Name of the file words are stored in.
charNum - Number of starting character lists to create.
Throws:
FileNotFoundException - Indicates the file name passed in does not exist or cannot be accessed.
IOException - File was found but an error occurred while reading it.
WordGamesException - Thrown when the specified file name is not null and cannot be successfully read.
Method Detail

getFileName

public String getFileName()
Getter for the name of the file associated with this word set.
Returns:
The associated file name.

setFileName

public void setFileName(String newName)
Setter for the name of the file associated with this word set.
Parameters:
newName - The new associated file name.

getNumberOfWords

public int getNumberOfWords()
Determines the number of words that are contained in the word list.
Returns:
The number of words.

saveWords

public void saveWords()
               throws WordGamesException
Saves the word list to a file.

addWord

public boolean addWord(String word)
Adds a word to the word list. Note that this returns false if the word is already in the word list.
Parameters:
word - Word to be added.
Returns:
true if the word is added, false otherwise.

removeWord

public boolean removeWord(String word)
Removes a word from the word list. Note that this returns false if the word is not in the word list.
Parameters:
word - Word to be removed.
Returns:
true if the word is removed, false otherwise.

containsWord

public boolean containsWord(String word)
Checks is a word is contained in the word list.
Parameters:
word - Word to be look for.
Returns:
true if the word is found in the word list, false otherwise.

containsChar

public boolean containsChar(String word)
Checks if the first x characters are used in any words I know.
Parameters:
word - Characters of word to be look for.
Returns:
true if the characters are found in the x character list, false otherwise.

initialize

public void initialize()
                throws FileNotFoundException,
                       IOException,
                       WordGamesException
Initializes the class instance by validating the input file and reading its contents.
Throws:
FileNotFoundException - Indicates the file name passed in does not exist or cannot be accessed.
IOException - File was found but an error occurred while reading it.
WordGamesException - A processing error was encountered while reading the word list file, typically caused by a corrupt file.

dumpWords

public void dumpWords()
Dumps all the words in the word set to standard out as plain text.

dumpWords

public void dumpWords(String fileName)
               throws FileNotFoundException
Dumps all the words in the word set to the specified file name as plain text.
Parameters:
fileName - The name of the file to write the word set to.
FileNotFoundException - Thrown if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason

dumpWords

public void dumpWords(PrintStream stream)
Dumps all the words in the word set to the specified stream as plain text.
Parameters:
stream - The stream to write the word set to.