Package org.gcube.informationsystem.tree
Class Node<T>
java.lang.Object
org.gcube.informationsystem.tree.Node<T>
- Type Parameters:
T- The type of the element stored in the node.
- All Implemented Interfaces:
Comparable<Node<T>>
Represents a node in a
Tree.- Author:
- Luca Frosini (ISTI - CNR)
-
Field Summary
FieldsModifier and TypeFieldDescriptionThe children of this node.The elements of the children of this node.The elements of all descendants of this node.All descendants of this node.static StringThe string used for indentation when printing the tree.The parent of this node.protected TThe element stored in this node.The tree to which this node belongs. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds a child to this node.intvoidelaborate(NodeElaborator<T> nodeElaborator) Traverses the subtree starting from this node and applies the given elaborator.protected voidelaborate(NodeElaborator<T> nodeElaborator, int level) Traverses the subtree starting from this node and applies the given elaborator.Returns the children of this node.Returns the elements of the children of this node.Returns the elements of all descendants of this node.Returns all descendants of this node.Returns the identifier of this node's element.Returns the element stored in this node.Returns the parent of this node.getTree()Returns the tree to which this node belongs.Sets the parent of this node.toString()
-
Field Details
-
INDENTATION
The string used for indentation when printing the tree. -
t
The element stored in this node. -
tree
The tree to which this node belongs. -
childrenElements
The elements of the children of this node. -
descendantElements
The elements of all descendants of this node. -
parent
The parent of this node. -
children
The children of this node. -
descendants
All descendants of this node.
-
-
Constructor Details
-
Node
Constructs a new node with the given element.- Parameters:
t- The element to store in the node.
-
-
Method Details
-
getTree
Returns the tree to which this node belongs.- Returns:
- The parent tree.
-
getNodeElement
Returns the element stored in this node.- Returns:
- The node's element.
-
getParent
Returns the parent of this node.- Returns:
- The parent node, or
nullif this is the root.
-
setParent
Sets the parent of this node.- Parameters:
parent- The parent node.- Returns:
- This node.
-
addChild
Adds a child to this node.- Parameters:
child- The child node to add.- Returns:
- This node.
-
getIdentifier
Returns the identifier of this node's element.- Returns:
- The identifier.
-
getChildren
Returns the children of this node.- Returns:
- A set of child nodes.
-
getDescendants
Returns all descendants of this node.- Returns:
- A set of all descendant nodes.
-
getChildrenElements
Returns the elements of the children of this node.- Returns:
- A set of the elements of the child nodes.
-
getDescendantElements
Returns the elements of all descendants of this node.- Returns:
- A set of the elements of all descendant nodes.
-
toString
-
compareTo
- Specified by:
compareToin interfaceComparable<T>
-
elaborate
Traverses the subtree starting from this node and applies the given elaborator.- Parameters:
nodeElaborator- The elaborator to apply to each node.- Throws:
Exception- if an error occurs during elaboration.
-
elaborate
Traverses the subtree starting from this node and applies the given elaborator.- Parameters:
nodeElaborator- The elaborator to apply to each node.level- The current level in the tree.- Throws:
Exception- if an error occurs during elaboration.
-