Package com.google.gwt.user.client.ui
Class PrefixTree
- All Implemented Interfaces:
Iterable<String>,Collection<String>
A prefix tree (aka trie).
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final intStores the requested prefix length.protected intStore the number of elements contained by this PrefixTree and its sub-trees.protected JavaScriptObjectField to store subtrees in.protected JavaScriptObjectField to store terminal nodes in. -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.PrefixTree(int prefixLength) Constructor.PrefixTree(int prefixLength, Collection<String> source) Constructor.PrefixTree(Collection<String> source) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionbooleanAdd a String to the PrefixTree.voidclear()Initialize native state.booleanbooleanprotected static PrefixTreecreatePrefixTree(int prefixLength) Used by native methods to create an appropriately blessed PrefixTree.getSuggestions(String search, int limit) Retrieve suggestions from the PrefixTree.iterator()intsize()Get the number of all elements contained within the PrefixTree.protected voidsuggestImpl(String search, String prefix, Collection<String> output, int limit) Methods inherited from class java.util.AbstractCollection
addAll, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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:
addin interfaceCollection<String>- Overrides:
addin classAbstractCollection<String>- Parameters:
s- The data to add- Returns:
trueif the string was added,falseotherwise
-
clear
public void clear()Initialize native state.- Specified by:
clearin interfaceCollection<String>- Overrides:
clearin classAbstractCollection<String>
-
contains
- Specified by:
containsin interfaceCollection<String>- Overrides:
containsin classAbstractCollection<String>
-
contains
-
getSuggestions
Retrieve suggestions from the PrefixTree. The number of items returned from getSuggestions may slightly exceedlimitso 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:
iteratorin interfaceCollection<String>- Specified by:
iteratorin interfaceIterable<String>- Specified by:
iteratorin classAbstractCollection<String>
-
size
public int size()Get the number of all elements contained within the PrefixTree.- Specified by:
sizein interfaceCollection<String>- Specified by:
sizein classAbstractCollection<String>- Returns:
- the size of the prefix tree
-
suggestImpl
-