becker.xtras.jotto
Class SampleWordList

java.lang.Object
  extended by becker.xtras.jotto.SampleWordList
All Implemented Interfaces:
IWordList

public final class SampleWordList
extends Object
implements IWordList

A list of words that can grow as needed.

Author:
Byron Weber Becker

Constructor Summary
SampleWordList()
          Create an word list by reading from the file included in the becker library.
SampleWordList(Scanner in)
          Create a word list from a file.
 
Method Summary
 void add(Word wd)
          Add a new word to the list.
 boolean contains(String aWord)
          Does the list of words contain a word-difficulty pair with the given word?
 Word getWord(IWordPredicate test)
          Find one word that passes the given test; the test is typically given by a Hint object (which implements IWordPredicate).
 Word[] getWords(int maxDesired, IWordPredicate test)
          Find at most maxDesired words that pass the given test; the test is typically given by a Hint object (which implements IWordPredicate).
 Word[] getWords(IWordPredicate test)
          Find all the words that pass the given test; the test is typically given by a Hint object (which implements IWordPredicate).
static void main(String[] args)
          Test the class.
 int numWords()
          The number of words in the list.
 Word randomWord()
          Find a random word.
 Word randomWord(int difficulty)
          Find a random word with the given difficulty in the list.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SampleWordList

public SampleWordList(Scanner in)
Create a word list from a file.


SampleWordList

public SampleWordList()
Create an word list by reading from the file included in the becker library.

Method Detail

add

public void add(Word wd)
Add a new word to the list.


contains

public boolean contains(String aWord)
Description copied from interface: IWordList
Does the list of words contain a word-difficulty pair with the given word?

Specified by:
contains in interface IWordList
Parameters:
aWord - a word to search for in the list
Returns:
true if the word is contained in the list; false otherwise.

numWords

public int numWords()
Description copied from interface: IWordList
The number of words in the list.

Specified by:
numWords in interface IWordList
Returns:
the number of words in the list.

randomWord

public Word randomWord()
Description copied from interface: IWordList
Find a random word. The list must contain at least one word.

Specified by:
randomWord in interface IWordList
Returns:
a random word from the list.

randomWord

public Word randomWord(int difficulty)
Description copied from interface: IWordList
Find a random word with the given difficulty in the list. The list must contain at least one such word.

Specified by:
randomWord in interface IWordList
Parameters:
difficulty - The required difficulty, one of 0..2
Returns:
a word with the required difficulty

getWord

public Word getWord(IWordPredicate test)
Description copied from interface: IWordList
Find one word that passes the given test; the test is typically given by a Hint object (which implements IWordPredicate). The method should start with a random word in the list and then proceed sequentially through the list until it either finds a word that passes the test or it it exhausts the list, in which case it returns null.

Specified by:
getWord in interface IWordList
Parameters:
test - The test that the Word must pass
Returns:
a word passing the test or null if no such word exists.

getWords

public Word[] getWords(IWordPredicate test)
Description copied from interface: IWordList
Find all the words that pass the given test; the test is typically given by a Hint object (which implements IWordPredicate).

Specified by:
getWords in interface IWordList
Parameters:
test - The test that each returned Word must pass.
Returns:
a filled array of Words that pass the test; an array with length 0 if no such words exist.

getWords

public Word[] getWords(int maxDesired,
                       IWordPredicate test)
Description copied from interface: IWordList
Find at most maxDesired words that pass the given test; the test is typically given by a Hint object (which implements IWordPredicate).

Specified by:
getWords in interface IWordList
Parameters:
maxDesired - the maximum number of words to return.
test - The test that each returned Word must pass.
Returns:
a filled array of Words that pass the test; an array with length 0 if no such words exist.

main

public static void main(String[] args)
Test the class.