Package edu.ksu.cis.viewer
Class Trie
java.lang.Object
edu.ksu.cis.viewer.Trie
- All Implemented Interfaces:
BSTInterface
,TreeInterface
,Serializable
An immutable trie that can draw itself. The trie is immutable in
the sense that any Trie returned by a public constructor or method
cannot subsequently be changed. A trie is comprised of a nonempty tree
containing all of the characters used in the strings that it stores.
The root of the tree stores
null
, and its children store the
first characters of all of the strings stored. Characters occurring in
subsequent positions of a string are stored in children of the characters
they follow. Nodes that end contained strings are colored red, and other
nodes are colored black. Thus a string is contained in the trie if its
first character is a child of the root, its second character is a child
of that character, and so on until its last character is reached, and this
character is red. If the empty string is to be stored, the root will
be drawn red. The children of a given node will be drawn in order of
their Unicode values.- Author:
- Rod Howell (rhowell@ksu.edu)
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionclone()
Because this structure is immutable, this method simply returns thisTrie
.Returns the children of thisTrie
.Returns a drawing of thisTrie
.getDrawing
(Font fnt) Returns a drawing of this tree using the given Font.getRoot()
Returns the root of thisTrie
.boolean
isEmpty()
Always returnsfalse
.Returns theTrie
resulting from the insertion ofkey
into thisTrie
.Returns theTrie
resulting from the removal ofkey
from thisTrie
.
-
Constructor Details
-
Trie
public Trie()Constructs an empty Trie.
-
-
Method Details
-
put
Returns theTrie
resulting from the insertion ofkey
into thisTrie
. Ifkey
is already in thisTrie
, an identicalTrie
will be returned.- Specified by:
put
in interfaceBSTInterface
- Parameters:
key
- the key to insert- Returns:
- the resutling tree
- Throws:
NullPointerException
- Ifkey
isnull
-
remove
Returns theTrie
resulting from the removal ofkey
from thisTrie
. Ifkey
is not in thisTrie
, an identicalTrie
is returned.- Specified by:
remove
in interfaceBSTInterface
- Parameters:
key
- the key to remove- Returns:
- the resulting tree
- Throws:
NullPointerException
- If key isnull
-
getDrawing
Returns a drawing of thisTrie
.- Specified by:
getDrawing
in interfaceBSTInterface
- Returns:
- a drawing of the tree
-
getDrawing
Returns a drawing of this tree using the given Font.- Specified by:
getDrawing
in interfaceBSTInterface
- Parameters:
fnt
- the font to use- Returns:
- a drawing of the tree
- Throws:
NullPointerException
- iffnt
isnull
.
-
clone
Because this structure is immutable, this method simply returns thisTrie
.- Specified by:
clone
in interfaceBSTInterface
- Overrides:
clone
in classObject
- Returns:
- a clone of the this tree
-
getRoot
Returns the root of thisTrie
. This method is intended for use by theTreeDrawing
class.- Specified by:
getRoot
in interfaceTreeInterface
- Returns:
- the root of this tree
- See Also:
-
getChildren
Returns the children of thisTrie
. This method is intended for use by theTreeDrawing
class.- Specified by:
getChildren
in interfaceTreeInterface
- Returns:
- an array containing the children of this tree
-
isEmpty
public boolean isEmpty()Always returnsfalse
. This method is intended for use by theTreeDrawing
class.- Specified by:
isEmpty
in interfaceTreeInterface
- Returns:
- whether this tree is empty
-