Class AbstractNode

java.lang.Object
uk.blankaspect.common.basictree.AbstractNode
All Implemented Interfaces:
Cloneable, ITreeNode<AbstractNode>
Direct Known Subclasses:
BooleanNode, DoubleNode, IntNode, ListNode, LongNode, MapNode, NullNode, StringNode

public abstract class AbstractNode extends Object implements ITreeNode<AbstractNode>, Cloneable
This is the abstract base class of a node of a tree. It is extended by concrete classes of the uk.blankaspect.common.basictree package that implement
  • a node that represents a null value,
  • nodes that contain instances of fundamental Java types (boolean, int, long, double and String), and
  • nodes that contain other nodes (a list and a map).

This class implements ITreeNode to allow the methods of TreeUtils to be used on a tree of AbstractNodes.

  • Constructor Details

    • AbstractNode

      protected AbstractNode(AbstractNode parent)
      Creates a new instance of a node with the specified parent.
      Parameters:
      parent - the parent of the node.
  • Method Details

    • getType

      public abstract NodeType getType()
      Returns the type of this node.
      Returns:
      the type of this node.
    • isContainer

      public abstract boolean isContainer()
      Returns true if this node can contain other nodes.
      Returns:
      true if this node can contain other nodes; false otherwise.
    • getParent

      public AbstractNode getParent()
      Returns the parent of this node.
      Specified by:
      getParent in interface ITreeNode<AbstractNode>
      Returns:
      the parent of this node, or null if this node has no parent.
    • getChildren

      public List<AbstractNode> getChildren()
      Returns a list of the children of this node.
      Specified by:
      getChildren in interface ITreeNode<AbstractNode>
      Returns:
      a list of the children of this node.
    • clone

      public AbstractNode clone()
      Creates and returns a copy of this node that has no parent.
      Overrides:
      clone in class Object
      Returns:
      a copy of this node that has no parent.
    • isRoot

      public boolean isRoot()
      Returns true if this node is the root of the tree to which it belongs. A node is deemed to be the root of its tree if it has no parent.
      Returns:
      true if this node is the root of the tree to which it belongs.
    • setParent

      public void setParent(AbstractNode parent)
      Sets the parent of this node to the specified node.
      Parameters:
      parent - the node to which the parent of this node will be set, which should be null if this node has no parent.
    • getListIndex

      public int getListIndex()
      If this node is an element of a list node, returns the index of the element in the list node's list of elements.
      Returns:
      if this node is an element of a list node, the index of the element; otherwise, -1.
    • getMapKey

      public String getMapKey()
      If this node is the value of a key–value pair of a map node, returns the key that is associated with the value.
      Returns:
      if this node is the value of a key–value pair of a map node, the key of the KV pair; otherwise, null.