Class WordListDictionary

java.lang.Object
org.passay.dictionary.WordListDictionary
All Implemented Interfaces:
Dictionary

public class WordListDictionary extends Object implements Dictionary
Provides fast searching for dictionary words using a word list. It's critical that the word list provided to this dictionary be sorted according to the natural ordering of String.
  • Field Details

    • wordList

      protected final WordList wordList
      list used for searching.
  • Constructor Details

    • WordListDictionary

      public WordListDictionary(WordList wl)
      Creates a new dictionary instance from the supplied WordList.
      Parameters:
      wl - list of words sorted according to WordList.getComparator().

      NOTE Failure to provide a sorted word list will produce incorrect results.

  • Method Details

    • getWordList

      public WordList getWordList()
      Returns the word list used for searching.
      Returns:
      word list
    • size

      public long size()
      Description copied from interface: Dictionary
      Returns the number of words in this dictionary
      Specified by:
      size in interface Dictionary
      Returns:
      total number of words to search
    • search

      public boolean search(CharSequence word)
      Description copied from interface: Dictionary
      Returns whether the supplied word exists in the dictionary.
      Specified by:
      search in interface Dictionary
      Parameters:
      word - to search for
      Returns:
      whether word was found
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • main

      public static void main(String[] args) throws Exception
      Provides command line access to this word list dictionary.
      Parameters:
      args - command line arguments
      Throws:
      Exception - if an error occurs