Package org.passay.dictionary
Class WordLists
java.lang.Object
org.passay.dictionary.WordLists
Utility class for common operations on word lists.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Comparator<CharSequence>Case insensitive comparator.static final Comparator<CharSequence>Case sensitive comparator.private static final intIndex returned when word not found by binary search. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intbinarySearch(WordList wordList, CharSequence word) Performs a binary search of the given word list for the given word.static ArrayWordListcreateFromReader(Reader[] readers) Creates a case-sensitiveArrayWordListby reading the contents of the given readers.static ArrayWordListcreateFromReader(Reader[] readers, boolean caseSensitive) Creates anArrayWordListby reading the contents of the given readers.static ArrayWordListcreateFromReader(Reader[] readers, boolean caseSensitive, ArraySorter sorter) Creates anArrayWordListby reading the contents of the given file with support for sorting file contents.static voidreadWordList(Reader reader, List<String> words) Reads words, one per line, from a reader into the given word list.static voidreadWords(InputStream in, String charset, List<String> words) Reads words, one per line, from an input stream into the given word list.static voidReads words, one per line, from a reader into the given word list.static voidreadZippedWords(InputStream in, String charset, String regex, List<String> words) Reads words, one per line, from an input stream into the given word list.
-
Field Details
-
CASE_SENSITIVE_COMPARATOR
Case sensitive comparator. -
CASE_INSENSITIVE_COMPARATOR
Case insensitive comparator. -
NOT_FOUND
private static final int NOT_FOUNDIndex returned when word not found by binary search.- See Also:
-
-
Constructor Details
-
WordLists
private WordLists()Private constructor of utility class.
-
-
Method Details
-
binarySearch
Performs a binary search of the given word list for the given word.- Parameters:
wordList- to searchword- to search for- Returns:
- index of supplied word in list or a negative number if not found.
-
createFromReader
Creates a case-sensitiveArrayWordListby 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 anArrayWordListby reading the contents of the given readers.- Parameters:
readers- array of readerscaseSensitive- 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 anArrayWordListby reading the contents of the given file with support for sorting file contents.- Parameters:
readers- array of readerscaseSensitive- set to true to create case-sensitive word list (default), false otherwisesorter- to sort the input array with- Returns:
- word list read from given readers
- Throws:
IOException- if an error occurs reading from a reader
-
readWords
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 fromwords- the list to which the words are added- Throws:
IOException- if an error occurs
-
readWords
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 fromcharset- the charset used to decode text from the streamwords- 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 fromcharset- the charset used to decode text from the streamregex- 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 readwords- the list to which the words are added- Throws:
IOException- if an error occurs
-
readWordList
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.
-