Class 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.
    Author:
    Middleware Services
    • Field Detail

      • wordList

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

      • 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 Detail

      • 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​(String 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
      • 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