bill.apps.wordsearch
Class WordSearch

java.lang.Object
  |
  +--bill.apps.wordsearch.WordSearch

public class WordSearch
extends Object

This class controls the checking of the letter list for words.


Constructor Summary
WordSearch()
          Class creator.
 
Method Summary
 String findWord(int numWords)
          Controls the finding of words in the given letters.
 Vector getLetters()
          Retrieves the list of letters available for making words out of.
 String getWordFile()
          Word list file name getter.
 Vector getWordLengths()
          get the list of word lengths for the words we are trying to create.
 int getWordListSize()
          Determines the number of words that are contained in the word list.
 void init()
          Clears out instance variables and resets them to an 'empty' status.
 boolean initializeLengthsFromSysIn()
          Gets the list of word lengths from the user using System.in.
 boolean initializeLettersFromSysIn()
          Gets the letters that are available to create our word(s) from.
 boolean isValidWord(String word)
          Checks if the specified word is valid.
 void setLetters(String letters)
          Sets the list of letters available for making words out of.
 void setLetters(Vector letters)
          Sets the list of letters available for making words out of.
 void setWordLengths(Vector lengths)
          Set the list of word lengths for the words we are trying to create.
 void setWordList(WordList wordList)
          Word list setter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WordSearch

public WordSearch()
Class creator. Sets class variables to defaults.
Method Detail

init

public void init()
Clears out instance variables and resets them to an 'empty' status.

getWordListSize

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

setWordList

public void setWordList(WordList wordList)
Word list setter. Sets the class instance's word list to the provided list.
Parameters:
wordList - The word list to be used

getWordFile

public String getWordFile()
Word list file name getter.
Returns:
The name of the word list file

getWordLengths

public Vector getWordLengths()
get the list of word lengths for the words we are trying to create. Each element in this vector is an Integer object representing the number of letters in the word.
Returns:
The Vector of word lengths.

setWordLengths

public void setWordLengths(Vector lengths)
Set the list of word lengths for the words we are trying to create. Each element in this vector is an Integer object representing the number of letters in the word.
Parameters:
lengths - The Vector of word lengths.

isValidWord

public boolean isValidWord(String word)
Checks if the specified word is valid. Valid means it is in the word list.
Parameters:
word - The word to check the validity of.
Returns:
Returns true if the word is valid, returns false otherwise.

getLetters

public Vector getLetters()
Retrieves the list of letters available for making words out of.
Returns:
The list of available letters, the Vector contains WordSearchLetter objects.

setLetters

public void setLetters(Vector letters)
Sets the list of letters available for making words out of.
Parameters:
letters - A Vector containing the letters that are available. Note that this must contain WordSearchLetter objects.

setLetters

public void setLetters(String letters)
Sets the list of letters available for making words out of.
Parameters:
letters - A String containing the letters that are available.

initializeLengthsFromSysIn

public boolean initializeLengthsFromSysIn()
Gets the list of word lengths from the user using System.in.
Returns:
true if the lengths are read successfully, false otherwise.

initializeLettersFromSysIn

public boolean initializeLettersFromSysIn()
Gets the letters that are available to create our word(s) from.
Returns:
true if the letters are read successfully, false otherwise.

findWord

public String findWord(int numWords)
Controls the finding of words in the given letters. This requires looping through our available letters and attempting to build words out of them. When we find a word we then check if we are searching for additional words. If so, we then search the remaining letters for the additional words.
Parameters:
numWords - The number of words we still need to find in the list of letters.
Returns:
The word that we found, or null if no words were found.