public class Trie extends java.lang.Object implements java.io.Serializable, java.lang.Cloneable, java.util.Collection<java.lang.String>, RevisionHandler
Modifier and Type | Class and Description |
---|---|
static class |
Trie.TrieIterator
Represents an iterator over a trie
|
static class |
Trie.TrieNode
Represents a node in the trie.
|
Constructor and Description |
---|
Trie()
initializes the data structure
|
Modifier and Type | Method and Description |
---|---|
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
|
java.lang.String |
getRevision()
Returns the revision string.
|
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.
|
<T> T[] |
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
|
public boolean add(java.lang.String o)
add
in interface java.util.Collection<java.lang.String>
o
- the string to addpublic 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 triepublic boolean containsAll(java.util.Collection<?> c)
containsAll
in interface java.util.Collection<java.lang.String>
c
- the collection to look for in the triepublic boolean containsPrefix(java.lang.String prefix)
prefix
- the prefix to checkpublic 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 havepublic 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 removepublic boolean removeAll(java.util.Collection<?> c)
removeAll
in interface java.util.Collection<java.lang.String>
c
- the collection to removepublic boolean retainAll(java.util.Collection<?> c)
retainAll
in interface java.util.Collection<java.lang.String>
c
- the collection to use as referencepublic 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 storedpublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String getRevision()
getRevision
in interface RevisionHandler
public static void main(java.lang.String[] args)
args
- commandline arguments