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>>
public class Node<T> extends Object implements Comparable<Node<T>>
Represents a node in aTree.- Author:
- Luca Frosini (ISTI - CNR)
-
-
Field Summary
Fields Modifier and Type Field Description protected Set<Node<T>>childrenThe children of this node.protected Set<T>childrenElementsThe elements of the children of this node.protected Set<T>descendantElementsThe elements of all descendants of this node.protected Set<Node<T>>descendantsAll descendants of this node.static StringINDENTATIONThe string used for indentation when printing the tree.protected Node<T>parentThe parent of this node.protected TtThe element stored in this node.protected Tree<T>treeThe tree to which this node belongs.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Node<T>addChild(Node<T> child)Adds a child to this node.intcompareTo(Node<T> other)voidelaborate(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.Set<Node<T>>getChildren()Returns the children of this node.Set<T>getChildrenElements()Returns the elements of the children of this node.Set<T>getDescendantElements()Returns the elements of all descendants of this node.Set<Node<T>>getDescendants()Returns all descendants of this node.StringgetIdentifier()Returns the identifier of this node's element.TgetNodeElement()Returns the element stored in this node.Node<T>getParent()Returns the parent of this node.Tree<T>getTree()Returns the tree to which this node belongs.Node<T>setParent(Node<T> parent)Sets the parent of this node.StringtoString()
-
-
-
Constructor Detail
-
Node
public Node(T t)
Constructs a new node with the given element.- Parameters:
t- The element to store in the node.
-
-
Method Detail
-
getTree
public Tree<T> getTree()
Returns the tree to which this node belongs.- Returns:
- The parent tree.
-
getNodeElement
public T getNodeElement()
Returns the element stored in this node.- Returns:
- The node's element.
-
getParent
public Node<T> getParent()
Returns the parent of this node.- Returns:
- The parent node, or
nullif this is the root.
-
setParent
public Node<T> setParent(Node<T> parent)
Sets the parent of this node.- Parameters:
parent- The parent node.- Returns:
- This node.
-
addChild
public Node<T> addChild(Node<T> child)
Adds a child to this node.- Parameters:
child- The child node to add.- Returns:
- This node.
-
getIdentifier
public String getIdentifier()
Returns the identifier of this node's element.- Returns:
- The identifier.
-
getChildren
public Set<Node<T>> getChildren()
Returns the children of this node.- Returns:
- A set of child nodes.
-
getDescendants
public Set<Node<T>> getDescendants()
Returns all descendants of this node.- Returns:
- A set of all descendant nodes.
-
getChildrenElements
public Set<T> getChildrenElements()
Returns the elements of the children of this node.- Returns:
- A set of the elements of the child nodes.
-
getDescendantElements
public Set<T> getDescendantElements()
Returns the elements of all descendants of this node.- Returns:
- A set of the elements of all descendant nodes.
-
compareTo
public int compareTo(Node<T> other)
- Specified by:
compareToin interfaceComparable<T>
-
elaborate
public void elaborate(NodeElaborator<T> nodeElaborator) throws Exception
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
protected void elaborate(NodeElaborator<T> nodeElaborator, int level) throws Exception
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.
-
-