class PrefixTree
extends java.util.AbstractCollection<java.lang.String>
Modifier and Type | Field and Description |
---|---|
protected int |
prefixLength
Stores the requested prefix length.
|
protected int |
size
Store the number of elements contained by this PrefixTree and its
sub-trees.
|
protected JavaScriptObject |
subtrees
Field to store subtrees in.
|
protected JavaScriptObject |
suffixes
Field to store terminal nodes in.
|
Constructor and Description |
---|
PrefixTree()
Constructor.
|
PrefixTree(java.util.Collection<java.lang.String> source)
Constructor.
|
PrefixTree(int prefixLength)
Constructor.
|
PrefixTree(int prefixLength,
java.util.Collection<java.lang.String> source)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
add(java.lang.String s)
Add a String to the PrefixTree.
|
void |
clear()
Initialize native state.
|
boolean |
contains(java.lang.Object o) |
boolean |
contains(java.lang.String s) |
protected static PrefixTree |
createPrefixTree(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() |
int |
size()
Get the number of all elements contained within the PrefixTree.
|
protected void |
suggestImpl(java.lang.String search,
java.lang.String prefix,
java.util.Collection<java.lang.String> output,
int limit) |
addAll, containsAll, isEmpty, remove, removeAll, retainAll, toArray, toArray, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
protected final int prefixLength
protected JavaScriptObject suffixes
protected JavaScriptObject subtrees
protected int size
public PrefixTree()
public PrefixTree(java.util.Collection<java.lang.String> source)
source
- Initialize from another collectionpublic PrefixTree(int prefixLength)
prefixLength
- Smaller prefix length equals faster, more direct
searches, at a cost of setup time.public PrefixTree(int prefixLength, java.util.Collection<java.lang.String> source)
prefixLength
- Smaller prefix length equals faster, more direct
searches, at a cost of setup time.source
- Initialize from another collectionprotected static PrefixTree createPrefixTree(int prefixLength)
prefixLength
- Smaller prefix length equals faster, more direct
searches, at a cost of setup timepublic boolean add(java.lang.String s)
add
in interface java.util.Collection<java.lang.String>
add
in class java.util.AbstractCollection<java.lang.String>
s
- The data to addtrue
if the string was added, false
otherwisepublic void clear()
clear
in interface java.util.Collection<java.lang.String>
clear
in class java.util.AbstractCollection<java.lang.String>
public boolean contains(java.lang.Object o)
contains
in interface java.util.Collection<java.lang.String>
contains
in class java.util.AbstractCollection<java.lang.String>
public boolean contains(java.lang.String s)
public java.util.List<java.lang.String> getSuggestions(java.lang.String search, int limit)
limit
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.
search
- The prefix to search forlimit
- The desired number of results to retrievepublic 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>
iterator
in class java.util.AbstractCollection<java.lang.String>
public int size()
size
in interface java.util.Collection<java.lang.String>
size
in class java.util.AbstractCollection<java.lang.String>
protected void suggestImpl(java.lang.String search, java.lang.String prefix, java.util.Collection<java.lang.String> output, int limit)