|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectweka.core.Trie
public class Trie
A class representing a Trie data structure for strings. See also Trie on WikiPedia.
Nested Class Summary | |
---|---|
static class |
Trie.TrieIterator
Represents an iterator over a trie |
static class |
Trie.TrieNode
Represents a node in the trie. |
Constructor Summary | |
---|---|
Trie()
initializes the data structure |
Method Summary | ||
---|---|---|
boolean |
add(java.lang.String o)
Ensures that this collection contains the specified element. |
|
boolean |
addAll(java.util.Collection<? extends java.lang.String> c)
Adds all of the elements in the specified collection to this collection |
|
void |
clear()
Removes all of the elements from this collection |
|
java.lang.Object |
clone()
returns a deep copy of itself |
|
boolean |
contains(java.lang.Object o)
Returns true if this collection contains the specified element. |
|
boolean |
containsAll(java.util.Collection<?> c)
Returns true if this collection contains all of the elements in the specified collection. |
|
boolean |
containsPrefix(java.lang.String prefix)
checks whether the given prefix is stored in the trie |
|
boolean |
equals(java.lang.Object o)
Compares the specified object with this collection for equality. |
|
java.lang.String |
getCommonPrefix()
returns the common prefix for all the nodes |
|
Trie.TrieNode |
getRoot()
returns the root node of the trie |
|
java.util.Vector<java.lang.String> |
getWithPrefix(java.lang.String prefix)
returns all stored strings that match the given prefix |
|
int |
hashCode()
Returns the hash code value for this collection. |
|
boolean |
isEmpty()
Returns true if this collection contains no elements. |
|
java.util.Iterator<java.lang.String> |
iterator()
Returns an iterator over the elements in this collection. |
|
static void |
main(java.lang.String[] args)
Only for testing (prints the built Trie). |
|
boolean |
remove(java.lang.Object o)
Removes a single instance of the specified element from this collection, if it is present. |
|
boolean |
removeAll(java.util.Collection<?> c)
Removes all this collection's elements that are also contained in the specified collection |
|
boolean |
retainAll(java.util.Collection<?> c)
Retains only the elements in this collection that are contained in the specified collection |
|
int |
size()
Returns the number of elements in this collection. |
|
java.lang.Object[] |
toArray()
Returns an array containing all of the elements in this collection. |
|
|
toArray(T[] a)
Returns an array containing all of the elements in this collection; the runtime type of the returned array is that of the specified array. |
|
java.lang.String |
toString()
returns the trie in string representation |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public Trie()
Method Detail |
---|
public boolean add(java.lang.String o)
add
in interface java.util.Collection<java.lang.String>
o
- the string to add
public boolean addAll(java.util.Collection<? extends java.lang.String> c)
addAll
in interface java.util.Collection<java.lang.String>
c
- the collection to addpublic void clear()
clear
in interface java.util.Collection<java.lang.String>
public java.lang.Object clone()
clone
in class java.lang.Object
public boolean contains(java.lang.Object o)
contains
in interface java.util.Collection<java.lang.String>
o
- the object to check for in trie
public boolean containsAll(java.util.Collection<?> c)
containsAll
in interface java.util.Collection<java.lang.String>
c
- the collection to look for in the trie
public boolean containsPrefix(java.lang.String prefix)
prefix
- the prefix to check
public boolean equals(java.lang.Object o)
equals
in interface java.util.Collection<java.lang.String>
equals
in class java.lang.Object
o
- the object to check for equalitypublic java.lang.String getCommonPrefix()
public Trie.TrieNode getRoot()
public java.util.Vector<java.lang.String> getWithPrefix(java.lang.String prefix)
prefix
- the prefix that all strings must have
public int hashCode()
hashCode
in interface java.util.Collection<java.lang.String>
hashCode
in class java.lang.Object
public boolean isEmpty()
isEmpty
in interface java.util.Collection<java.lang.String>
public java.util.Iterator<java.lang.String> iterator()
iterator
in interface java.lang.Iterable<java.lang.String>
iterator
in interface java.util.Collection<java.lang.String>
public boolean remove(java.lang.Object o)
remove
in interface java.util.Collection<java.lang.String>
o
- the object to remove
public boolean removeAll(java.util.Collection<?> c)
removeAll
in interface java.util.Collection<java.lang.String>
c
- the collection to remove
public boolean retainAll(java.util.Collection<?> c)
retainAll
in interface java.util.Collection<java.lang.String>
c
- the collection to use as reference
public int size()
size
in interface java.util.Collection<java.lang.String>
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection<java.lang.String>
public <T> T[] toArray(T[] a)
toArray
in interface java.util.Collection<java.lang.String>
a
- the array into which the elements of this collection
are to be stored
public java.lang.String toString()
toString
in class java.lang.Object
public static void main(java.lang.String[] args)
args
- commandline arguments
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |