public class SuggestTree
extends java.lang.Object
Note that this implementation is not synchronized. If multiple threads access a Suggest Tree concurrently, and at least one of the threads modifies the tree, it must be synchronized externally.
Modifier and Type | Class and Description |
---|---|
static class |
SuggestTree.Entry
A weighted term.
|
class |
SuggestTree.Iterator
An iterator over the terms in the tree.
|
static class |
SuggestTree.Node
A list of autocomplete suggestions, ordered from highest weight to lowest
weight.
|
Constructor and Description |
---|
SuggestTree(int k)
Creates a Suggest Tree with the specified k-value.
|
Modifier and Type | Method and Description |
---|---|
SuggestTree.Node |
getAutocompleteSuggestions(java.lang.String prefix)
Returns the k highest-weighted terms in the tree that start with the
specified prefix, or null if there is no such term.
|
SuggestTree.Entry |
getEntry(java.lang.String term)
Returns the tree entry for the specified term, or null if there is no
such entry.
|
SuggestTree.Iterator |
iterator()
Returns an iterator over the terms in the tree.
|
static void |
main(java.lang.String[] args) |
void |
put(java.lang.String term,
int weight)
Inserts the specified term with the specified weight into the tree, or
reweights the term if it is already present.
|
void |
remove(java.lang.String term)
Removes the specified term from the tree.
|
int |
size()
Returns the number of terms in the tree.
|
public SuggestTree(int k)
k
- the maximum number of autocomplete suggestions to return for a
given prefixjava.lang.IllegalArgumentException
- if the specified k-value is less than 1public final SuggestTree.Node getAutocompleteSuggestions(java.lang.String prefix)
prefix
- the prefix for which to return autocomplete suggestionsjava.lang.IllegalArgumentException
- if the specified prefix is an empty stringjava.lang.NullPointerException
- if the specified prefix is nullpublic SuggestTree.Entry getEntry(java.lang.String term)
term
- the term for which to return the corresponding tree entryjava.lang.IllegalArgumentException
- if the specified term is an empty stringjava.lang.NullPointerException
- if the specified term is nullpublic final SuggestTree.Iterator iterator()
public final int size()
public void put(java.lang.String term, int weight)
term
- the term to be inserted or reweightedweight
- the weight to be assigned to the termjava.lang.IllegalArgumentException
- if the specified term is an empty string or much too long
(longer than 32767 characters)java.lang.NullPointerException
- if the specified term is nullpublic void remove(java.lang.String term)
term
- the term to be removedjava.lang.IllegalArgumentException
- if the specified term is an empty stringjava.lang.NullPointerException
- if the specified term is nullpublic static void main(java.lang.String[] args)