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.
public class Tree<T> extends Object
Represents a generic tree structure.- Author:
- Luca Frosini (ISTI - CNR)
-
-
Constructor Summary
Constructors Constructor Description Tree()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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Node<T>addNode(T t)Adds a new node to the tree.voidelaborate(NodeElaborator<T> nodeElaborator)Traverses the tree and applies the given elaborator to each node.Node<T>getNodeByIdentifier(String identifier)Returns the node with the given identifier.NodeInformation<T>getNodeInformation()Returns the node information provider for this tree.Node<T>getRootNode()Returns the root node of the tree.booleanisChildOf(String referenceIdentifier, String requiredChild)Checks 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.voidsetNodeInformation(NodeInformation<T> ni)Sets the node information provider for this tree, if not already set.voidsetRoot(T root)Sets the root element of this tree, if not already set.StringtoString()
-
-
-
Constructor Detail
-
Tree
public Tree()
Constructs an empty tree.
-
Tree
public Tree(NodeInformation<T> ni)
Constructs a tree with the given node information provider.- Parameters:
ni- The node information provider.
-
Tree
public Tree(T root, NodeInformation<T> ni)
Constructs a tree with the given root element and node information provider.- Parameters:
root- The root element.ni- The node information provider.
-
-
Method Detail
-
setNodeInformation
public void setNodeInformation(NodeInformation<T> ni)
Sets the node information provider for this tree, if not already set.- Parameters:
ni- The node information provider.
-
setRoot
public void setRoot(T root) throws RuntimeException
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
public NodeInformation<T> getNodeInformation()
Returns the node information provider for this tree.- Returns:
- The node information provider.
-
addNode
public Node<T> addNode(T t)
Adds a new node to the tree.- Parameters:
t- The element to add.- Returns:
- The newly created or existing node for the element.
-
elaborate
public void elaborate(NodeElaborator<T> nodeElaborator) throws Exception
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
public Node<T> getNodeByIdentifier(String identifier)
Returns the node with the given identifier.- Parameters:
identifier- The identifier of the node.- Returns:
- The node, or
nullif not found.
-
isChildOf
public boolean isChildOf(String referenceIdentifier, String requiredChild)
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
public boolean isParentOf(String referenceIdentifier, String requiredParent)
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.
-
-