Package org.passay.dictionary
Class WordLists
- java.lang.Object
-
- org.passay.dictionary.WordLists
-
public final class WordLists extends Object
Utility class for common operations on word lists.- Author:
- Middleware Services
-
-
Field Summary
Fields Modifier and Type Field Description static Comparator<String>
CASE_INSENSITIVE_COMPARATOR
Case insensitive comparator.static Comparator<String>
CASE_SENSITIVE_COMPARATOR
Case sensitive comparator.static int
NOT_FOUND
Index returned when word not found by binary search.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
binarySearch(WordList wordList, String word)
Performs a binary search of the given word list for the given word.static ArrayWordList
createFromReader(Reader[] readers)
Creates a case-sensitiveArrayWordList
by reading the contents of the given readers.static ArrayWordList
createFromReader(Reader[] readers, boolean caseSensitive)
Creates anArrayWordList
by reading the contents of the given readers.static ArrayWordList
createFromReader(Reader[] readers, boolean caseSensitive, ArraySorter sorter)
Creates anArrayWordList
by reading the contents of the given file with support for sorting file contents.static void
readWordList(Reader reader, List<String> words)
Reads words, one per line, from a reader into the given word list.static void
readWords(InputStream in, String charset, List<String> words)
Reads words, one per line, from an input stream into the given word list.static void
readWords(Reader reader, List<String> words)
Reads words, one per line, from a reader into the given word list.static void
readZippedWords(InputStream in, String charset, String regex, List<String> words)
Reads words, one per line, from an input stream into the given word list.
-
-
-
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 searchword
- 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-sensitiveArrayWordList
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 anArrayWordList
by 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 anArrayWordList
by 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
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 fromwords
- 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 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
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.
-
-