|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.vt.middleware.dictionary.TernaryTree
public class TernaryTree
TernaryTree is an implementation of a ternary tree. Methods are
provided for inserting strings and searching for strings. The algorithms in
this class are all recursive, and have not been optimized for any particular
purpose. Data which is inserted is not sorted before insertion, however data
can be inserted beginning with the median of the supplied data.
| Field Summary | |
|---|---|
protected static java.util.Comparator<java.lang.Character> |
CASE_INSENSITIVE_COMPARATOR
Case insensitive comparator. |
protected static java.util.Comparator<java.lang.Character> |
CASE_SENSITIVE_COMPARATOR
Case sensitive comparator. |
protected java.util.Comparator<java.lang.Character> |
comparator
Character comparator. |
| Constructor Summary | |
|---|---|
TernaryTree()
Creates an empty case sensitive ternary tree. |
|
TernaryTree(boolean caseSensitive)
Creates an empty ternary tree with the given case sensitivity. |
|
| Method Summary | |
|---|---|
java.util.List<java.lang.String> |
getWords()
This will return a list of all the words in this TernaryTree. |
void |
insert(java.lang.String word)
This will insert the supplied word into the TernaryTree. |
void |
insert(java.lang.String[] words)
This will insert the supplied array of words into the
TernaryTree. |
java.lang.String[] |
nearSearch(java.lang.String word,
int distance)
This will return an array of strings which are near to the supplied word by the supplied distance. |
java.lang.String[] |
partialSearch(java.lang.String word)
This will return an array of strings which partially match the supplied word. |
void |
print(java.io.Writer out)
This will print an ASCII representation of this TernaryTree to
the supplied PrintWriter. |
boolean |
search(java.lang.String word)
This will return true if the supplied word has been inserted into the TernaryTree. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected static final java.util.Comparator<java.lang.Character> CASE_SENSITIVE_COMPARATOR
protected static final java.util.Comparator<java.lang.Character> CASE_INSENSITIVE_COMPARATOR
protected java.util.Comparator<java.lang.Character> comparator
| Constructor Detail |
|---|
public TernaryTree()
public TernaryTree(boolean caseSensitive)
caseSensitive - True to create case-sensitive tree, false otherwise.| Method Detail |
|---|
public void insert(java.lang.String word)
TernaryTree.
word - String to insertpublic void insert(java.lang.String[] words)
TernaryTree.
words - String[] to insertpublic boolean search(java.lang.String word)
TernaryTree.
word - String to search for
boolean - whether word was foundpublic java.lang.String[] partialSearch(java.lang.String word)
NOTE This method is not supported for case insensitive ternary trees. Since the tree is built without regard to case any words returned from the tree may or may not match the case of the supplied word.
word - String to search for
String[] - of matching words
java.lang.UnsupportedOperationException - if this is a case insensitive
ternary tree
public java.lang.String[] nearSearch(java.lang.String word,
int distance)
NOTE This method is not supported for case insensitive ternary trees. Since the tree is built without regard to case any words returned from the tree may or may not match the case of the supplied word.
word - String to search fordistance - int for valid match
String[] - of matching words
java.lang.UnsupportedOperationException - if this is a case insensitive
ternary treepublic java.util.List<java.lang.String> getWords()
TernaryTree.
This is a very expensive operation, every node in the tree is traversed.
The returned list cannot be modified.
String[] - of words
public void print(java.io.Writer out)
throws java.io.IOException
TernaryTree to
the supplied PrintWriter. This is a very expensive operation,
every node in the tree is traversed. The output produced is hard to read,
but it should give an indication of whether or not your tree is balanced.
out - PrintWriter to print to
java.io.IOException - if an error occurs
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||