Package nz.co.gregs.dbvolution.query
Class TreeNode<T extends DBRow>
- java.lang.Object
-
- nz.co.gregs.dbvolution.query.TreeNode<T>
-
- Type Parameters:
T
- The DBRow class
public class TreeNode<T extends DBRow> extends Object
Encapsulates a DBRow class for use inDBRecursiveQuery
tree or path.Use
getData()
to retrieve the DBRow contain in the node,getParent()
to move up the hierarchy, andgetChildren()
to move down it.- Author:
- Gregory Graham
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChild(TreeNode<T> child)
Append the supplied DBRow to the list of children for this node.void
addChild(T childData)
Append the supplied DBRow to the list of children for this node.List<TreeNode<T>>
getChildren()
Returns a list of all known children of this node, that is all database rows returned by the recursive query that referenced this row.T
getData()
Retrieves the DBRow within this node.TreeNode<T>
getParent()
Retrieves the node that is the parent of this node.boolean
isLeaf()
Indicates whether or not this node is a leaf node, that is it has no known children.boolean
isRoot()
Indicates whether or not this node is a root node, that is it has no known parent.String
toString()
-
-
-
Constructor Detail
-
TreeNode
public TreeNode(T data)
Create a new node for the DBRow- Parameters:
data
- the data to store in the node
-
-
Method Detail
-
getChildren
public List<TreeNode<T>> getChildren()
Returns a list of all known children of this node, that is all database rows returned by the recursive query that referenced this row.- Returns:
- a list of TreeNodes
-
addChild
public void addChild(T childData)
Append the supplied DBRow to the list of children for this node.Also adds this node as the parent of the supplied node.
- Parameters:
childData
- the data to add as a child of this node
-
addChild
public void addChild(TreeNode<T> child)
Append the supplied DBRow to the list of children for this node.Also adds this node as the parent of the supplied node.
- Parameters:
child
- the node to add as a child of this node
-
getData
public T getData()
Retrieves the DBRow within this node.- Returns:
- a DBRow
-
isRoot
public boolean isRoot()
Indicates whether or not this node is a root node, that is it has no known parent.- Returns:
- TRUE if this node is the top of a hierarchy.
-
isLeaf
public boolean isLeaf()
Indicates whether or not this node is a leaf node, that is it has no known children.- Returns:
- TRUE if this node is the bottom of a hierarchy.
-
getParent
public TreeNode<T> getParent()
Retrieves the node that is the parent of this node.Use
isRoot()
to determine if the root has been reached.- Returns:
- the TreeNode immediately above this node in the hierarchy
-
-