Class 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 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 - true to 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.
      • getRootNode

        public Node<T> getRootNode()
        Returns the root node of the tree.
        Returns:
        The root node.
      • 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 null if 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:
        true if 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:
        true if the second node is a parent of the first.