Class WordLists


  • public final class WordLists
    extends Object
    Utility class for common operations on word lists.
    Author:
    Middleware Services
    • Field Detail

      • CASE_SENSITIVE_COMPARATOR

        public static final Comparator<String> CASE_SENSITIVE_COMPARATOR
        Case sensitive comparator.
      • CASE_INSENSITIVE_COMPARATOR

        public static final Comparator<String> CASE_INSENSITIVE_COMPARATOR
        Case insensitive comparator.
      • NOT_FOUND

        public static final int NOT_FOUND
        Index returned when word not found by binary search.
        See Also:
        Constant Field Values
    • Method Detail

      • binarySearch

        public static int binarySearch​(WordList wordList,
                                       String word)
        Performs a binary search of the given word list for the given word.
        Parameters:
        wordList - to search
        word - to search for
        Returns:
        index of supplied word in list or a negative number if not found.
      • createFromReader

        public static ArrayWordList createFromReader​(Reader[] readers)
                                              throws IOException
        Creates a case-sensitive ArrayWordList by reading the contents of the given readers.
        Parameters:
        readers - array of readers
        Returns:
        word list read from the given readers
        Throws:
        IOException - if an error occurs reading from a reader
      • createFromReader

        public static ArrayWordList createFromReader​(Reader[] readers,
                                                     boolean caseSensitive)
                                              throws IOException
        Creates an ArrayWordList by reading the contents of the given readers.
        Parameters:
        readers - array of readers
        caseSensitive - set to true to create case-sensitive word list (default), false otherwise
        Returns:
        word list read from the given readers
        Throws:
        IOException - if an error occurs reading from a reader
      • createFromReader

        public static ArrayWordList createFromReader​(Reader[] readers,
                                                     boolean caseSensitive,
                                                     ArraySorter sorter)
                                              throws IOException
        Creates an ArrayWordList by reading the contents of the given file with support for sorting file contents.
        Parameters:
        readers - array of readers
        caseSensitive - set to true to create case-sensitive word list (default), false otherwise
        sorter - to sort the input array with
        Returns:
        word list read from given readers
        Throws:
        IOException - if an error occurs reading from a reader
      • readWordList

        public static void readWordList​(Reader reader,
                                        List<String> wordList)
                                 throws IOException
        Reads words, one per line, from a reader into the given word list.
        Parameters:
        reader - Reader containing words, one per line. The reader is closed on completion.
        wordList - Destination word list.
        Throws:
        IOException - on IO errors reading from reader.