Package com.google.gwt.user.client.ui
Class PrefixTree
- java.lang.Object
-
- java.util.AbstractCollection<java.lang.String>
-
- com.google.gwt.user.client.ui.PrefixTree
-
- All Implemented Interfaces:
java.lang.Iterable<java.lang.String>,java.util.Collection<java.lang.String>
class PrefixTree extends java.util.AbstractCollection<java.lang.String>A prefix tree (aka trie).
-
-
Field Summary
Fields Modifier and Type Field Description protected intprefixLengthStores the requested prefix length.protected intsizeStore the number of elements contained by this PrefixTree and its sub-trees.protected JavaScriptObjectsubtreesField to store subtrees in.protected JavaScriptObjectsuffixesField to store terminal nodes in.
-
Constructor Summary
Constructors Constructor Description PrefixTree()Constructor.PrefixTree(int prefixLength)Constructor.PrefixTree(int prefixLength, java.util.Collection<java.lang.String> source)Constructor.PrefixTree(java.util.Collection<java.lang.String> source)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(java.lang.String s)Add a String to the PrefixTree.voidclear()Initialize native state.booleancontains(java.lang.Object o)booleancontains(java.lang.String s)protected static PrefixTreecreatePrefixTree(int prefixLength)Used by native methods to create an appropriately blessed PrefixTree.java.util.List<java.lang.String>getSuggestions(java.lang.String search, int limit)Retrieve suggestions from the PrefixTree.java.util.Iterator<java.lang.String>iterator()intsize()Get the number of all elements contained within the PrefixTree.protected voidsuggestImpl(java.lang.String search, java.lang.String prefix, java.util.Collection<java.lang.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
-
-
-
-
Field Detail
-
prefixLength
protected final int prefixLength
Stores the requested prefix length.
-
suffixes
protected JavaScriptObject suffixes
Field to store terminal nodes in.
-
subtrees
protected JavaScriptObject subtrees
Field to store subtrees in.
-
size
protected int size
Store the number of elements contained by this PrefixTree and its sub-trees.
-
-
Constructor Detail
-
PrefixTree
public PrefixTree()
Constructor.
-
PrefixTree
public PrefixTree(java.util.Collection<java.lang.String> source)
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
public PrefixTree(int prefixLength, java.util.Collection<java.lang.String> source)Constructor.- Parameters:
prefixLength- Smaller prefix length equals faster, more direct searches, at a cost of setup time.source- Initialize from another collection
-
-
Method Detail
-
createPrefixTree
protected static PrefixTree createPrefixTree(int prefixLength)
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
public boolean add(java.lang.String s)
Add a String to the PrefixTree.- Specified by:
addin interfacejava.util.Collection<java.lang.String>- Overrides:
addin classjava.util.AbstractCollection<java.lang.String>- Parameters:
s- The data to add- Returns:
trueif the string was added,falseotherwise
-
clear
public void clear()
Initialize native state.- Specified by:
clearin interfacejava.util.Collection<java.lang.String>- Overrides:
clearin classjava.util.AbstractCollection<java.lang.String>
-
contains
public boolean contains(java.lang.Object o)
- Specified by:
containsin interfacejava.util.Collection<java.lang.String>- Overrides:
containsin classjava.util.AbstractCollection<java.lang.String>
-
contains
public boolean contains(java.lang.String s)
-
getSuggestions
public java.util.List<java.lang.String> getSuggestions(java.lang.String search, int limit)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
public java.util.Iterator<java.lang.String> iterator()
- Specified by:
iteratorin interfacejava.util.Collection<java.lang.String>- Specified by:
iteratorin interfacejava.lang.Iterable<java.lang.String>- Specified by:
iteratorin classjava.util.AbstractCollection<java.lang.String>
-
size
public int size()
Get the number of all elements contained within the PrefixTree.- Specified by:
sizein interfacejava.util.Collection<java.lang.String>- Specified by:
sizein classjava.util.AbstractCollection<java.lang.String>- Returns:
- the size of the prefix tree
-
suggestImpl
protected void suggestImpl(java.lang.String search, java.lang.String prefix, java.util.Collection<java.lang.String> output, int limit)
-
-