org.synchronoss.cpo
Class Node

Package class diagram package Node
java.lang.Object
  extended by org.synchronoss.cpo.Node
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<Node>
Direct Known Subclasses:
JdbcCpoWhere

public class Node
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable, java.lang.Comparable<Node>

This is a general Node class to be used to build different types of trees. There are very few rules in this class as they should be implemented by users of this class.

Version:
1.0
Author:
David E. Berry
See Also:
Serialized Form

Constructor Summary
protected Node()
          This is the default constructor for the Node class.
protected Node(int nodeType)
          This constructor allows you to create a composite or component node based on the node_type.
 
Method Summary
 boolean acceptBFVisitor(INodeVisitor nv)
          Implements the visitor pattern.
 boolean acceptDFVisitor(INodeVisitor nv)
          Implements the visitor pattern.
 void addChild(Node node)
          This function adds a child to the linked-list of children for this node.
 void addChildSort(Node node)
          This function adds a child to the linked-list of children for this node.
 void addChildSort(Node node, java.util.Comparator<Node> c)
           
 java.lang.Object clone()
           
 int compareTo(Node o)
           
static Node createNode(int nodeType)
          This is the factory method for creating Node objects.
protected  int doCompare(Node n1, Node n2, java.util.Comparator<Node> c)
           
 boolean equals(Node o)
           
 boolean getAllowChildren()
           
 int getChildCount()
           
 java.util.List<Node> getChildList()
           
 Node getFirstChild()
          Gets the first child node in the linked-list of children.
 Node getNextSibling()
          Gets the next sibling for this node in the linked list of Nodes.
 Node getParentNode()
          Gets the parent node for this node
 Node getPrevSibling()
          Gets the previous sibling for this node in the linked list of Nodes.
 boolean hasParent()
          Checks to see if this node has a parent.
 void insertParentAfter(Node node)
          Inserts a new Parent Node as a child of this node and moves all pre-existing children to be children of the new Parent Node.
 void insertParentBefore(Node node)
          Inserts a new Parent into the tree structure and adds this node as its child.
 void insertSiblingAfter(Node node)
          Adds a Sibling immediately following this Node.
 void insertSiblingBefore(Node node)
          Inserts a Sibling into the linked list just prior to this Node
 boolean isLeaf()
          Checks to see if this node is a leaf node, that is, if it has no children.
 void release()
          Resets all the attributes to their default state.
 void removeAll()
          Remove this node and all its children from the tree.
 boolean removeChild(Node node)
          Searches for an immediate child node and if found removes it from the linked-list of children.
 void removeChildNode()
          Remove just this node from the tree.
protected  void setAllowChildren(boolean ac)
           
 void setFirstChild(Node node)
          Sets the first child node in the linked-list of children.
 void setNextSibling(Node node)
          Sets the NextSibling for this node.
 void setParent(Node node)
          Sets the Parent Node for this Node.
 void setPrevSibling(Node node)
          Sets the PrevSibling for this node.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Node

protected Node()
This is the default constructor for the Node class. By default, it creates a Composite Node, that is, a Node that can have children nodes.


Node

protected Node(int nodeType)
This constructor allows you to create a composite or component node based on the node_type.

Parameters:
nodeType - nodeType can be one of two values: Node.ParentNode Node.ChildNode
Method Detail

createNode

public static Node createNode(int nodeType)
This is the factory method for creating Node objects.

Parameters:
nodeType - nodeType can be one of two values: Node.ParentNode Node.ChildNode
Returns:
an Instance of an Node

release

public void release()
Resets all the attributes to their default state.


setAllowChildren

protected void setAllowChildren(boolean ac)

getAllowChildren

public boolean getAllowChildren()

setParent

public void setParent(Node node)
Sets the Parent Node for this Node.

Parameters:
node - The node that will become the parent.
See Also:
Node, Node, Node

setPrevSibling

public void setPrevSibling(Node node)
Sets the PrevSibling for this node. It also sets the NextSibling of the previous node to insure that the doubly-linked list is maintained.

Parameters:
node - The node that will become the previous Sibling

setNextSibling

public void setNextSibling(Node node)
Sets the NextSibling for this node. It also sets the PrevSibling of the next node to insure that the doubly-linked list is maintained.

Parameters:
node - The node that will become the next Sibling

getParentNode

public Node getParentNode()
Gets the parent node for this node

Returns:
an Node representing the parent of this node or null if no parent exists.

getPrevSibling

public Node getPrevSibling()
Gets the previous sibling for this node in the linked list of Nodes.

Returns:
an Node that represents the previous sibling or null if no sibling exists.

getNextSibling

public Node getNextSibling()
Gets the next sibling for this node in the linked list of Nodes.

Returns:
an Node that represents the next sibling or null if no sibling exists.

hasParent

public boolean hasParent()
Checks to see if this node has a parent.

Returns:
boolean indicating true if this node has a parent, false if it has no parent.

isLeaf

public boolean isLeaf()
Checks to see if this node is a leaf node, that is, if it has no children.

Returns:
boolean indicating true if it is a leafNode, false if not

addChild

public void addChild(Node node)
              throws ChildNodeException
This function adds a child to the linked-list of children for this node. It adds the child to the end of the list.

Parameters:
node - Node that is the node to be added as a child of this Node.
Throws:
NodeException
ChildNodeException

addChildSort

public void addChildSort(Node node)
                  throws ChildNodeException
This function adds a child to the linked-list of children for this node. It adds the child to the end of the list.

Parameters:
node - Node that is the node to be added as a child of this Node.
Throws:
NodeException
ChildNodeException

addChildSort

public void addChildSort(Node node,
                         java.util.Comparator<Node> c)
                  throws ChildNodeException
Throws:
ChildNodeException

doCompare

protected int doCompare(Node n1,
                        Node n2,
                        java.util.Comparator<Node> c)

insertSiblingBefore

public void insertSiblingBefore(Node node)
                         throws ChildNodeException
Inserts a Sibling into the linked list just prior to this Node

Parameters:
node - Node to be made the prevSibling
Throws:
ChildNodeException

insertSiblingAfter

public void insertSiblingAfter(Node node)
Adds a Sibling immediately following this Node.

Parameters:
node - Node to be made the next sibling

insertParentBefore

public void insertParentBefore(Node node)
                        throws ChildNodeException
Inserts a new Parent into the tree structure and adds this node as its child.

Parameters:
node - Node that will become this nodes new Parent.
Throws:
ChildNodeException

insertParentAfter

public void insertParentAfter(Node node)
                       throws ChildNodeException
Inserts a new Parent Node as a child of this node and moves all pre-existing children to be children of the new Parent Node.

Parameters:
node - Node to become a child of this node and parent to all pre-existing children of this node.
Throws:
ChildNodeException

removeChild

public boolean removeChild(Node node)
                    throws ChildNodeException
Searches for an immediate child node and if found removes it from the linked-list of children.

Parameters:
node - Node to be searched for and removed if found.
Throws:
ChildNodeException

removeChildNode

public void removeChildNode()
                     throws ChildNodeException
Remove just this node from the tree. The children of this node get attached to the parent.

Throws:
ChildNodeException

removeAll

public void removeAll()
               throws ChildNodeException
Remove this node and all its children from the tree.

Throws:
ChildNodeException

getFirstChild

public Node getFirstChild()
Gets the first child node in the linked-list of children.

Returns:
Node reference to the first child node in the linked-list of children

setFirstChild

public void setFirstChild(Node node)
                   throws ChildNodeException
Sets the first child node in the linked-list of children.

Parameters:
node - Node which will be made the first child node in the linked-list of children.
Throws:
ChildNodeException

acceptDFVisitor

public boolean acceptDFVisitor(INodeVisitor nv)
                        throws java.lang.Exception
Implements the visitor pattern. This is a Depth-based traversal that will call the INodeVisitor visitBegin(), visitMiddle(), and visitEnd() for parent nodes and will call visit() for leaf nodes.

Parameters:
nv - INodeVisitor to call upon reaching a node when traversing the tree.
Throws:
java.lang.Exception
See Also:
INodeVisitor

acceptBFVisitor

public boolean acceptBFVisitor(INodeVisitor nv)
                        throws java.lang.Exception
Implements the visitor pattern. This is a Breadth-based traversal that will call the INodeVisitor.visit() for all nodes.

Parameters:
nv - INodeVisitor to call upon reaching a node when traversing the tree.
Throws:
java.lang.Exception
See Also:
INodeVisitor

getChildCount

public int getChildCount()

getChildList

public java.util.List<Node> getChildList()

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException

compareTo

public int compareTo(Node o)
Specified by:
compareTo in interface java.lang.Comparable<Node>

equals

public boolean equals(Node o)


Copyright © 2010. All Rights Reserved.