public class TernaryTree extends Object
Modifier and Type | Field and Description |
---|---|
protected static Comparator<Character> |
CASE_INSENSITIVE_COMPARATOR
Case insensitive comparator.
|
protected static Comparator<Character> |
CASE_SENSITIVE_COMPARATOR
Case sensitive comparator.
|
protected Comparator<Character> |
comparator
Character comparator.
|
Constructor and Description |
---|
TernaryTree()
Creates an empty case sensitive ternary tree.
|
TernaryTree(boolean caseSensitive)
Creates an empty ternary tree with the given case sensitivity.
|
Modifier and Type | Method and Description |
---|---|
protected Map<Integer,Integer> |
getNodeStats()
Returns a histogram of how many words end at each depth.
|
List<String> |
getWords()
Returns a list of all the words in this ternary tree.
|
void |
insert(String word)
Inserts the supplied word into this tree.
|
void |
insert(String[] words)
Inserts the supplied array of words into this tree.
|
String[] |
nearSearch(String word,
int distance)
Return an array of strings which are near to the supplied word by the supplied distance.
|
String[] |
partialSearch(String word)
Returns an array of strings which partially match the supplied word. word should be of the format '.e.e.e' Where
the '.' character represents any valid character.
|
void |
print(Writer out)
Prints an ASCII representation of this ternary tree to the supplied writer.
|
void |
print(Writer out,
boolean fullPath)
Prints an ASCII representation of this ternary tree to the supplied writer.
|
boolean |
search(String word)
Returns whether the supplied word has been inserted into this ternary tree.
|
protected static final Comparator<Character> CASE_SENSITIVE_COMPARATOR
protected static final Comparator<Character> CASE_INSENSITIVE_COMPARATOR
protected final Comparator<Character> comparator
public TernaryTree()
public TernaryTree(boolean caseSensitive)
caseSensitive
- whether this ternary tree should be case sensitive.public void insert(String word)
word
- to insertpublic void insert(String[] words)
words
- to insertpublic boolean search(String word)
word
- to search forpublic String[] partialSearch(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
- to search forUnsupportedOperationException
- if this is a case insensitive ternary treepublic String[] nearSearch(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
- to search fordistance
- for valid matchUnsupportedOperationException
- if this is a case insensitive ternary treepublic List<String> getWords()
public void print(Writer out, boolean fullPath) throws IOException
out
- to print tofullPath
- specifies whether each line should show the full path from root or only the suffixIOException
- if an error occurspublic void print(Writer out) throws IOException
out
- to print toIOException
- if an error occursCopyright © 2003-2024 Virginia Tech. All Rights Reserved.