Package com.google.gwt.user.client.ui
Class PrefixTree
- All Implemented Interfaces:
Iterable<String>
,Collection<String>
A prefix tree (aka trie).
-
Field Summary
Modifier and TypeFieldDescriptionprotected final int
Stores the requested prefix length.protected int
Store the number of elements contained by this PrefixTree and its sub-trees.protected JavaScriptObject
Field to store subtrees in.protected JavaScriptObject
Field to store terminal nodes in. -
Constructor Summary
ConstructorDescriptionConstructor.PrefixTree
(int prefixLength) Constructor.PrefixTree
(int prefixLength, Collection<String> source) Constructor.PrefixTree
(Collection<String> source) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Add a String to the PrefixTree.void
clear()
Initialize native state.boolean
boolean
protected static PrefixTree
createPrefixTree
(int prefixLength) Used by native methods to create an appropriately blessed PrefixTree.getSuggestions
(String search, int limit) Retrieve suggestions from the PrefixTree.iterator()
int
size()
Get the number of all elements contained within the PrefixTree.protected void
suggestImpl
(String search, String prefix, Collection<String> output, int limit) Methods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
Field Details
-
prefixLength
protected final int prefixLengthStores the requested prefix length. -
suffixes
Field to store terminal nodes in. -
subtrees
Field to store subtrees in. -
size
protected int sizeStore the number of elements contained by this PrefixTree and its sub-trees.
-
-
Constructor Details
-
PrefixTree
public PrefixTree()Constructor. -
PrefixTree
Constructor.- Parameters:
source
- Initialize from another collection
-
PrefixTree
public PrefixTree(int prefixLength) Constructor.- Parameters:
prefixLength
- Smaller prefix length equals faster, more direct searches, at a cost of setup time.
-
PrefixTree
Constructor.- Parameters:
prefixLength
- Smaller prefix length equals faster, more direct searches, at a cost of setup time.source
- Initialize from another collection
-
-
Method Details
-
createPrefixTree
Used by native methods to create an appropriately blessed PrefixTree.- Parameters:
prefixLength
- Smaller prefix length equals faster, more direct searches, at a cost of setup time- Returns:
- a newly constructed prefix tree
-
add
Add a String to the PrefixTree.- Specified by:
add
in interfaceCollection<String>
- Overrides:
add
in classAbstractCollection<String>
- Parameters:
s
- The data to add- Returns:
true
if the string was added,false
otherwise
-
clear
public void clear()Initialize native state.- Specified by:
clear
in interfaceCollection<String>
- Overrides:
clear
in classAbstractCollection<String>
-
contains
- Specified by:
contains
in interfaceCollection<String>
- Overrides:
contains
in classAbstractCollection<String>
-
contains
-
getSuggestions
Retrieve suggestions from the PrefixTree. The number of items returned from getSuggestions may slightly exceedlimit
so that all suffixes and partial stems will be returned. This prevents the search space from changing size if the PrefixTree is used in an interactive manner.
The returned List is guaranteed to be safe; changing its contents will not affect the PrefixTree.- Parameters:
search
- The prefix to search forlimit
- The desired number of results to retrieve- Returns:
- A List of suggestions
-
iterator
- Specified by:
iterator
in interfaceCollection<String>
- Specified by:
iterator
in interfaceIterable<String>
- Specified by:
iterator
in classAbstractCollection<String>
-
size
public int size()Get the number of all elements contained within the PrefixTree.- Specified by:
size
in interfaceCollection<String>
- Specified by:
size
in classAbstractCollection<String>
- Returns:
- the size of the prefix tree
-
suggestImpl
-