Package uk.blankaspect.common.basictree
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
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
andString
), 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
AbstractNode
s.
-
Constructor Summary
ModifierConstructorDescriptionprotected
AbstractNode
(AbstractNode parent) Creates a new instance of a node with the specified parent. -
Method Summary
Modifier and TypeMethodDescriptionclone()
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
getType()
Returns the type of this node.abstract boolean
Returnstrue
if this node can contain other nodes.boolean
isRoot()
Returnstrue
if this node is the root of the tree to which it belongs.void
setParent
(AbstractNode parent) Sets the parent of this node to the specified node.
-
Constructor Details
-
AbstractNode
Creates a new instance of a node with the specified parent.- Parameters:
parent
- the parent of the node.
-
-
Method Details
-
getType
Returns the type of this node.- Returns:
- the type of this node.
-
isContainer
public abstract boolean isContainer()Returnstrue
if this node can contain other nodes.- Returns:
true
if this node can contain other nodes;false
otherwise.
-
getParent
Returns the parent of this node.- Specified by:
getParent
in interfaceITreeNode<AbstractNode>
- Returns:
- the parent of this node, or
null
if this node has no parent.
-
getChildren
Returns a list of the children of this node.- Specified by:
getChildren
in interfaceITreeNode<AbstractNode>
- Returns:
- a list of the children of this node.
-
clone
Creates and returns a copy of this node that has no parent. -
isRoot
public boolean isRoot()Returnstrue
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
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 benull
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
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
.
-