Class TreeNode<T extends DBRow>

  • Type Parameters:
    T - The DBRow class

    public class TreeNode<T extends DBRow>
    extends Object
    Encapsulates a DBRow class for use in DBRecursiveQuery tree or path.

    Use getData() to retrieve the DBRow contain in the node, getParent() to move up the hierarchy, and getChildren() to move down it.

    Author:
    Gregory Graham
    • Constructor Summary

      Constructors 
      Constructor Description
      TreeNode​(T data)
      Create a new node for the DBRow
      TreeNode​(T data, TreeNode<T> parent)
      Create a new node the contains the specified DBRow as the data, and the specified TreeNode as the parent of the node.
    • Constructor Detail

      • TreeNode

        public TreeNode​(T data)
        Create a new node for the DBRow
        Parameters:
        data - the data to store in the node
      • TreeNode

        public TreeNode​(T data,
                        TreeNode<T> parent)
        Create a new node the contains the specified DBRow as the data, and the specified TreeNode as the parent of the node.
        Parameters:
        data - the data to store in the node
        parent - the parent node of the data
    • 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