Class WordLists

java.lang.Object
org.passay.dictionary.WordLists

public final class WordLists extends Object
Utility class for common operations on word lists.
  • Field Details

    • CASE_SENSITIVE_COMPARATOR

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

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

      private static final int NOT_FOUND
      Index returned when word not found by binary search.
      See Also:
  • Constructor Details

    • WordLists

      private WordLists()
      Private constructor of utility class.
  • Method Details

    • binarySearch

      public static int binarySearch(WordList wordList, CharSequence 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
    • readWords

      public static void readWords(Reader reader, List<String> words) throws IOException
      Reads words, one per line, from a reader into the given word list.

      This method does not close the reader.

      Parameters:
      reader - the reader to read words from
      words - the list to which the words are added
      Throws:
      IOException - if an error occurs
    • readWords

      public static void readWords(InputStream in, String charset, List<String> words) throws IOException
      Reads words, one per line, from an input stream into the given word list.

      This method does not close the input stream.

      Parameters:
      in - the input stream to read words from
      charset - the charset used to decode text from the stream
      words - the list to which the words are added
      Throws:
      IOException - if an error occurs
    • readZippedWords

      public static void readZippedWords(InputStream in, String charset, String regex, List<String> words) throws IOException
      Reads words, one per line, from an input stream into the given word list. The input stream is assumed to contain compressed data in the ZIP format.

      This method does not close the input stream.

      Parameters:
      in - the input stream containing compressed data to read words from
      charset - the charset used to decode text from the stream
      regex - a regular expression that is used to match the ZIP entry names to determine which of the entries should be read, or null if all entries should be read
      words - the list to which the words are added
      Throws:
      IOException - if an error occurs
    • readWordList

      public static void readWordList(Reader reader, List<String> words) 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.
      words - Destination word list.
      Throws:
      IOException - on IO errors reading from reader.