Interface TreeNode<D,​N extends TreeNode<D,​?>>

    • Method Detail

      • getParentNode

        @Pure
        N getParentNode()
        Replies the parent node or null.
        Returns:
        the node that is containing this object.
      • setChildAt

        boolean setChildAt​(int index,
                           N child)
                    throws IndexOutOfBoundsException
        Set the n-th child in this node.
        Parameters:
        index - is the index of the child to reply
        child - is the new child node.
        Returns:
        true if it was set, otherwise false
        Throws:
        IndexOutOfBoundsException - if the given index was invalid
      • indexOf

        @Pure
        int indexOf​(N child)
        Replies the index of the specified child.
        Parameters:
        child - is the node to search for.
        Returns:
        the index or -1.
      • getPartitionEnumeration

        @Pure
        Class<? extends Enum<?>> getPartitionEnumeration()
        Replies the enumeration type that is defining the children of the nodes.
        Returns:
        the enumeration type of the child partition, or null if no such enumeration type is defined.
      • getAllUserData

        D[] getAllUserData​(D[] array)
        Replies the all user data associated to this node.
        Parameters:
        array - is the array to fill if it has enough cells
        Returns:
        the parameter a if it has enough cells, otherwise another array.
      • getAllUserData

        @Pure
        List<D> getAllUserData()
        Replies the all user data associated to this node.
        Returns:
        all the user data
      • getUserData

        @Pure
        D getUserData()
        Replies the first user data associated to this node.
        Returns:
        first user data
      • getUserDataCount

        @Pure
        int getUserDataCount()
        Replies the count of user data associated to this node.
        Returns:
        the count of user data.
      • getUserDataAt

        @Pure
        D getUserDataAt​(int index)
                 throws IndexOutOfBoundsException
        Replies the user data associated to this node which is at the specified index.
        Parameters:
        index - is the position of the data to reply
        Returns:
        the user data
        Throws:
        IndexOutOfBoundsException - when the given index in not valid
      • addUserData

        boolean addUserData​(Collection<? extends D> data)
        Add a user data associated to this node.
        Parameters:
        data - the data to add.
        Returns:
        true if the the list of user data has changed, otherwise false.
      • addUserData

        boolean addUserData​(int index,
                            Collection<? extends D> data)
        Add a user data associated to this node.
        Parameters:
        index - is the position where to put the elements in the user data list.
        data - the data to add.
        Returns:
        true if the the list of user data has changed, otherwise false.
      • addUserData

        boolean addUserData​(D data)
        Add a user data associated to this node.
        Parameters:
        data - the data to add.
        Returns:
        true if the data was successfully added, otherwhise false
      • addUserData

        void addUserData​(int index,
                         D data)
        Add a user data associated to this node.
        Parameters:
        index - is the position where to insert the data.
        data - the data to add.
      • removeUserData

        boolean removeUserData​(Collection<D> data)
        Remove a user data associated to this node.
        Parameters:
        data - the data to remove.
        Returns:
        true if the data was successfully removed, otherwhise false
      • removeUserData

        boolean removeUserData​(D data)
        Remove a user data associated to this node.
        Parameters:
        data - the data to remove.
        Returns:
        true if the data was successfully removed, otherwhise false
      • removeUserData

        D removeUserData​(int index)
        Remove a user data associated to this node.
        Parameters:
        index - is the position of the user data to remove.
        Returns:
        the removed data or null if the data was not removed.
      • setUserData

        boolean setUserData​(Collection<D> data)
        Set the user data associated to this node.
        Parameters:
        data - the data to put inside.
        Returns:
        true if the data was successfully set, otherwhise false
      • setUserData

        boolean setUserData​(D data)
        Set the user data associated to this node.
        Parameters:
        data - the data to put inside.
        Returns:
        true if the data was successfully set, otherwhise false
      • setUserDataAt

        boolean setUserDataAt​(int index,
                              D data)
                       throws IndexOutOfBoundsException
        Set the user data associated to this node at the specified index.
        Parameters:
        index - the index at which the data must be set.
        data - the data to put inside.
        Returns:
        true if the data was successfully set, otherwhise false
        Throws:
        IndexOutOfBoundsException - if the given index was invalid
      • addTreeNodeListener

        void addTreeNodeListener​(TreeNodeListener listener)
        Add a listener on the node events.
        Parameters:
        listener - the listener.
      • removeTreeNodeListener

        void removeTreeNodeListener​(TreeNodeListener listener)
        Remove a listener on the node events.
        Parameters:
        listener - the listener.
      • isEmpty

        @Pure
        boolean isEmpty()
        Replies if this node is a leaf and has no user data.

        This function is equivalent to call IterableNode.isLeaf() && getUserDataCount()==0

        Returns:
        true is this node is a leaf without user data, otherwise false
      • isRoot

        @Pure
        boolean isRoot()
        Replies if this node is a root.
        Returns:
        true is this node is the root, otherwise false
      • isValid

        @Pure
        boolean isValid()
        Replies if this node is a valid. The validity of a node depends of the node implementation.
        Returns:
        true is this node is valid, otherwise false
      • clear

        void clear()
        Clear the tree.

        Caution: this method also destroyes the links between the child nodes inside the tree. If you want to unlink the first-level child node with this node but leave the rest of the tree unchanged, please call setChildAt(i,null).

      • removeAllUserData

        void removeAllUserData()
        Remove all the user data associated to this node.
      • removeChild

        boolean removeChild​(N child)
        Remove the specified node from this node if it is a child.
        Parameters:
        child - is the child to remove.
        Returns:
        true if the node was removed, otherwise false
      • removeDeeplyFromParent

        void removeDeeplyFromParent()
        Remove this node from its parent and remove the parent if it is becoming empty, and so one.
      • getDeepNodeCount

        @Pure
        int getDeepNodeCount()
        Replies the count of nodes inside the tree for which the root is this node.
        Returns:
        the count of node inside the subtree.
      • getDeepUserDataCount

        @Pure
        int getDeepUserDataCount()
        Replies the count of user data inside the tree for which the root is this node.
        Returns:
        the count of user data inside the subtree.
      • getChildren

        @Pure
        N[] getChildren​(Class<N> type)
        Replies the child nodes of this node.

        This function may put null in the array cells if the current tree node has not a child at the corresponding index.

        Parameters:
        type - is the type of the children to reply.
        Returns:
        the children.
        See Also:
        getChildren(Object[]), children()
      • getChildren

        void getChildren​(Object[] array)
        Replies the child nodes of this node.

        This function may put null in the array cells if the current tree node has not a child at the corresponding index.

        Parameters:
        array - is the array to fill.
        See Also:
        getChildren(Class), children()
      • getDepth

        @Pure
        int getDepth()
        Replies the depth level of this node. Depth level 0 is the root node, 1 are the children of the root node, etc.
        Returns:
        the height of the lowest leaf in the tree.
      • getMinHeight

        @Pure
        int getMinHeight()
        Replies the minimal height of the tree.
        Returns:
        the height of the uppest leaf in the tree.
      • getMaxHeight

        @Pure
        int getMaxHeight()
        Replies the maximal height of the tree.
        Returns:
        the height of the lowest leaf in the tree.
      • getHeights

        @Pure
        int[] getHeights()
        Replies the heights of all the leaf nodes. The order of the heights is given by a depth-first iteration.
        Returns:
        the heights of the leaf nodes
      • moveTo

        boolean moveTo​(N newParent,
                       int index)
        Move this node in the given new node.

        If any child node is already present at the given position in the new parent node, the tree node may replace the existing node or insert the moving node according to its implementation.

        This function is preferred to a sequence of calls to IterableNode.removeFromParent() and setChildAt(int, TreeNode) because it fires a limited set of events dedicated to the move the node.

        Parameters:
        newParent - is the new parent for this node.
        index - is the position of this node in the new parent.
        Returns:
        true on success, otherwise false.