Package org.gcube.informationsystem.tree
Class Tree<T>
java.lang.Object
org.gcube.informationsystem.tree.Tree<T>
- Type Parameters:
T- The type of the elements stored in the tree.
Represents a generic tree structure.
- Author:
- Luca Frosini (ISTI - CNR)
-
Constructor Summary
ConstructorsConstructorDescriptionTree()Constructs an empty tree.Tree(NodeInformation<T> ni) Constructs a tree with the given node information provider.Tree(T root, NodeInformation<T> ni) Constructs a tree with the given root element and node information provider. -
Method Summary
Modifier and TypeMethodDescriptionAdds a new node to the tree.voidelaborate(NodeElaborator<T> nodeElaborator) Traverses the tree and applies the given elaborator to each node.getNodeByIdentifier(String identifier) Returns the node with the given identifier.Returns the node information provider for this tree.Returns the root node of the tree.booleanChecks if a node is a child of another node.booleanisParentOf(String referenceIdentifier, String requiredParent) Checks if a node is a parent of another node.voidsetAllowMultipleInheritance(boolean allowMultipleInheritance) Sets whether multiple inheritance is allowed in this tree.voidSets the node information provider for this tree, if not already set.voidSets the root element of this tree, if not already set.toString()
-
Constructor Details
-
Tree
public Tree()Constructs an empty tree. -
Tree
Constructs a tree with the given node information provider.- Parameters:
ni- The node information provider.
-
Tree
Constructs a tree with the given root element and node information provider.- Parameters:
root- The root element.ni- The node information provider.
-
-
Method Details
-
setNodeInformation
Sets the node information provider for this tree, if not already set.- Parameters:
ni- The node information provider.
-
setRoot
Sets the root element of this tree, if not already set.- Parameters:
root- The root element.- Throws:
RuntimeException- if the node information provider has not been set.
-
setAllowMultipleInheritance
public void setAllowMultipleInheritance(boolean allowMultipleInheritance) Sets whether multiple inheritance is allowed in this tree.- Parameters:
allowMultipleInheritance-trueto allow multiple inheritance.
-
getNodeInformation
Returns the node information provider for this tree.- Returns:
- The node information provider.
-
addNode
Adds a new node to the tree.- Parameters:
t- The element to add.- Returns:
- The newly created or existing node for the element.
-
getRootNode
Returns the root node of the tree.- Returns:
- The root node.
-
toString
-
elaborate
Traverses the tree and applies the given elaborator to each node.- Parameters:
nodeElaborator- The elaborator to apply.- Throws:
Exception- if an error occurs during elaboration.
-
getNodeByIdentifier
Returns the node with the given identifier.- Parameters:
identifier- The identifier of the node.- Returns:
- The node, or
nullif not found.
-
isChildOf
Checks if a node is a child of another node.- Parameters:
referenceIdentifier- The identifier of the potential parent node.requiredChild- The identifier of the potential child node.- Returns:
trueif the second node is a child of the first.
-
isParentOf
Checks if a node is a parent of another node.- Parameters:
referenceIdentifier- The identifier of the potential child node.requiredParent- The identifier of the potential parent node.- Returns:
trueif the second node is a parent of the first.
-