public class Trie extends Object implements Serializable, Cloneable, Collection<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(String o)
Ensures that this collection contains the specified element.
|
boolean |
addAll(Collection<? extends String> c)
Adds all of the elements in the specified collection to this collection
|
void |
clear()
Removes all of the elements from this collection
|
Object |
clone()
returns a deep copy of itself
|
boolean |
contains(Object o)
Returns true if this collection contains the specified element.
|
boolean |
containsAll(Collection<?> c)
Returns true if this collection contains all of the elements in the
specified collection.
|
boolean |
containsPrefix(String prefix)
checks whether the given prefix is stored in the trie
|
boolean |
equals(Object o)
Compares the specified object with this collection for equality.
|
String |
getCommonPrefix()
returns the common prefix for all the nodes
|
String |
getRevision()
Returns the revision string.
|
Trie.TrieNode |
getRoot()
returns the root node of the trie
|
Vector<String> |
getWithPrefix(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.
|
Iterator<String> |
iterator()
Returns an iterator over the elements in this collection.
|
static void |
main(String[] args)
Only for testing (prints the built Trie).
|
boolean |
remove(Object o)
Removes a single instance of the specified element from this collection,
if it is present.
|
boolean |
removeAll(Collection<?> c)
Removes all this collection's elements that are also contained in the
specified collection
|
boolean |
retainAll(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.
|
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.
|
String |
toString()
returns the trie in string representation
|
parallelStream, removeIf, spliterator, stream
public boolean add(String o)
add
in interface Collection<String>
o
- the string to addpublic boolean addAll(Collection<? extends String> c)
addAll
in interface Collection<String>
c
- the collection to addpublic void clear()
clear
in interface Collection<String>
public Object clone()
public boolean contains(Object o)
contains
in interface Collection<String>
o
- the object to check for in triepublic boolean containsAll(Collection<?> c)
containsAll
in interface Collection<String>
c
- the collection to look for in the triepublic boolean containsPrefix(String prefix)
prefix
- the prefix to checkpublic boolean equals(Object o)
equals
in interface Collection<String>
equals
in class Object
o
- the object to check for equalitypublic String getCommonPrefix()
public Trie.TrieNode getRoot()
public Vector<String> getWithPrefix(String prefix)
prefix
- the prefix that all strings must havepublic int hashCode()
hashCode
in interface Collection<String>
hashCode
in class Object
public boolean isEmpty()
isEmpty
in interface Collection<String>
public Iterator<String> iterator()
public boolean remove(Object o)
remove
in interface Collection<String>
o
- the object to removepublic boolean removeAll(Collection<?> c)
removeAll
in interface Collection<String>
c
- the collection to removepublic boolean retainAll(Collection<?> c)
retainAll
in interface Collection<String>
c
- the collection to use as referencepublic int size()
size
in interface Collection<String>
public Object[] toArray()
toArray
in interface Collection<String>
public <T> T[] toArray(T[] a)
toArray
in interface Collection<String>
a
- the array into which the elements of this collection
are to be storedpublic String toString()
public String getRevision()
getRevision
in interface RevisionHandler
public static void main(String[] args)
args
- commandline argumentsCopyright © 2019 University of Waikato, Hamilton, NZ. All rights reserved.