becker.xtras.jotto
Interface IWordList

All Known Implementing Classes:
SampleWordList

public interface IWordList

Classes implementing IWordList provide a list of word-difficulty pairs (Word objects).

The becker library contains a file of approximately 4,250 word-difficulty pairs. This file may be opened with the following code:

 import java.io.*;
 ...
 InputStream inStream = IWordList.class.getResourceAsStream("words.txt");
 Scanner in = new Scanner(new InputStreamReader(inStream));
 

Alternatively, the file may be downloaded here.

Author:
Byron Weber Becker

Method Summary
 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).
 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.
 

Method Detail

contains

boolean contains(String aWord)
Does the list of words contain a word-difficulty pair with the given word?

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

numWords

int numWords()
The number of words in the list.

Returns:
the number of words in the list.

randomWord

Word randomWord()
Find a random word. The list must contain at least one word.

Returns:
a random word from the list.

randomWord

Word randomWord(int difficulty)
Find a random word with the given difficulty in the list. The list must contain at least one such word.

Parameters:
difficulty - The required difficulty, one of 0..2
Returns:
a word with the required difficulty

getWord

Word getWord(IWordPredicate test)
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.

Parameters:
test - The test that the Word must pass
Returns:
a word passing the test or null if no such word exists.

getWords

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).

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

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).

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.