Class DefaultTreeNode<Self extends DefaultTreeNode<Self>>

  • All Implemented Interfaces:
    TreeNode<Self>
    Direct Known Subclasses:
    ModelCriteriaNode

    public class DefaultTreeNode<Self extends DefaultTreeNode<Self>>
    extends Object
    implements TreeNode<Self>
    Generic implementation of a node in a tree.

    Any method that is not purely on tree or nodes should go into a specialized subclass of this class!

    Author:
    hmlnarik
    • Constructor Detail

      • DefaultTreeNode

        protected DefaultTreeNode​(Map<String,​Object> treeProperties)
        Parameters:
        treeProperties - Reference to tree properties map. Tree properties are maintained outside of this node.
    • Method Detail

      • getEdgeProperties

        public Map<String,​Object> getEdgeProperties()
        Description copied from interface: TreeNode
        Parent-to-this-node edge properties. For example, import/no-import mode or sync mode belongs here.
        Specified by:
        getEdgeProperties in interface TreeNode<Self extends DefaultTreeNode<Self>>
        Returns:
        Returns properties of the edge from the parent to this node. Never returns null.
      • getEdgeProperty

        public <V> Optional<V> getEdgeProperty​(String key,
                                               Class<V> clazz)
        Description copied from interface: TreeNode
        Convenience method for obtaining a single parent-to-this-node edge property.
        Specified by:
        getEdgeProperty in interface TreeNode<Self extends DefaultTreeNode<Self>>
        Returns:
        Optional with a property value if it exists. Never returns null
      • setEdgeProperty

        public void setEdgeProperty​(String property,
                                    Object value)
      • getNodeProperties

        public Map<String,​Object> getNodeProperties()
        Description copied from interface: TreeNode
        Properties of the this node. In storage context, properties of the single map storage represented by this node, for example read-only/read-write flag.
        Specified by:
        getNodeProperties in interface TreeNode<Self extends DefaultTreeNode<Self>>
        Returns:
        Returns properties of the storage managed in this node. Never returns null.
      • getNodeProperty

        public <V> Optional<V> getNodeProperty​(String key,
                                               Class<V> clazz)
        Description copied from interface: TreeNode
        Convenience method for obtaining a single property of this node.
        Specified by:
        getNodeProperty in interface TreeNode<Self extends DefaultTreeNode<Self>>
        Returns:
        Optional with a property value if it exists. Never returns null
      • setNodeProperty

        public void setNodeProperty​(String property,
                                    Object value)
      • getTreeProperties

        public Map<String,​Object> getTreeProperties()
        Description copied from interface: TreeNode
        Properties of the whole tree. For example, kind of the stored objects, e.g. realms or clients.
        Specified by:
        getTreeProperties in interface TreeNode<Self extends DefaultTreeNode<Self>>
        Returns:
        Returns properties of the tree that contains in this node. Never returns null.
      • getTreeProperty

        public <V> Optional<V> getTreeProperty​(String key,
                                               Class<V> clazz)
        Description copied from interface: TreeNode
        Convenience method for obtaining a single property of tree that this node belongs to.
        Specified by:
        getTreeProperty in interface TreeNode<Self extends DefaultTreeNode<Self>>
        Returns:
        Optional with a property value if it exists. Never returns null
      • getId

        public String getId()
        Description copied from interface: TreeNode
        Returns ID of the node, which could match e.g. ID of the component with storage definition.
        Specified by:
        getId in interface TreeNode<Self extends DefaultTreeNode<Self>>
        Returns:
        Node ID
      • setId

        public void setId​(String id)
      • findFirstDfs

        public Optional<Self> findFirstDfs​(Predicate<Self> visitor)
        Description copied from interface: TreeNode
        Depth-first search for a node.
        Specified by:
        findFirstDfs in interface TreeNode<Self extends DefaultTreeNode<Self>>
        Parameters:
        visitor - Predicate on nodes, returns true when a search condition is satisfied which terminates the search.
        Returns:
        Leftmost first node that matches the predicate, null when no node matches.
      • findFirstBottommostDfs

        public Optional<Self> findFirstBottommostDfs​(Predicate<Self> visitor)
        Description copied from interface: TreeNode
        Depth-first search for a node that is bottommost from those matching DFS.
        Specified by:
        findFirstBottommostDfs in interface TreeNode<Self extends DefaultTreeNode<Self>>
        Parameters:
        visitor - Predicate on nodes, returns true when a search condition is satisfied which terminates the search.
        Returns:
        Leftmost and bottommost node that matches the predicate, null when no node matches.
      • findFirstBfs

        public Optional<Self> findFirstBfs​(Predicate<Self> visitor)
        Description copied from interface: TreeNode
        Breadth-first search for a node.
        Specified by:
        findFirstBfs in interface TreeNode<Self extends DefaultTreeNode<Self>>
        Parameters:
        visitor - Predicate on nodes, returns true when a search condition is satisfied which terminates the search.
        Returns:
        First node that matches the predicate, null when no node matches.
      • getChildren

        public List<Self> getChildren()
        Description copied from interface: TreeNode
        Returns the children of the current node. Order does matter.
        Specified by:
        getChildren in interface TreeNode<Self extends DefaultTreeNode<Self>>
        Returns:
        Read-only list of the children. Never returns null.
      • addChild

        public void addChild​(Self node)
        Description copied from interface: TreeNode
        Adds a node as a child of this node, and sets the parent of the node to this node.
        Specified by:
        addChild in interface TreeNode<Self extends DefaultTreeNode<Self>>
        Parameters:
        node - Future child node. If null or the node is already amongst the children list, no action is done.
      • addChild

        public void addChild​(int index,
                             Self node)
        Description copied from interface: TreeNode
        Adds a node as a child of this node, and sets the parent of the node to this node.
        Specified by:
        addChild in interface TreeNode<Self extends DefaultTreeNode<Self>>
        Parameters:
        index - Index at which the specified element is to be inserted
        node - Future child node. If null or the node is already amongst the children list, no action is done.
      • setParent

        public void setParent​(Self parent)
        Description copied from interface: TreeNode
        Sets the parent node to the given parent. If this node was a child of another node, also removes this node from the children of the previous parent.
        Specified by:
        setParent in interface TreeNode<Self extends DefaultTreeNode<Self>>
        Parameters:
        parent - New parent node or null if this node should be parentless.
      • cloneTree

        public <RNode extends TreeNode<? super RNode>> RNode cloneTree​(Function<Self,​RNode> instantiateFunc)