jdsl.core.ref
Class NodeBinaryTree.NBTNode

java.lang.Object
  |
  +--jdsl.core.ref.HashtableDecorable
        |
        +--jdsl.core.ref.NodeBinaryTree.NBTNode
All Implemented Interfaces:
Accessor, Decorable, Position, java.io.Serializable
Direct Known Subclasses:
NodeBinaryTree.NBTSuperNode
Enclosing class:
NodeBinaryTree

protected static class NodeBinaryTree.NBTNode
extends HashtableDecorable
implements Position

This is the class for all user-visible nodes It contains links for its parent, children, and element. It determines its container by asking its parent; the supernode will be at the end of a chain of parents, and it will know. All methods must be protected so subclasses can override them

See Also:
Serialized Form

Constructor Summary
protected NodeBinaryTree.NBTNode(NodeBinaryTree.NBTNode parent, java.lang.Object element)
          make a new external node
 
Method Summary
protected  NodeBinaryTree container()
          O(1) time
 java.lang.Object element()
          O(1) time
protected  void expand()
          O(1) time Expands this node into an internal node Asserts if this node is external
protected  boolean isInternal()
          O(1) time
protected  boolean isLeftChild()
          O(1) time
protected  boolean isSuperNode()
          Used to determine if this node is the super node
protected  NodeBinaryTree.NBTNode left()
          O(1) time
protected  void makeUncontained()
          O(1) time Makes this node uncontained
protected  NodeBinaryTree.NBTNode otherChild(NodeBinaryTree.NBTNode child)
          O(1) time
protected  NodeBinaryTree.NBTNode parent()
          O(1) time
protected  void removeSelfAndAbove()
          O(1) time This method removes this node and its parent, replacing its parent with my sibling This is the asymmetric opposite of expand.
protected  java.lang.Object replaceElement(java.lang.Object newElement)
          O(1) time Replaces my element, returning the old element
protected  void replaceSelf(NodeBinaryTree.NBTNode newSubtree)
          O(1) time Replaces me with a new node, as far as my parent is concerned protected so restructurable trees can use it
protected  NodeBinaryTree.NBTNode right()
          O(1) time
protected  void setChild(NodeBinaryTree.NBTNode currchild, NodeBinaryTree.NBTNode newchild)
          O(1) time Replaces one of my children with a new node protected to allow SuperNode to override it
protected  void setContainer(NodeBinaryTree x)
          O(1) time Sets the parameter container as this node's container
protected  void setLeft(NodeBinaryTree.NBTNode x)
          O(1) time Sets the parameter node as this node's left child
protected  void setParent(NodeBinaryTree.NBTNode x)
          O(1) time Sets the parameter node as this node's parent
protected  void setRight(NodeBinaryTree.NBTNode x)
          O(1) time Sets the parameter node as this node's right child
 java.lang.String toString()
           
 
Methods inherited from class jdsl.core.ref.HashtableDecorable
capacity, destroy, get, has, hash, rehash, set, size
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface jdsl.core.api.Decorable
destroy, get, has, set
 

Constructor Detail

NodeBinaryTree.NBTNode

protected NodeBinaryTree.NBTNode(NodeBinaryTree.NBTNode parent,
                                 java.lang.Object element)
make a new external node
Method Detail

element

public java.lang.Object element()
O(1) time
Specified by:
element in interface Accessor
Following copied from interface: jdsl.core.api.Accessor
Returns:
the element currently stored at this accessor

container

protected NodeBinaryTree container()
O(1) time
Returns:
this node's container.

parent

protected NodeBinaryTree.NBTNode parent()
O(1) time
Returns:
this node's parent.

left

protected NodeBinaryTree.NBTNode left()
O(1) time
Returns:
this node's left child.

right

protected NodeBinaryTree.NBTNode right()
O(1) time
Returns:
this node's right child.

otherChild

protected NodeBinaryTree.NBTNode otherChild(NodeBinaryTree.NBTNode child)
O(1) time
Parameters:
one - of my children
Returns:
my other child (asserts if the parameter isn't my child)

isInternal

protected boolean isInternal()
O(1) time
Returns:
Whether or not this node is internal

setLeft

protected void setLeft(NodeBinaryTree.NBTNode x)
O(1) time Sets the parameter node as this node's left child
Parameters:
A - node

setRight

protected void setRight(NodeBinaryTree.NBTNode x)
O(1) time Sets the parameter node as this node's right child
Parameters:
A - node

setParent

protected void setParent(NodeBinaryTree.NBTNode x)
O(1) time Sets the parameter node as this node's parent
Parameters:
A - node

setContainer

protected void setContainer(NodeBinaryTree x)
O(1) time Sets the parameter container as this node's container

isLeftChild

protected boolean isLeftChild()
O(1) time
Returns:
whether or not this node is its parent's left child

makeUncontained

protected void makeUncontained()
O(1) time Makes this node uncontained

expand

protected void expand()
O(1) time Expands this node into an internal node Asserts if this node is external

removeSelfAndAbove

protected void removeSelfAndAbove()
O(1) time This method removes this node and its parent, replacing its parent with my sibling This is the asymmetric opposite of expand.

setChild

protected void setChild(NodeBinaryTree.NBTNode currchild,
                        NodeBinaryTree.NBTNode newchild)
O(1) time Replaces one of my children with a new node protected to allow SuperNode to override it
Parameters:
currchild - My current child
newchild - The node to replace it with

replaceSelf

protected void replaceSelf(NodeBinaryTree.NBTNode newSubtree)
O(1) time Replaces me with a new node, as far as my parent is concerned protected so restructurable trees can use it
Parameters:
newSubtree - the node to replace me with

replaceElement

protected java.lang.Object replaceElement(java.lang.Object newElement)
O(1) time Replaces my element, returning the old element
Parameters:
newElement - my new element
Returns:
The element I used to contain

isSuperNode

protected boolean isSuperNode()
Used to determine if this node is the super node

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object