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 Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    Creates a new instance of a node with the specified parent.
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates and returns a copy of this node that has no parent.
    Returns a list of the children of this node.
    int
    If this node is an element of a list node, returns the index of the element in the list node's list of elements.
    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 the parent of this node.
    abstract NodeType
    Returns the type of this node.
    abstract boolean
    Returns true if this node can contain other nodes.
    boolean
    Returns true if this node is the root of the tree to which it belongs.
    void
    Sets the parent of this node to the specified node.
    toString(boolean printableAsciiOnly)
    Returns a string representation of this node whose characters may optionally be escaped where necessary so that the returned string contains only printable characters from the US-ASCII character encoding.

    Methods inherited from class java.lang.Object

    equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface uk.blankaspect.common.tree.ITreeNode

    isLeaf
  • 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.
    • toString

      public String toString(boolean printableAsciiOnly)
      Returns a string representation of this node whose characters may optionally be escaped where necessary so that the returned string contains only printable characters from the US-ASCII character encoding.
      Parameters:
      printableAsciiOnly - if true, the characters of the string representation will be escaped where necessary so that the returned string contains only printable characters from the US-ASCII character encoding (ie, characters in the range U+0020 to U+007E inclusive).
      Returns:
      a string representation of this node.