Class TreeNode


  • public class TreeNode
    extends java.lang.Object
    Represents a node of a tree.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      java.util.List<TreeNode> children
      The children.
      protected java.lang.Object data
      The user node data.
    • Constructor Summary

      Constructors 
      Constructor Description
      TreeNode()
      Create a new node.
      TreeNode​(java.lang.Object data)
      Create a new node.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addChild​(TreeNode child)
      Adds a child to the list of children for this node.
      java.util.List<TreeNode> getChildren()
      Return the children of node.
      java.lang.Object getData()
      Get the node data.
      int getNumberOfChildren()
      Returns the number of immediate children of this node.
      void insertChildAt​(int index, TreeNode child)
      Inserts a node at the specified position in the child list.
      void removeChildAt​(int index)
      Remove the Node element at index index of the List.
      void setChildren​(java.util.List<TreeNode> children)
      Sets the children of a Node object.
      void setData​(java.lang.Object data)
      Set the node data.
      java.lang.String toString()
      Get the string representation.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • data

        protected java.lang.Object data
        The user node data.
      • children

        public java.util.List<TreeNode> children
        The children.
    • Constructor Detail

      • TreeNode

        public TreeNode()
        Create a new node.
      • TreeNode

        public TreeNode​(java.lang.Object data)
        Create a new node.
    • Method Detail

      • getChildren

        public java.util.List<TreeNode> getChildren()
        Return the children of node.
        Returns:
        The children of node.
      • setChildren

        public void setChildren​(java.util.List<TreeNode> children)
        Sets the children of a Node object.
        Parameters:
        children - The list to set.
      • getNumberOfChildren

        public int getNumberOfChildren()
        Returns the number of immediate children of this node.
        Returns:
        the number of immediate children.
      • addChild

        public void addChild​(TreeNode child)
        Adds a child to the list of children for this node.
        Parameters:
        child - a Node
      • insertChildAt

        public void insertChildAt​(int index,
                                  TreeNode child)
                           throws java.lang.IndexOutOfBoundsException
        Inserts a node at the specified position in the child list. Will throw an ArrayIndexOutOfBoundsException if the index does not exist.
        Parameters:
        index - the position to insert at.
        child - the Node object to insert.
        Throws:
        java.lang.IndexOutOfBoundsException - if thrown.
      • removeChildAt

        public void removeChildAt​(int index)
                           throws java.lang.IndexOutOfBoundsException
        Remove the Node element at index index of the List.
        Parameters:
        index - the index of the element to delete.
        Throws:
        java.lang.IndexOutOfBoundsException - if thrown.
      • getData

        public java.lang.Object getData()
        Get the node data.
        Returns:
        The node data.
      • setData

        public void setData​(java.lang.Object data)
        Set the node data.
        Parameters:
        data - The node data.
      • toString

        public java.lang.String toString()
        Get the string representation.
        Overrides:
        toString in class java.lang.Object
        Returns:
        The string representation.