|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.princeton.cs.algs4.growingtree.framework.GrowingTreeNode<P>
public class GrowingTreeNode<P extends NodeProperties>
The class provides the base structure of a BSTTree
, a node of the Binary Search Tree.
It uses the elements natural ordering. It uses everything defined within the AbstractTree
The BSTTree cannot be the head of the tree, it is only the nodes. It defines recursive methods which aren't defined in the head node and it does not define the methods for the head node.
A Binary Search Tree is a binary tree that has a key associated with each of its internal nodes, with the additional property that the key in any node is larger than (or eqaul to) that keys in all nodes in that node's left subtree and smaller than (or equal to) the keys in all nodes in the node's right subtree. (Sedgewick, 502, Algorithms in C)
Note that this implementation is not synchronized. If multiple threads access this tree concurrently, and at least one of the threads modifies the tree structurally, it must be synchronized externally.
Field Summary | |
---|---|
static int |
ANIMATING_BST_TREE_TYPE
Tree type defining AnimatingBSTTree. |
static int |
BST_TREE_TYPE
Tree type defining only a BSTTree. |
static int |
DRAWING_BST_TREE_TYPE
Tree type defining a DrawingBSTTree. |
Constructor Summary | |
---|---|
GrowingTreeNode()
Constructs a new, empty BSTTree, sorted according to the keys' natural order. |
|
GrowingTreeNode(int treeType)
Constructs a new, empty BSTTree according to the type passed. |
|
GrowingTreeNode(int treeType,
P p,
IExperimentLogger<P> logger)
|
Method Summary | |
---|---|
void |
addAnimator(Animation a)
Adds an animation to the current node. |
void |
animationEventPerformed(AnimationEvent e)
Implements AnimationListener which requires the following method. |
int |
compareTo(GrowingTreeNode<P> that)
|
void |
constructAnimatingBSTTree()
Constructor for the ANIMATING_BST_TREE_TYPE. |
void |
constructBSTTree()
Constructor for the BST_TREE_TYPE. |
void |
constructDrawingBSTTree()
Constructor for the DRAWING_BST_TREE_TYPE. |
GrowingTreeNode<P> |
delete()
|
void |
drawNode()
Draws the node of the tree using the previously defined graphics. |
void |
drawNode(java.awt.Graphics2D g2)
Draws the node of the tree to the given Graphics2D. |
void |
drawNode(java.awt.Graphics2D g2,
java.awt.geom.AffineTransform a)
Draws the node of the tree to the given Graphics2D, using the AffineTransform . |
void |
drawNodeAndLeftLink()
Draws the node and left link of the tree using the previously defined graphics. |
void |
drawNodeAndLink()
Draws the node and link of the tree using the previously defined graphics.. |
void |
drawNodeAndLink(java.awt.Graphics2D g2)
Draws the node and link of the tree to the given Graphics2D. |
void |
drawNodeAndLink(java.awt.Graphics2D g2,
java.awt.geom.AffineTransform a)
Draws the node and link of the tree to the given Graphics2D. |
void |
drawNodeAndLink(java.awt.Graphics2D g2,
java.awt.geom.AffineTransform a,
boolean bottomLinks)
Draws the node and link of the tree to the given Graphics2D. |
void |
drawNodeAndLink(java.awt.Graphics2D g2,
boolean bottomLinks)
Draws the node and link of the tree to the given Graphics2D. |
void |
drawNodeAndLink(java.awt.Graphics2D g2,
double sectionHeight,
java.awt.geom.AffineTransform a,
double drawingLevel,
double powerLevel)
Draws the node and link of the tree to the given Graphics2D. |
void |
drawNodeAndLink(java.awt.Graphics2D g2,
double sectionHeight,
java.awt.geom.AffineTransform a,
double drawingLevel,
double powerLevel,
boolean bottomLinks)
Draws the node and link of the tree to the given Graphics2D. |
void |
drawNodeAndRightLink()
Draws the node and right link of the tree using the previously defined graphics. |
void |
eraseNodeAndLink()
Erases the previous drawing of the nodeAndLinkm, simply drawing. |
void |
eraseNodeAndLink(java.awt.Graphics2D g2)
Erases the previous drawing of the nodeAndLinkm, simply drawing. |
Animation |
getAnimator()
Gets the first Animation of the node. |
Tree[] |
getChildren()
Returns the children of the current Tree . |
java.awt.Graphics2D |
getCurrentGraphics()
Gets the graphics previously defined within the tree. |
double |
getCurrentPower2()
Gets the current power of 2 to which the tree was last drawn. |
java.awt.geom.AffineTransform |
getCurrentTransform()
Gets the AffineTransform defined within the tree. |
double |
getDrawingLevel()
Gets the drawing level for the current DrawingTree . |
GrowingTreeHead<P> |
getHead()
Gets the head for the node. |
int |
getInorderCount()
Returns the inorder count of the current node. |
KeyType |
getKey()
Returns the key of the current BSTTree . |
java.awt.Color |
getLeftLinkColor()
|
GrowingTreeNode<P> |
getLeftNodeInternal()
Returns the left BSTTree of the current tree. |
int |
getLevel()
Gets the the level of the current BSTTree . |
int |
getMaxKeyWidth()
|
P |
getNodeProperties()
|
GrowingTreeNode<P> |
getParentTree()
Returns the parent of the current tree. |
java.awt.Color |
getRightLinkColor()
|
GrowingTreeNode<P> |
getRightNodeInternal()
Returns the right BSTTree of the current tree. |
GrowingTreeNode<P> |
getRoot()
|
java.awt.geom.Rectangle2D |
getScreenBounds()
Gets the bounds of the screen to which the tree is drawing. |
double |
getSectionHeight()
Gets the height of the section for the DrawingTree . |
NodeSettings |
getSettings()
Gets the NodeSettings of the tree. |
ShadowNode<P> |
getShadowNode()
BST_TREE_TYPE Accesssor methods* |
int |
getTreeType()
Gets the tree type for the BSTTree. |
java.lang.String |
getTreeTypeString()
Gets the tree type String for the BSTTree. |
java.lang.Object |
getValue()
Returns the value of the current BSTTree . |
IAlgorithmNode<P> |
insertNode(GrowingTreeNode<P> node)
|
boolean |
inTree()
Determines if the current node is within a BSTTree. |
boolean |
isAnimateDrawing()
Gets the boolean flag whether the node should draw if called from an animation. |
boolean |
isEmpty()
Returns true if the current BSTTree is empty. |
boolean |
isLeaf()
Determines if the current node is a leaf |
boolean |
isNodeAnimating()
Returns true if the node is animating. |
boolean |
isSettingsSaved()
Returns true if the settings are currently saved for the DrawingTree. |
void |
restoreLeftSettings()
Restores the settings for the tree, decrementing the count of left Saves and total saves by one. |
void |
restoreRightSettings()
Restores the settings for the tree, decrementing the count of right Saves and total saves by one. |
void |
restoreSettings()
Restores the settings for the tree, decrementing the count of saves by one. |
void |
restoreTransform()
Restores the AffineTransform defined previously within the tree. |
GrowingTreeNode<P> |
rotateLeftPointers()
Rotate the tree to the left. |
GrowingTreeNode<P> |
rotateRightPointers()
Rotate the tree to the right. |
void |
rotateUp()
|
void |
saveLeftSettings()
Saves the settings for the tree, incrementing the count of left Saves and total saves by one and setting the previous settings accordingly. |
void |
saveRightSettings()
Saves the settings for the tree, incrementing the count of right Saves and total saves by one and setting the previous settings accordingly. |
void |
saveSettings()
Saves the settings for the tree, incrementing the count of saves by one and setting the previous settings accordingly. |
void |
setAnimateDrawing(boolean animateDrawing)
Sets the boolean flag whether the node should draw if called from an animation. |
void |
setCurrentGraphics(java.awt.Graphics2D g2)
Sets the graphics defined within the tree. |
void |
setNodeSettings(NodeSettings s)
Sets the settings of the node for the BSTTree . |
void |
setScreenBounds(java.awt.geom.Rectangle2D bounds)
Sets the bounds of the screen to which the tree is drawing. |
void |
setSettings(NodeSettings s)
Sets the NodeSettings of the DrawingTree . |
void |
setTreeType(int treeType)
Sets the tree type for the BSTTree. |
int |
size()
Returns the number of nodes in the current Tree and below. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int BST_TREE_TYPE
public static final int DRAWING_BST_TREE_TYPE
public static final int ANIMATING_BST_TREE_TYPE
Constructor Detail |
---|
public GrowingTreeNode()
Default type is BST_TREE_TYPE.
public GrowingTreeNode(int treeType)
treeType
- type of tree that should be implemented.public GrowingTreeNode(int treeType, P p, IExperimentLogger<P> logger)
Method Detail |
---|
public void setTreeType(int treeType)
treeType
- setting for the tree.public int getTreeType()
public java.lang.String getTreeTypeString()
public void constructBSTTree()
public ShadowNode<P> getShadowNode()
public P getNodeProperties()
public java.awt.Color getLeftLinkColor()
public java.awt.Color getRightLinkColor()
public GrowingTreeHead<P> getHead()
public int size()
size
in interface Tree<P extends NodeProperties>
public boolean isEmpty()
BSTTree
is empty.
isEmpty
in interface Tree<P extends NodeProperties>
BSTTree
is empty.public java.lang.Object getValue()
BSTTree
.
getValue
in interface Tree<P extends NodeProperties>
BSTTree
.public int compareTo(GrowingTreeNode<P> that)
public KeyType getKey()
BSTTree
.
getKey
in interface Tree<P extends NodeProperties>
BSTTree
.public int getLevel()
BSTTree
.
The level is the integer count of how far down the tree is to the current node.
getLevel
in interface Tree<P extends NodeProperties>
BSTTree
.public int getInorderCount()
public GrowingTreeNode<P> getLeftNodeInternal()
BSTTree
of the current tree. Used to traverse down
the binary tree.
BSTTree
that is the left subtree of the current BSTTree
,
null of no such tree exists.public GrowingTreeNode<P> getRightNodeInternal()
BSTTree
of the current tree. Used to traverse down
the binary tree.
BSTTree
that is the right subtree of the current BSTTree
,
null of no such tree exists.public Tree[] getChildren()
Tree
.
getChildren
in interface Tree<P extends NodeProperties>
Tree
array that is the children and null if the tree is an exterior node.public GrowingTreeNode<P> getParentTree()
getParentTree
in interface Tree<P extends NodeProperties>
public GrowingTreeNode<P> getRoot()
public boolean inTree()
public boolean isLeaf()
public IAlgorithmNode<P> insertNode(GrowingTreeNode<P> node)
public GrowingTreeNode<P> delete()
public GrowingTreeNode<P> rotateRightPointers()
public GrowingTreeNode<P> rotateLeftPointers()
public void rotateUp()
public int getMaxKeyWidth()
public void constructDrawingBSTTree()
public double getDrawingLevel()
DrawingTree
. This is a necessary method for allowing
intermidiary drawing between two levels, because the param is a double, not an integer.
getDrawingLevel
in interface DrawingTree<P extends NodeProperties>
public double getSectionHeight()
DrawingTree
. The section height is generally
used to determine link length and node height when drawing the tree.
getSectionHeight
in interface DrawingTree<P extends NodeProperties>
public java.awt.geom.Rectangle2D getScreenBounds()
getScreenBounds
in interface DrawingTree<P extends NodeProperties>
public double getCurrentPower2()
public NodeSettings getSettings()
NodeSettings
of the tree.
These settings are used for drawing the node and the links of the given tree.
getSettings
in interface DrawingTree<P extends NodeProperties>
NodeSettings
for use in drawing the tree.public boolean isSettingsSaved()
NodeSettings
are saved.public java.awt.geom.AffineTransform getCurrentTransform()
AffineTransform
defined within the tree. The current transform
is used when calling draw
without the AffineTransform
value.
getCurrentTransform
in interface DrawingTree<P extends NodeProperties>
public java.awt.Graphics2D getCurrentGraphics()
makeTree
or by the client using setCurrentGraphics
.
public void setScreenBounds(java.awt.geom.Rectangle2D bounds)
getClipBounds
on the Graphics2D passed, however, the bounds
can be set in any way.
setScreenBounds
in interface DrawingTree<P extends NodeProperties>
bounds
- the rectangle representing the bounds of the screen.public void setCurrentGraphics(java.awt.Graphics2D g2)
g2
- Graphics2D which are the defined graphics for the tree.public void setNodeSettings(NodeSettings s)
BSTTree
. No settings are saved
and the previous settings are not modified.
s
- NodeSettings
set for the entire tree.public void setSettings(NodeSettings s)
NodeSettings
of the DrawingTree
.
These settings are used for drawing the node and the links of the given tree.
If the settings are saved, the previous settings are modified to the NodeSettings
,
leaving the current settings unmodified. To modify the current settings, use setNodeSettings
.
If the settings are not saved, the previous settings are made null and the currentSettings are set.
setSettings
in interface DrawingTree<P extends NodeProperties>
s
- NodeSettings
for use in drawing the tree.public void restoreTransform()
AffineTransform
defined previously within the tree.
The previous transform is always the last transform defined and is automatically
updated each time setCurrentTransform
is called.
public void saveSettings()
public void saveLeftSettings()
public void saveRightSettings()
public void restoreLeftSettings()
public void restoreRightSettings()
public void restoreSettings()
public void drawNode()
AffineTransform
.
drawNode
in interface DrawingTree<P extends NodeProperties>
public void drawNode(java.awt.Graphics2D g2)
AffineTransform
.
drawNode
in interface DrawingTree<P extends NodeProperties>
g2
- graphics to which the node is drawn.public void drawNode(java.awt.Graphics2D g2, java.awt.geom.AffineTransform a)
AffineTransform
.
The drawing uses the AffineTransform
to determine the exact way to draw the
node.
drawNode
in interface DrawingTree<P extends NodeProperties>
g2
- graphics to which the node is drawn.a
- transform to draw the node.public void drawNodeAndLeftLink()
AffineTransform
,
section height, drawing level, and power level.
public void drawNodeAndRightLink()
AffineTransform
,
section height, drawing level, and power level.
public void eraseNodeAndLink()
public void eraseNodeAndLink(java.awt.Graphics2D g2)
public void drawNodeAndLink()
AffineTransform
,
section height, drawing level, and power level.
drawNodeAndLink
in interface DrawingTree<P extends NodeProperties>
public void drawNodeAndLink(java.awt.Graphics2D g2)
AffineTransform
,
section height, drawing level, and power level.
drawNodeAndLink
in interface DrawingTree<P extends NodeProperties>
g2
- graphics to which the node is drawn.public void drawNodeAndLink(java.awt.Graphics2D g2, boolean bottomLinks)
AffineTransform
,
section height, drawing level, and power level.
g2
- graphics to which the node is drawn.bottomLinks
- the boolean to declare whether the bottom links should be drawn.public void drawNodeAndLink(java.awt.Graphics2D g2, java.awt.geom.AffineTransform a)
g2
- graphics to which the node and links are drawn.a
- transfrom to draw the node and links.public void drawNodeAndLink(java.awt.Graphics2D g2, java.awt.geom.AffineTransform a, boolean bottomLinks)
g2
- graphics to which the node and links are drawn.a
- transfrom to draw the node and links.bottomLinks
- the boolean to declare whether the bottom links should be drawn.public void drawNodeAndLink(java.awt.Graphics2D g2, double sectionHeight, java.awt.geom.AffineTransform a, double drawingLevel, double powerLevel)
AffineTransform
, section height,
drawing level, and power level to render the node and its links.
drawNodeAndLink
in interface DrawingTree<P extends NodeProperties>
g2
- graphics to which the node and links are drawn.sectionHeight
- the height of the tree' section, to draw the correct lengths for the links.a
- transfrom to draw the node and links.drawingLevel
- the level in the tree to which the node is currently being drawn.powerLevel
- the power to which the links extend, depending on how many links are present.public void drawNodeAndLink(java.awt.Graphics2D g2, double sectionHeight, java.awt.geom.AffineTransform a, double drawingLevel, double powerLevel, boolean bottomLinks)
AffineTransform
, section height,
drawing level, and power level to render the node and its links.
g2
- graphics to which the node and links are drawn.sectionHeight
- the height of the tree' section, to draw the correct lengths for the links.a
- transfrom to draw the node and links.drawingLevel
- the level in the tree to which the node is currently being drawn.powerLevel
- the power to which the links extend, depending on how many links are present.bottomLinks
- the boolean to declare whether the bottom links should be drawn.public void constructAnimatingBSTTree()
public boolean isNodeAnimating()
isNodeAnimating
in interface AnimatingTree<P extends NodeProperties>
public Animation getAnimator()
Animation
of the node.
getAnimator
in interface AnimatingTree<P extends NodeProperties>
public void setAnimateDrawing(boolean animateDrawing)
animateDrawing
- boolean flag to draw if animating.public void addAnimator(Animation a)
addAnimator
in interface AnimatingTree<P extends NodeProperties>
a
- the Animation
being added to the node.public boolean isAnimateDrawing()
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.
animationEventPerformed
in interface AnimationListener
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 |