public class Lexicon
extends Object
implements Iterable<String>, Set<String>
Lexicon
essentially a Set
of strings
that supports efficient lookup operations for words and prefixes.Constructor and Description |
---|
Lexicon() |
Lexicon(String filename) |
Lexicon(String word1,
String word2,
String... words) |
Modifier and Type | Method and Description |
---|---|
boolean |
add(String word) |
boolean |
addAll(Collection<? extends String> c) |
void |
addWordsFrom(InputStream input) |
void |
addWordsFrom(Reader reader) |
void |
addWordsFrom(Scanner input) |
void |
addWordsFromFile(File file) |
void |
addWordsFromFile(String filename) |
void |
clear() |
boolean |
contains(Object o) |
boolean |
contains(String word) |
boolean |
containsAll(Collection<?> c) |
boolean |
containsPrefix(String prefix)
Returns true if any words in the lexicon begin with
prefix . |
boolean |
equals(Object o) |
int |
hashCode() |
boolean |
isEmpty() |
Iterator<String> |
iterator() |
int |
prefixCount() |
boolean |
remove(Object word) |
boolean |
remove(String word) |
boolean |
removeAll(Collection<?> c) |
boolean |
retainAll(Collection<?> c) |
int |
size() |
Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
String |
toString() |
public Lexicon()
public Lexicon(String filename)
public Lexicon(String word1, String word2, String... words)
public boolean add(String word)
add
in interface Collection<String>
add
in interface Set<String>
public boolean addAll(Collection<? extends String> c)
addAll
in interface Collection<String>
addAll
in interface Set<String>
public void addWordsFrom(InputStream input)
public void addWordsFrom(Reader reader)
public void addWordsFrom(Scanner input)
public void addWordsFromFile(File file)
public void addWordsFromFile(String filename)
public void clear()
clear
in interface Collection<String>
clear
in interface Set<String>
public boolean contains(Object o)
contains
in interface Collection<String>
contains
in interface Set<String>
public boolean contains(String word)
public boolean containsAll(Collection<?> c)
containsAll
in interface Collection<String>
containsAll
in interface Set<String>
public boolean containsPrefix(String prefix)
prefix
.
Like containsWord
, this method ignores the case of letters
so that "MO" is a prefix of "monkey" or "Monday".
The empty string is a prefix of every string, so this method returns
true when passed the empty string.public boolean equals(Object o)
equals
in interface Collection<String>
equals
in interface Set<String>
equals
in class Object
public int hashCode()
hashCode
in interface Collection<String>
hashCode
in interface Set<String>
hashCode
in class Object
public boolean isEmpty()
isEmpty
in interface Collection<String>
isEmpty
in interface Set<String>
public Iterator<String> iterator()
iterator
in interface Iterable<String>
iterator
in interface Collection<String>
iterator
in interface Set<String>
public int prefixCount()
public boolean remove(Object word)
remove
in interface Collection<String>
remove
in interface Set<String>
public boolean remove(String word)
public boolean removeAll(Collection<?> c)
removeAll
in interface Collection<String>
removeAll
in interface Set<String>
public boolean retainAll(Collection<?> c)
retainAll
in interface Collection<String>
retainAll
in interface Set<String>
public int size()
size
in interface Collection<String>
size
in interface Set<String>
public String toString()
toString
in class Object
public Object[] toArray()
toArray
in interface Collection<String>
toArray
in interface Set<String>
public <T> T[] toArray(T[] a)
toArray
in interface Collection<String>
toArray
in interface Set<String>