|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--BSTTree | +--BSTTreeHead
This class provides the head structure for a BSTTree
. It implements the
interface for TreeHead and implements all important methods necessary for maintaining a
Binary Search Tree.
The BSTTreeHead additionally extends BSTTree, using the information and methods of a
BSTTree in addition to the specialized methods of a BSTTreeHead.
Nested Class Summary | |
class |
BSTTreeHead.NodeAndKey
An object which keeps both a BSTTree node and an integer key. |
Field Summary | |
static int |
BINARY_DISPLAY
Binary Display |
static int |
SECTIONAL_DISPLAY
sectional display |
static java.lang.String |
TREE_INFORMATION
String representing information regarding the type of tree. |
Fields inherited from class BSTTree |
ANIMATING_BST_TREE_TYPE, BST_TREE_TYPE, DRAWING_BST_TREE_TYPE |
Fields inherited from interface TreeHead |
BALANCE_NODE, CHANGE_DISPLAY, INORDER_TRAVERSAL, INSERT_NODE, LEVELORDER_TRAVERSAL, PARTITION_NODE, POSTORDER_TRAVERSAL, PREORDER_TRAVERSAL, REMOVE_NODE, ROTATE_TO_TOP_NODE, ROTATE_UP, ROTATE_UP_DOUBLE, SEARCH, SELECT, SPLAY_NODE, TRAVERSE |
Constructor Summary | |
BSTTreeHead()
Constructs a new, null BSTTreeHead, sorted according to the keys' natural order. |
|
BSTTreeHead(int treeType)
Constructs a new, empty BSTTree according to the type passed. |
Method Summary | |
void |
addTreeAnimator(Animation a)
Adds the Animation to the list of Animations for the Head. |
void |
addTreeMessageListener(TreeMessageListener l)
Adds an TreeMessageListener from the TREE, according to the TreeMessageListener interface and the TreeMessageEvent . |
void |
AnimateTree(java.awt.Graphics2D g2)
Animates the entire BSTTree. |
void |
animationEventPerformed(AnimationEvent e)
Implements AnimationListener which requires the following method. |
double |
averageInsertion(int n)
Returns the average Insertion time, according to n, the amount of elements in the tree. |
double |
averageSearchHit(int n)
Returns the average Search hit time, according to n, the amount of elements in the tree. |
double |
averageSearchMiss(int n)
Returns the average Search miss time, according to n, the amount of elements in the tree. |
void |
balance(Tree node)
Balances the tree, from the node downward, recursively rotating the median to the top. |
void |
balanceAnimatingType(BSTTree node)
Balances the tree from the given node, recursively rotating the median to the top. |
void |
balanceTree()
Balances the entire tree, recursively rotating the median to the top. |
void |
balanceTreeType(BSTTree node)
Balances the tree from the given node, recursively rotating the median to the top. |
void |
changeDisplay()
Changes the display of the current tree. |
void |
changeDisplayAnimatingType()
Change Display of the BSTTree . |
void |
changeDisplayTreeType()
Change Display of the BSTTree . |
void |
clear()
Clears the BSTTree completely, removing all references to all nodes and all values return to the default. |
void |
clearAnimators()
Clears the Animation s from the list of Animations for the Head. |
void |
constructAnimatingBSTTreeHead()
Constructor for the ANIMATING_BST_TREE_TYPE. |
void |
constructBSTTreeHead()
Constructor for the BST_TREE_TYPE. |
void |
constructDrawingBSTTreeHead()
Constructor for the DRAWING_BST_TREE_TYPE. |
void |
DrawTree(java.awt.Graphics2D g2)
Draws the entire tree from the null head down. |
DrawingTree |
findNode(double x,
double y)
Finds the node represented by the x-y coordinates given. |
void |
fixLevel()
Fixes the lowest level of the Tree , using recursive calls into the BSTTree. |
int |
fixSize()
Fixes the size of each subtree, using recursive calls into the BSTTree. |
protected java.awt.Color |
getBackgroundColor()
Sets the background paint for the tree. |
Tree |
getChild()
Gets the child of the TreeHead. |
PaintSettings |
getDeleteLeftLinePaintSettings()
Gets the Paint for the left line of Paint. |
PaintSettings |
getDeleteRightLinePaintSettings()
Gets the Paint for the right line of Paint. |
int |
getDisplay()
Gets the display choice for the tree. |
KeySettings |
getDrawingKeySettings()
Gets the KeySettings for the entire tree. |
NodeSettings |
getDrawingNodeSettings()
Gets the NodeSettings for the entire tree. |
java.util.LinkedList |
getInorderTree()
Makes a inorder representation of the tree in an array of BSTTree s. |
KeySettings |
getInsertAnimatorKeySettings()
Gets the KeySettings for the animator key settings for insertion. |
NodeSettings |
getInsertAnimatorNodeSettings()
Gets the NodeSettings for the animator node settings for insertion. |
NodeSettings |
getInsertNodeLeftSettings()
Gets the NodeSettings for the left node settings for insertion. |
NodeSettings |
getInsertNodeRightSettings()
Gets the NodeSettings for the right node settings for insertion. |
java.util.LinkedList |
getLevelorderTree()
Makes a levelorder representation of the tree in an array of BSTTree s. |
double |
getNodeHeight()
Gets the height of the standard node within the tree. |
double |
getNodeWidth()
Gets the width of the standard node within the tree. |
java.util.LinkedList |
getPostorderTree()
Makes a postorder representation of the tree in an array of BSTTree s. |
java.util.LinkedList |
getPreorderTree()
Makes a preorder representation of the tree in an array of BSTTree s. |
int |
getPreviousDisplay()
Gets the previous display choice for the tree. |
KeySettings |
getRotateAnimatorKeySettings()
Gets the KeySettings for the animator key settings for rotation. |
NodeSettings |
getRotateChildNodeSettings()
Gets the NodeSettings for the child node settings for rotation. |
NodeSettings |
getRotateDescendantNodeSettings()
Gets the NodeSettings for the descendant node settings for rotation. |
KeySettings |
getRotateOriginalKeySettings()
Gets the KeySettings for the original key settings for rotation. |
NodeSettings |
getRotateOriginalNodeSettings()
Gets the NodeSettings for the original node settings for rotation. |
NodeSettings |
getRotateRootNodeSettings()
Gets the NodeSettings for the root node settings for rotation. |
java.awt.geom.Rectangle2D |
getScreenBounds()
Gets the bounds of the screen to which the tree is drawing. |
KeySettings |
getSearchAnimatorKeySettings()
Gets the KeySettings for the animator key settings for searching. |
NodeSettings |
getSearchAnimatorNodeSettings()
Gets the NodeSettings for the animator node settings for searching. |
NodeSettings |
getSearchNodeLeftSettings()
Gets the NodeSettings for the left node settings for searching. |
NodeSettings |
getSearchNodeRightSettings()
Gets the NodeSettings for the right node settings for searching. |
KeySettings |
getSelectAnimatorKeySettings()
Gets the KeySettings for the animator key settings for selection. |
NodeSettings |
getSelectAnimatorNodeSettings()
Gets the NodeSettings for the animator node settings for selection. |
NodeSettings |
getSelectNodeLeftSettings()
Gets the NodeSettings for the left node settings for selection. |
NodeSettings |
getSelectNodeRightSettings()
Gets the NodeSettings for the right node settings for selection. |
KeySettings |
getTraverseAnimatorKeySettings()
Gets the KeySettings for the animator key settings for traversal. |
NodeSettings |
getTraverseAnimatorNodeSettings()
Gets the NodeSettings for the animator node settings for traversal. |
int |
getTreeAnimationStepSize()
Gets the step size of the Animation s of the tree. |
Animation |
getTreeAnimator()
Gets the first Animation in the list of Animations for the Head and null if no
Animations are present. |
int |
getTreeLevel()
Gets the lowest level of the Tree. |
protected double |
getTreeSectionHeight()
Returns the height of the section, used for rendering the tree. |
java.lang.String |
getTreeStatus()
Gets the Tree's status, using the String status of Animation . |
java.lang.String |
getTreeStatusMessage()
Makes a new tree message. |
protected WaitingActionList |
getWaitingList()
Gets the WaitingActionList representing the waitingList for the tree. |
boolean |
insert(java.lang.Comparable keyInsert,
java.lang.Object valueInsert)
Inserts the comaparable object keyInsert to the tree using its natural ordering . |
void |
insert(Tree node)
Inserts the node to the tree using its natural ordering . |
protected void |
insertAnimatingType(BSTTree node)
Inserts the comaparable node to the tree using its natural ordering . |
protected void |
insertDrawingType(BSTTree node)
Insert the comaparable node to the tree using its natural ordering . |
protected void |
insertTreeType(BSTTree node)
Insert the comaparable node to the tree using its natural ordering . |
boolean |
isJumpStep()
Gets the JumpStep of the current tree. |
boolean |
isStepPause()
Gets the StepPause of the current tree. |
boolean |
isTreeAnimating()
Returns true if the current AnimatingBSTTreeHead is animating (whether the animating list is empty. |
boolean |
isTreeEmpty()
Returns true if the |
boolean |
isTreeRemove()
Gets whether the AnimatingBSTTreeHead is removing an Animation . |
Animation |
makeBalanceAnimation(BSTTree node)
Makes a balance Animation using the given node. |
Animation |
makeChangeDisplayAnimation()
Makes a changeDisplay Animation. |
Animation |
makeDeletionAnimation(BSTTree node)
Makes a deletion Animation using the given node. |
Animation |
makeInsertAnimation(BSTTree insertNode)
Makes an insert Animation using the given node. |
protected BSTTree |
makeNode(java.lang.Comparable keyInsert,
java.lang.Object valueInsert)
Makes and places the node into the tree. |
protected BSTTree |
makeNodeDrawingType(java.lang.Comparable keyInsert,
java.lang.Object valueInsert)
Makes and places the node into the tree. |
protected BSTTree |
makeNodeTreeType(java.lang.Comparable keyInsert,
java.lang.Object valueInsert)
Makes and places the node into the tree. |
Animation |
makePartitionAnimation(BSTTree node,
int keySelect)
Makes a partition Animation using the given node and given keySelect. |
Animation |
makeRotationAnimation(BSTTree node)
Makes a rotation Animation using the given node. |
Animation |
makeRotationDoubleAnimation(BSTTree node)
Makes a rotationDouble Animation using the given node. |
Animation |
makeSearchAnimation(java.lang.Comparable keySearch)
Makes a search Animation using the given keySearch. |
Animation |
makeSelectionAnimation(BSTTree node,
int keySelect)
Makes a select Animation using the given keySelect. |
Animation |
makeTraverseAnimation(java.util.LinkedList nodeList)
Makes a traverse Animation using the given LinkedList. |
void |
MakeTree(java.awt.Graphics2D g2)
Makes the entire tree from the null head down. |
protected void |
messageAction(java.lang.String msg)
Calls all of the listeners of the Tree and passes the tree message information information regarding the status of the Tree. |
protected void |
messageAction(java.lang.String msg,
java.lang.Object msgObj)
Calls all of the listeners of the Tree and passes the tree message information information regarding the status of the Tree. |
Tree |
partition(Tree node,
int keySelect)
Partitions from the given node the keySelect value. |
protected Tree |
partitionAnimatingType(BSTTree node,
int keySelect)
Partitions from the given node the keySelect value. |
protected BSTTree |
partitionTreeType(BSTTree node,
int keySelect)
Partitions from the given node the keySelect value. |
void |
pause()
Sets the status of the AnimatingBSTTree to pause. |
void |
play()
Sets the status of the AnimatingBSTTree to play. |
boolean |
remove(java.lang.Comparable keyRemove)
Removes the comaparable object keyRemove from the BSTTree using its natural ordering . |
void |
remove(Tree node)
Removes the given node from the tree. |
protected void |
removeAnimatingType(BSTTree node)
Removes the node in the BSTTree. |
void |
removeTreeAnimation()
Quickly removes all Animations within the Tree. |
void |
removeTreeMessageListener(TreeMessageListener l)
Removes an TreeMessageListener from the TREE, according to the TreeMessageListener interface and the TreeMessageEvent . |
void |
removeTreeType(BSTTree node)
Removes the given node from the tree. |
void |
resetTreeLevel()
Resets the lowest level of the Tree . |
void |
rewind()
Sets the status of the AnimatingBSTTree to rewind. |
void |
rotateToTop(BSTTree node)
Rotates the BSTTTree to the top. |
protected void |
rotateToTopAnimatingType(BSTTree node)
Rotates to top the node in the BSTTree. |
protected void |
rotateToTopTreeType(BSTTree node)
Rotates to top the node up in the BSTTree. |
void |
rotateUp(BSTTree node)
Rotates the BSTTree up. |
void |
rotateUp(BSTTree node,
int levelCount)
Rotates the BSTTree up. |
protected void |
rotateUpAnimatingType(BSTTree node)
Rotates the node up in the BSTTree. |
void |
rotateUpDouble(BSTTree node)
Double Rotatation of the BSTTTree . |
void |
rotateUpDouble(BSTTree node,
int levelCount)
Doubly Rotates the BSTTree up to the top. |
protected void |
rotateUpDoubleAnimatingType(BSTTree node)
Double Rotates the node up in the BSTTree. |
void |
rotateUpDoubleTreeType(BSTTree node)
Double Rotates the BSTTree up. |
void |
rotateUpTreeType(BSTTree node)
Rotates the BSTTree up. |
Tree |
search(java.lang.Comparable keySearch)
Searches for the comaparable object in the Tree using its natural ordering . |
protected Tree |
searchAnimatingType(java.lang.Comparable keySearch)
Searches for the Tree in the entire tree. |
Tree |
searchTreeType(java.lang.Comparable keySearch)
Searches for the Tree in the entire tree. |
Tree |
select(Tree node,
int keySelect)
Selects the kth smallest item in the Tree using its natural ordering from the given node. |
protected Tree |
selectAnimatingType(BSTTree node,
int keySelect)
Selects for the Tree in the entire tree. |
Tree |
selectTreeType(BSTTree node,
int keySelect)
Selects for the Tree in the entire tree. |
protected void |
setBackgroundColor(java.awt.Color background)
Sets the background paint for the tree. |
void |
setChild(Tree child)
Sets the child of the TreeHead. |
void |
setDeleteLeftLinePaintSettings(PaintSettings p)
Sets the PaintSettings for the left line of Paint. |
void |
setDeleteRightLinePaintSettings(PaintSettings p)
Sets the PaintSettings for the right line of Paint. |
void |
setDisplay(int display)
Sets the display choice for the tree. |
void |
setDrawingKeySettings(KeySettings k)
Sets the KeySettings for the key of the head, used in creation of new nodes. |
void |
setDrawingNodeSettings(NodeSettings s)
Sets the NodeSettings for the node of the head, used in creation of new nodes. |
void |
setInsertAnimatorKeySettings(KeySettings k)
Sets the KeySettings for the animator key settings for insertion. |
void |
setInsertAnimatorNodeSettings(NodeSettings n)
Sets the NodeSettings for the animator node settings for insertion. |
void |
setInsertNodeLeftSettings(NodeSettings n)
Sets the NodeSettings for the left node settings for insertion. |
void |
setInsertNodeRightSettings(NodeSettings n)
Sets the NodeSettings for the right node settings for insertion. |
void |
setJumpStep(boolean b)
Sets the JumpStep of the current tree to the boolean value. |
protected void |
setNodeHeight(double height)
Sets the node height for the standard node. |
protected void |
setNodeWidth(double width)
Sets the node width for the standard node. |
void |
setPreviousDisplay(int previousDisplay)
Sets the previous display choice for the tree. |
protected void |
setRemove(boolean b)
Sets whether the AnimatingBSTTreeHead is removing an Animation , because
multiple Animations may occur simultaneously. |
void |
setRotateAnimatorKeySettings(KeySettings k)
Sets the KeySettings for the animator key settings for rotation. |
void |
setRotateChildNodeSettings(NodeSettings n)
Sets the NodeSettings for the child node settings for rotation. |
void |
setRotateDescendantNodeSettings(NodeSettings n)
Sets the NodeSettings for the descendant node settings for rotation. |
void |
setRotateOriginalKeySettings(KeySettings k)
Sets the KeySettings for the original key settings for rotation. |
void |
setRotateOriginalNodeSettings(NodeSettings n)
Sets the NodeSettings for the original node settings for rotation. |
void |
setRotateRootNodeSettings(NodeSettings n)
Sets the NodeSettings for the root node settings for rotation. |
void |
setScreenBounds(java.awt.geom.Rectangle2D screen)
Sets the bounds of the screen to which the tree is drawing. |
void |
setSearchAnimatorKeySettings(KeySettings k)
Sets the KeySettings for the animator key settings for searching. |
void |
setSearchAnimatorNodeSettings(NodeSettings n)
Sets the NodeSettings for the animator node settings for searching. |
void |
setSearchNodeLeftSettings(NodeSettings n)
Sets the NodeSettings for the left node settings for searching. |
void |
setSearchNodeRightSettings(NodeSettings n)
Sets the NodeSettings for the right node settings for searching. |
protected void |
setSectionHeight(double height)
Sets the height of the section, used for rendering the tree. |
void |
setSelectAnimatorKeySettings(KeySettings k)
Sets the KeySettings for the animator key settings for selection. |
void |
setSelectAnimatorNodeSettings(NodeSettings n)
Sets the NodeSettings for the animator node settings for selection. |
void |
setSelectNodeLeftSettings(NodeSettings n)
Sets the NodeSettings for the left node settings for selection. |
void |
setSelectNodeRightSettings(NodeSettings n)
Sets the NodeSettings for the right node settings for selection. |
void |
setStepPause(boolean b)
Sets the StepPause of the current tree to the boolean value. |
void |
setTraverseAnimatorKeySettings(KeySettings k)
Sets the KeySettings for the animator key settings for traversal. |
void |
setTraverseAnimatorNodeSettings(NodeSettings n)
Sets the NodeSettings for the animator node settings for traversal. |
void |
setTreeAnimationsStepSize(int t)
Sets the step size of the Animation s of the tree. |
protected void |
setTreeLevel(int level)
Sets the lowest level of the Tree , used in numerous methods. |
void |
setTreeSettings(NodeSettings s,
KeySettings k)
Sets the NodeSettings for the entire tree from the head down. |
void |
setTreeStatus(java.lang.String s)
Sets the Status of the entire tree, using the status of Animation class. |
void |
setTreeType(int treeType)
Sets the tree type for the BSTTree. |
int |
size()
Returns the number of objects in the entire tree. |
void |
splay(BSTTree node)
Splays the BSTTTree to the top (Double rotates). |
protected void |
splayAnimatingType(BSTTree node)
Splays the node up in the BSTTree. |
protected void |
splayTreeType(BSTTree node)
Splays the node up in the BSTTree. |
void |
stop()
Sets the status of the AnimatingBSTTree to stop. |
java.util.LinkedList |
traverse(int traverseType)
Traverses the tree in the given traversal type. |
java.util.LinkedList |
traverseAnimatingType(int traverseType)
Traverses the tree in the given traversal type. |
java.util.LinkedList |
traverseTreeType(int traverseType)
Traverses the tree in the given traversal type. |
void |
waitingAction(java.lang.String action,
java.lang.Object element)
Acts according to the String action passed. |
double |
worstCaseInsertion(int n)
Returns the worst case Insertion time, according to n, the amount of elements in the tree. |
double |
worstCaseSearchHit(int n)
Returns the worst case Search hit time, according to n, the amount of elements in the tree. |
double |
worstCaseSearchMiss(int n)
Returns the worst case Search miss time, according to n, the amount of elements in the tree. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface Tree |
getChildren, getKey, getLevel, getParentTree, getValue, isEmpty |
Field Detail |
public static final java.lang.String TREE_INFORMATION
public static final int BINARY_DISPLAY
public static final int SECTIONAL_DISPLAY
Constructor Detail |
public BSTTreeHead()
Default type is BST_TREE_TYPE.
public BSTTreeHead(int treeType)
treeType
- type of tree that should be implemented.Method Detail |
public void setTreeType(int treeType)
setTreeType
in class BSTTree
treeType
- setting for the tree.protected void messageAction(java.lang.String msg)
msg
- String message being passed to all TreeMessage listeners.protected void messageAction(java.lang.String msg, java.lang.Object msgObj)
msg
- String message being passed to all TreeMessage listeners.msgObj
- Object related to the message and usable by all listeners.public void addTreeMessageListener(TreeMessageListener l)
TreeMessageEvent
.
addTreeMessageListener
in interface TreeHead
l
- the listener added recieves the TreeMessageEvents occuring.public void removeTreeMessageListener(TreeMessageListener l)
TreeMessageEvent
.
removeTreeMessageListener
in interface TreeHead
l
- the listener removed from recieving the TreeMessageEvents occuring.public java.lang.String getTreeStatusMessage()
messageAction
with the information
necessary for the tree status. The information presented include :
getTreeStatusMessage
in interface AnimatingTreeHead
public double averageSearchHit(int n)
n
- the size of the tree for which the average search hit is needed.
public double averageSearchMiss(int n)
n
- the size of the tree for which the average search hit is needed.
public double worstCaseSearchHit(int n)
n
- the size of the tree for which the worst case search hit is needed.
public double worstCaseSearchMiss(int n)
n
- the size of the tree for which the worst case search hit is needed.
public double averageInsertion(int n)
n
- the size of the tree for which the average search hit is needed.
public double worstCaseInsertion(int n)
n
- the size of the tree for which the worst case search hit is needed.
public void waitingAction(java.lang.String action, java.lang.Object element)
WaitingActionList
which keeps the list of actions, and calls the method when
instructed to call the next action.
waitingAction
in interface TreeHead
action
- String action representing the next action for the BSTTreeHead.element
- element to which the action could be occuring, depending on the type of action.protected WaitingActionList getWaitingList()
WaitingActionList
representing the waitingList for the tree. This allows
extension of the class have tthe ability to modify the attributes of the list.
WaitingActionList
waiting list for the tree.public void constructBSTTreeHead()
public boolean isTreeEmpty()
isTreeEmpty
in interface TreeHead
TreeHead
is empty.public Tree getChild()
getChild
in interface TreeHead
public int getTreeLevel()
getTreeLevel
in interface TreeHead
Tree
.public int size()
size
in interface TreeHead
size
in class BSTTree
public void setChild(Tree child)
setChild
in interface TreeHead
child
- Tree
, beginning the Tree
nodes.protected void setTreeLevel(int level)
Tree
, used in numerous methods. The level must remain very accurate. A level of 0 indicates an empty Tree.
level
- integer level set for the BSTTree
.public void resetTreeLevel()
Tree
. The level is set to 0, so that is can be recalculated, using fixLevel.
resetTreeLevel
in interface TreeHead
public void fixLevel()
Tree
, using recursive calls into the BSTTree. Generally, resetTreeLevel
is called before the method.
fixLevel
in interface TreeHead
public int fixSize()
fixSize
in class BSTTree
protected BSTTree makeNode(java.lang.Comparable keyInsert, java.lang.Object valueInsert) throws java.lang.ClassCastException
keyInsert
- comparable object which is added to the tree.valueInsert
- Object that accompanies keyInsert in the node.
java.lang.ClassCastException
- key cannot be compared with the keys
currently in the map.public void clear()
clear
in interface TreeHead
public boolean insert(java.lang.Comparable keyInsert, java.lang.Object valueInsert) throws java.lang.NullPointerException, java.lang.ClassCastException
insert
in interface TreeHead
keyInsert
- comparable object which is added to the tree.valueInsert
- Object that accompanies keyInsert in the node.
java.lang.ClassCastException
- key cannot be compared with the keys
currently in the map.
java.lang.NullPointerException
- key is null.public void insert(Tree node) throws java.lang.ClassCastException
node
- BSTTree which is added to the tree.
java.lang.ClassCastException
- key cannot be compared with the keys
currently in the map.public void remove(Tree node)
remove
in interface TreeHead
node
- the Tree
node to be removed from the tree.public boolean remove(java.lang.Comparable keyRemove) throws java.lang.ClassCastException, java.lang.NullPointerException
BSTTree
using its natural ordering .
If the method is successful in removing the element, true is returned.
remove
in interface TreeHead
keyRemove
- comparable object which is removed from the tree.
java.lang.ClassCastException
- key cannot be compared with the keys
currently in the map.
java.lang.NullPointerException
- key is null.public void balanceTree()
balanceTree
in interface TreeHead
public void balance(Tree node)
balance
in interface TreeHead
node
- the node from which the balance occurspublic Tree partition(Tree node, int keySelect)
partition
in interface TreeHead
keySelect
- integer key selecting the count item.node
- Tree which the partition occurs at.
public Tree search(java.lang.Comparable keySearch) throws java.lang.ClassCastException, java.lang.NullPointerException
Tree
using its natural ordering .
If the method is successful in finding the element, the item is returned. Otherwise, the closest item is
returned.
search
in interface TreeHead
search
in class BSTTree
keySearch
- comparable object which is search for within the tree.
java.lang.ClassCastException
- key cannot be compared with the keys
currently in the map.
java.lang.NullPointerException
- key is null.public Tree select(Tree node, int keySelect)
Tree
using its natural ordering from the given node.
If the method is successful in finding the element, the item is returned. Otherwise, null is
returned if the integer is greater than the size.
select
in interface TreeHead
keySelect
- integer key selecting the count item.node
- Tree which the partition occurs at.
public void rotateUp(BSTTree node)
BSTTree
up. It simply changes around references, including the
parent reference and the ancestor reference. The rotation upwards replaces the parent with
the node and brings the parent down a level.
node
- BSTTree that rotated upwards.public void rotateUp(BSTTree node, int levelCount)
BSTTree
up. It simply changes around references, including the
parent reference and the ancestor reference. The rotation upwards replaces the parent with
the node and brings the parent down a level.
node
- BSTTree that rotated upwards.levelCount
- the amount of levels up the node should rotatepublic void rotateUpDouble(BSTTree node)
BSTTTree
.
node
- BSTTree that is double rotated (bottom rotation first).public void rotateUpDouble(BSTTree node, int levelCount)
BSTTree
up to the top. This is also referred to as a Splay
and is the basis for a splay tree if the double rotation occurs to the top.
node
- BSTTree that rotated upwards.levelCount
- the amount of levels up the node should rotatepublic void rotateToTop(BSTTree node)
BSTTTree
to the top.
node
- BSTTree that is rotated to the top.public void splay(BSTTree node)
BSTTTree
to the top (Double rotates).
node
- BSTTree that is rotated to the top.public void changeDisplay()
public java.util.LinkedList traverse(int traverseType)
traverseType
- int defining the given traversal type.protected BSTTree makeNodeTreeType(java.lang.Comparable keyInsert, java.lang.Object valueInsert)
keyInsert
- comparable object which is added to the tree.valueInsert
- Object that accompanies keyInsert in the node.
java.lang.ClassCastException
- key cannot be compared with the keys
currently in the map.protected void insertTreeType(BSTTree node) throws java.lang.ClassCastException
node
- BSTTree node to be inserted into the tree
java.lang.ClassCastException
- key cannot be compared with the keys
currently in the map.public void removeTreeType(BSTTree node)
node
- the Tree
node to be removed from the tree.protected BSTTree partitionTreeType(BSTTree node, int keySelect)
keySelect
- integer key selecting the count item.
public void balanceTreeType(BSTTree node)
node
- BSTTree that is balanced from.public Tree searchTreeType(java.lang.Comparable keySearch) throws java.lang.ClassCastException
Tree
in the entire tree.
keySearch
- the comparable key which is searched for within the tree.
Tree
found or null if keySearch was not present within the tree.
java.lang.ClassCastException
- key cannot be compared with the keys
currently in the map.public Tree selectTreeType(BSTTree node, int keySelect) throws java.lang.ClassCastException
Tree
in the entire tree.
node
- the node from which the selection takes place.keySelect
- integer key selecting the count item.
Tree
found or null.
java.lang.ClassCastException
- key cannot be compared with the keys
currently in the map.public void rotateUpTreeType(BSTTree node)
BSTTree
up. It simply changes around references, including the
parent reference and the ancestor reference. The rotation upwards replaces the parent with
the node and brings the parent down a level.
node
- BSTTree that rotated upwards.public void rotateUpDoubleTreeType(BSTTree node)
BSTTree
up.
node
- BSTTree that rotated upwards.protected void splayTreeType(BSTTree node)
node
- BSTTree node that is splayed.protected void rotateToTopTreeType(BSTTree node)
node
- BSTTree node that is rotated up.public java.util.LinkedList traverseTreeType(int traverseType)
traverseType
- int defining the given traversal type.public void changeDisplayTreeType()
BSTTree
.
public java.util.LinkedList getPreorderTree()
BSTTree
s.
Changes in the references in the array have no effect upon the tree.
BSTTree
objects that are the preorder representation of the tree.public java.util.LinkedList getInorderTree()
BSTTree
s.
Changes in the references in the array have no effect upon the tree.
BSTTree
objects that are the preorder representation of the tree.public java.util.LinkedList getPostorderTree()
BSTTree
s.
Changes in the references in the array have no effect upon the tree.
BSTTree
objects that are the preorder representation of the tree.public java.util.LinkedList getLevelorderTree()
BSTTree
s.
Changes in the references in the array have no effect upon the tree.
BSTTree
objects that are the preorder representation of the tree.public void constructDrawingBSTTreeHead()
public int getDisplay()
public int getPreviousDisplay()
public NodeSettings getDrawingNodeSettings()
NodeSettings
for the entire tree.
getDrawingNodeSettings
in interface DrawingTreeHead
NodeSettings
for defined for the entire tree.public KeySettings getDrawingKeySettings()
KeySettings
for the entire tree.
getDrawingKeySettings
in interface DrawingTreeHead
KeySettings
for defined for the entire tree.public double getNodeWidth()
getNodeWidth
in interface DrawingTreeHead
public double getNodeHeight()
getNodeHeight
in interface DrawingTreeHead
public java.awt.geom.Rectangle2D getScreenBounds()
getScreenBounds
in interface DrawingTreeHead
getScreenBounds
in class BSTTree
protected double getTreeSectionHeight()
protected java.awt.Color getBackgroundColor()
public NodeSettings getInsertNodeLeftSettings()
public NodeSettings getInsertNodeRightSettings()
public NodeSettings getInsertAnimatorNodeSettings()
public KeySettings getInsertAnimatorKeySettings()
public NodeSettings getSearchNodeLeftSettings()
public NodeSettings getSearchNodeRightSettings()
public NodeSettings getSearchAnimatorNodeSettings()
public KeySettings getSearchAnimatorKeySettings()
public NodeSettings getSelectNodeLeftSettings()
public NodeSettings getSelectNodeRightSettings()
public NodeSettings getSelectAnimatorNodeSettings()
public KeySettings getSelectAnimatorKeySettings()
public NodeSettings getRotateRootNodeSettings()
public NodeSettings getRotateChildNodeSettings()
public NodeSettings getRotateDescendantNodeSettings()
public NodeSettings getRotateOriginalNodeSettings()
public KeySettings getRotateAnimatorKeySettings()
public KeySettings getRotateOriginalKeySettings()
public PaintSettings getDeleteLeftLinePaintSettings()
public PaintSettings getDeleteRightLinePaintSettings()
public NodeSettings getTraverseAnimatorNodeSettings()
public KeySettings getTraverseAnimatorKeySettings()
public void setDisplay(int display)
display
- sets the integer that defines the display choice of the tree.public void setPreviousDisplay(int previousDisplay)
public void setTreeSettings(NodeSettings s, KeySettings k)
NodeSettings
for the entire tree from the head down.
These settings are used for drawing the node and the links of each given tree.
setTreeSettings
in interface DrawingTreeHead
setTreeSettings
in class BSTTree
s
- NodeSettings
for use in drawing the entire tree.k
- KeySettings
for use in drawing the keys of the entire tree.public void setDrawingNodeSettings(NodeSettings s)
NodeSettings
for the node of the head, used in creation of new nodes.
s
- NodeSettings
for use in drawing the nodes.public void setDrawingKeySettings(KeySettings k)
KeySettings
for the key of the head, used in creation of new nodes.
k
- KeySettings
for use in drawing the keys.protected void setNodeWidth(double width)
MakeTree
.
width
- the width of the node.protected void setNodeHeight(double height)
MakeTree
.
height
- the height of the node.public void setScreenBounds(java.awt.geom.Rectangle2D screen)
getClipBounds
on the Graphics2D passed, however, the bounds
can be set in any way.
setScreenBounds
in interface DrawingTreeHead
setScreenBounds
in class BSTTree
protected void setSectionHeight(double height)
height
- of the section, used for drawing the tree.protected void setBackgroundColor(java.awt.Color background)
background
- paint of the background.public void setInsertNodeLeftSettings(NodeSettings n)
public void setInsertNodeRightSettings(NodeSettings n)
public void setInsertAnimatorNodeSettings(NodeSettings n)
public void setInsertAnimatorKeySettings(KeySettings k)
public void setSearchNodeLeftSettings(NodeSettings n)
public void setSearchNodeRightSettings(NodeSettings n)
public void setSearchAnimatorNodeSettings(NodeSettings n)
public void setSearchAnimatorKeySettings(KeySettings k)
public void setSelectNodeLeftSettings(NodeSettings n)
public void setSelectNodeRightSettings(NodeSettings n)
public void setSelectAnimatorNodeSettings(NodeSettings n)
public void setSelectAnimatorKeySettings(KeySettings k)
public void setRotateRootNodeSettings(NodeSettings n)
public void setRotateChildNodeSettings(NodeSettings n)
public void setRotateDescendantNodeSettings(NodeSettings n)
public void setRotateOriginalNodeSettings(NodeSettings n)
public void setRotateAnimatorKeySettings(KeySettings k)
public void setRotateOriginalKeySettings(KeySettings k)
public void setDeleteLeftLinePaintSettings(PaintSettings p)
public void setDeleteRightLinePaintSettings(PaintSettings p)
public void setTraverseAnimatorNodeSettings(NodeSettings n)
public void setTraverseAnimatorKeySettings(KeySettings k)
protected BSTTree makeNodeDrawingType(java.lang.Comparable keyInsert, java.lang.Object valueInsert)
keyInsert
- comparable object which is added to the tree.valueInsert
- Object that accompanies keyInsert in the node.
java.lang.ClassCastException
- key cannot be compared with the keys
currently in the map.protected void insertDrawingType(BSTTree node) throws java.lang.ClassCastException
Call to insertTreeType
node
- BSTTree node to be inserted into the tree
java.lang.ClassCastException
- key cannot be compared with the keys
currently in the map.public void MakeTree(java.awt.Graphics2D g2)
MakeTree
in interface DrawingTreeHead
g2
- Graphics2D which the tree is made to fit unto.public void DrawTree(java.awt.Graphics2D g2)
MakeTree
.
DrawTree
in interface DrawingTreeHead
g2
- Graphics2D which the tree is drawn onto.public DrawingTree findNode(double x, double y)
findNode
in interface DrawingTreeHead
findNode
in class BSTTree
x
- x-coordinate to find the node.y
- y-coordinate to find the node.
public void constructAnimatingBSTTreeHead()
public boolean isTreeRemove()
Animation
.
Animation
.public Animation getTreeAnimator()
Animation
in the list of Animations for the Head and null if no
Animations are present.
getTreeAnimator
in interface AnimatingTreeHead
Animation
in the Animation list.public boolean isTreeAnimating()
isTreeAnimating
in interface AnimatingTreeHead
public boolean isJumpStep()
isJumpStep
in interface AnimatingTreeHead
public boolean isStepPause()
isStepPause
in interface AnimatingTreeHead
public int getTreeAnimationStepSize()
Animation
s of the tree.
getTreeAnimationStepSize
in interface AnimatingTreeHead
public java.lang.String getTreeStatus()
Animation
.
getTreeStatus
in interface AnimatingTreeHead
Animation
status.protected void setRemove(boolean b)
Animation
, because
multiple Animations may occur simultaneously.
b
- boolean value as to whether the tree is removing an Animation
.public void clearAnimators()
Animation
s from the list of Animations for the Head.
public void addTreeAnimator(Animation a)
Animation
to the list of Animations for the Head. The method does
not add the tree as a listener to the Animation
. That must be accomplished by
the client.
addTreeAnimator
in interface AnimatingTreeHead
a
- Animation
added to the Animation list.public void removeTreeAnimation()
Animation.FINISH
so that al listeners of the Animations will
receive the AnimationEvent.
removeTreeAnimation
in interface AnimatingTreeHead
public void setJumpStep(boolean b)
AnimateTree
call.
setJumpStep
in interface AnimatingTreeHead
b
- sets the jumpStep to the value b.public void setStepPause(boolean b)
setStepPause
in interface AnimatingTreeHead
b
- sets the stepPause to the value b.public void setTreeAnimationsStepSize(int t)
Animation
s of the tree. The integer value
is passed to every Animation's setStepTime
method.
setTreeAnimationsStepSize
in interface AnimatingTreeHead
t
- integer step size setting.public void setTreeStatus(java.lang.String s)
Animation
class.
setTreeStatus
in interface AnimatingTreeHead
s
- String status to set the Tree's Status.protected void insertAnimatingType(BSTTree node) throws java.lang.ClassCastException
Call to insertDrawingType
node
- BSTTree node to be inserted into the tree
java.lang.ClassCastException
- key cannot be compared with the keys
currently in the map.protected Tree searchAnimatingType(java.lang.Comparable keySearch) throws java.lang.ClassCastException
Tree
in the entire tree.
Call to searchTreeType
keySearch
- the comparable key which is searched for within the tree.
Tree
found or null if keySearch was not present within the tree.
java.lang.ClassCastException
protected Tree selectAnimatingType(BSTTree node, int keySelect) throws java.lang.ClassCastException
Tree
in the entire tree.
Call to selectTreeType
keySelect
- integer key selecting the count item.
Tree
found or null.
java.lang.ClassCastException
protected void rotateUpAnimatingType(BSTTree node)
node
- BSTTree node that is rotated up.protected void rotateUpDoubleAnimatingType(BSTTree node)
node
- BSTTree node that is rotated up twice.protected void splayAnimatingType(BSTTree node)
node
- BSTTree node that is splayed.protected void rotateToTopAnimatingType(BSTTree node)
node
- BSTTree node that is splayed.protected void removeAnimatingType(BSTTree node)
DeleteBSTAnimation
is built, using the node, the super remove
method is called.
node
- BSTTree node that is deleted.protected Tree partitionAnimatingType(BSTTree node, int keySelect)
Call to selectTreeType
keySelect
- integer key selecting the count item.
selectTreeType
).public void balanceAnimatingType(BSTTree node)
balanceTREE
if no waiting action appears.
node
- BSTTree that is balanced from.public java.util.LinkedList traverseAnimatingType(int traverseType)
traverseType
- int defining the given traversal type.public void changeDisplayAnimatingType()
BSTTree
.
public Animation makeInsertAnimation(BSTTree insertNode)
insertNode
- BSTTree node that the insert Animation is built for.
public Animation makeSearchAnimation(java.lang.Comparable keySearch)
keySearch
- the comparable object which is search for within the tree.public Animation makeSelectionAnimation(BSTTree node, int keySelect)
keySelect
- the int which is selected for within the tree.public Animation makeRotationAnimation(BSTTree node)
node
- BSTTree node that the rotation Animation is built from.
public Animation makeDeletionAnimation(BSTTree node)
node
- BSTTree node that the deletion Animation is built from.
public Animation makePartitionAnimation(BSTTree node, int keySelect)
node
- BSTTree node that the deletion Animation is built from.keySelect
- finds the keySelectth node and rotates it to the top.
public Animation makeBalanceAnimation(BSTTree node)
node
- BSTTree node that the balance Animation is built from.
public Animation makeRotationDoubleAnimation(BSTTree node)
node
- BSTTree node that the doubleRotation Animation is built from.
public Animation makeTraverseAnimation(java.util.LinkedList nodeList)
nodeList
- the LinkedList containing the nodes that are the path of the traversal.public Animation makeChangeDisplayAnimation()
public void AnimateTree(java.awt.Graphics2D g2)
drawAnimation
method is called. Within this method, checks for removing a Animation are made, as are checks
for Waiting Actions.
AnimateTree
in interface AnimatingTreeHead
g2
- Graphics2D to which the Animation
s are drawn.public void play()
AnimatingBSTTree
to play.
play
in interface AnimatingTreeHead
public void stop()
AnimatingBSTTree
to stop.
stop
in interface AnimatingTreeHead
public void rewind()
AnimatingBSTTree
to rewind.
rewind
in interface AnimatingTreeHead
public void pause()
AnimatingBSTTree
to pause.
pause
in interface AnimatingTreeHead
public void animationEventPerformed(AnimationEvent e)
AnimationListener
which requires the following method.
The only status of animation it listens for is Animation.FINISH
, to remove
the animation from the animators list and Animation.STEP
, to possible pause
the animation if stepPause is true.
animationEventPerformed
in interface AnimationListener
animationEventPerformed
in class BSTTree
e
- AnimationEvent that represents the information of the Animation.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |