Class UnsupportedOperationTreeNode<D,​N extends TreeNode<D,​N>>

  • Type Parameters:
    D - is the type of the data inside the tree
    N - is the type of the tree nodes.
    All Implemented Interfaces:
    Comparable<N>, IterableNode<N>, TreeNode<D,​N>

    public class UnsupportedOperationTreeNode<D,​N extends TreeNode<D,​N>>
    extends Object
    implements TreeNode<D,​N>
    Generic implementation of a tree node that throws UnsupportedOperationException for all its operation. The sub classes must override the operations to provide a different behaviors.
    Since:
    13.0
    Version:
    17.0 2020-01-04 14:41:41
    Author:
    Stéphane GALLAND
    Maven Group Id:
    org.arakhne.afc.core
    Maven Artifact Id:
    mathtree
    • Constructor Detail

      • UnsupportedOperationTreeNode

        public UnsupportedOperationTreeNode()
    • Method Detail

      • getParentNode

        @Pure
        public N getParentNode()
        Description copied from interface: TreeNode
        Replies the parent node or null.
        Specified by:
        getParentNode in interface TreeNode<D,​N extends TreeNode<D,​N>>
        Returns:
        the node that is containing this object.
      • setChildAt

        public boolean setChildAt​(int index,
                                  N child)
                           throws IndexOutOfBoundsException
        Description copied from interface: TreeNode
        Set the n-th child in this node.
        Specified by:
        setChildAt in interface TreeNode<D,​N extends TreeNode<D,​N>>
        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
        public int indexOf​(N child)
        Description copied from interface: TreeNode
        Replies the index of the specified child.
        Specified by:
        indexOf in interface TreeNode<D,​N extends TreeNode<D,​N>>
        Parameters:
        child - is the node to search for.
        Returns:
        the index or -1.
      • getPartitionEnumeration

        @Pure
        public Class<? extends Enum<?>> getPartitionEnumeration()
        Description copied from interface: TreeNode
        Replies the enumeration type that is defining the children of the nodes.
        Specified by:
        getPartitionEnumeration in interface TreeNode<D,​N extends TreeNode<D,​N>>
        Returns:
        the enumeration type of the child partition, or null if no such enumeration type is defined.
      • getAllUserData

        public D[] getAllUserData​(D[] array)
        Description copied from interface: TreeNode
        Replies the all user data associated to this node.
        Specified by:
        getAllUserData in interface TreeNode<D,​N extends TreeNode<D,​N>>
        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
        public List<D> getAllUserData()
        Description copied from interface: TreeNode
        Replies the all user data associated to this node.
        Specified by:
        getAllUserData in interface TreeNode<D,​N extends TreeNode<D,​N>>
        Returns:
        all the user data
      • getUserData

        @Pure
        public D getUserData()
        Description copied from interface: TreeNode
        Replies the first user data associated to this node.
        Specified by:
        getUserData in interface TreeNode<D,​N extends TreeNode<D,​N>>
        Returns:
        first user data
      • getUserDataCount

        @Pure
        public int getUserDataCount()
        Description copied from interface: TreeNode
        Replies the count of user data associated to this node.
        Specified by:
        getUserDataCount in interface TreeNode<D,​N extends TreeNode<D,​N>>
        Returns:
        the count of user data.
      • addUserData

        public boolean addUserData​(Collection<? extends D> data)
        Description copied from interface: TreeNode
        Add a user data associated to this node.
        Specified by:
        addUserData in interface TreeNode<D,​N extends TreeNode<D,​N>>
        Parameters:
        data - the data to add.
        Returns:
        true if the the list of user data has changed, otherwise false.
      • addUserData

        public boolean addUserData​(int index,
                                   Collection<? extends D> data)
        Description copied from interface: TreeNode
        Add a user data associated to this node.
        Specified by:
        addUserData in interface TreeNode<D,​N extends TreeNode<D,​N>>
        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

        public boolean addUserData​(D data)
        Description copied from interface: TreeNode
        Add a user data associated to this node.
        Specified by:
        addUserData in interface TreeNode<D,​N extends TreeNode<D,​N>>
        Parameters:
        data - the data to add.
        Returns:
        true if the data was successfully added, otherwhise false
      • addUserData

        public void addUserData​(int index,
                                D data)
        Description copied from interface: TreeNode
        Add a user data associated to this node.
        Specified by:
        addUserData in interface TreeNode<D,​N extends TreeNode<D,​N>>
        Parameters:
        index - is the position where to insert the data.
        data - the data to add.
      • removeUserData

        public boolean removeUserData​(Collection<D> data)
        Description copied from interface: TreeNode
        Remove a user data associated to this node.
        Specified by:
        removeUserData in interface TreeNode<D,​N extends TreeNode<D,​N>>
        Parameters:
        data - the data to remove.
        Returns:
        true if the data was successfully removed, otherwhise false
      • removeUserData

        public boolean removeUserData​(D data)
        Description copied from interface: TreeNode
        Remove a user data associated to this node.
        Specified by:
        removeUserData in interface TreeNode<D,​N extends TreeNode<D,​N>>
        Parameters:
        data - the data to remove.
        Returns:
        true if the data was successfully removed, otherwhise false
      • removeUserData

        public D removeUserData​(int index)
        Description copied from interface: TreeNode
        Remove a user data associated to this node.
        Specified by:
        removeUserData in interface TreeNode<D,​N extends TreeNode<D,​N>>
        Parameters:
        index - is the position of the user data to remove.
        Returns:
        the removed data or null if the data was not removed.
      • setUserData

        public boolean setUserData​(Collection<D> data)
        Description copied from interface: TreeNode
        Set the user data associated to this node.
        Specified by:
        setUserData in interface TreeNode<D,​N extends TreeNode<D,​N>>
        Parameters:
        data - the data to put inside.
        Returns:
        true if the data was successfully set, otherwhise false
      • setUserData

        public boolean setUserData​(D data)
        Description copied from interface: TreeNode
        Set the user data associated to this node.
        Specified by:
        setUserData in interface TreeNode<D,​N extends TreeNode<D,​N>>
        Parameters:
        data - the data to put inside.
        Returns:
        true if the data was successfully set, otherwhise false
      • setUserDataAt

        public boolean setUserDataAt​(int index,
                                     D data)
                              throws IndexOutOfBoundsException
        Description copied from interface: TreeNode
        Set the user data associated to this node at the specified index.
        Specified by:
        setUserDataAt in interface TreeNode<D,​N extends TreeNode<D,​N>>
        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
      • isRoot

        @Pure
        public boolean isRoot()
        Description copied from interface: TreeNode
        Replies if this node is a root.
        Specified by:
        isRoot in interface TreeNode<D,​N extends TreeNode<D,​N>>
        Returns:
        true is this node is the root, otherwise false
      • isValid

        @Pure
        public boolean isValid()
        Description copied from interface: TreeNode
        Replies if this node is a valid. The validity of a node depends of the node implementation.
        Specified by:
        isValid in interface TreeNode<D,​N extends TreeNode<D,​N>>
        Returns:
        true is this node is valid, otherwise false
      • clear

        public void clear()
        Description copied from interface: TreeNode
        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).

        Specified by:
        clear in interface TreeNode<D,​N extends TreeNode<D,​N>>
      • removeAllUserData

        public void removeAllUserData()
        Description copied from interface: TreeNode
        Remove all the user data associated to this node.
        Specified by:
        removeAllUserData in interface TreeNode<D,​N extends TreeNode<D,​N>>
      • removeChild

        public boolean removeChild​(N child)
        Description copied from interface: TreeNode
        Remove the specified node from this node if it is a child.
        Specified by:
        removeChild in interface TreeNode<D,​N extends TreeNode<D,​N>>
        Parameters:
        child - is the child to remove.
        Returns:
        true if the node was removed, otherwise false
      • removeDeeplyFromParent

        public void removeDeeplyFromParent()
        Description copied from interface: TreeNode
        Remove this node from its parent and remove the parent if it is becoming empty, and so one.
        Specified by:
        removeDeeplyFromParent in interface TreeNode<D,​N extends TreeNode<D,​N>>
      • getDeepNodeCount

        @Pure
        public int getDeepNodeCount()
        Description copied from interface: TreeNode
        Replies the count of nodes inside the tree for which the root is this node.
        Specified by:
        getDeepNodeCount in interface TreeNode<D,​N extends TreeNode<D,​N>>
        Returns:
        the count of node inside the subtree.
      • getDeepUserDataCount

        @Pure
        public int getDeepUserDataCount()
        Description copied from interface: TreeNode
        Replies the count of user data inside the tree for which the root is this node.
        Specified by:
        getDeepUserDataCount in interface TreeNode<D,​N extends TreeNode<D,​N>>
        Returns:
        the count of user data inside the subtree.
      • getChildren

        @Pure
        public N[] getChildren​(Class<N> type)
        Description copied from interface: TreeNode
        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.

        Specified by:
        getChildren in interface TreeNode<D,​N extends TreeNode<D,​N>>
        Parameters:
        type - is the type of the children to reply.
        Returns:
        the children.
        See Also:
        TreeNode.getChildren(Object[]), TreeNode.children()
      • getDepth

        @Pure
        public int getDepth()
        Description copied from interface: TreeNode
        Replies the depth level of this node. Depth level 0 is the root node, 1 are the children of the root node, etc.
        Specified by:
        getDepth in interface TreeNode<D,​N extends TreeNode<D,​N>>
        Returns:
        the height of the lowest leaf in the tree.
      • getMinHeight

        @Pure
        public int getMinHeight()
        Description copied from interface: TreeNode
        Replies the minimal height of the tree.
        Specified by:
        getMinHeight in interface TreeNode<D,​N extends TreeNode<D,​N>>
        Returns:
        the height of the uppest leaf in the tree.
      • getMaxHeight

        @Pure
        public int getMaxHeight()
        Description copied from interface: TreeNode
        Replies the maximal height of the tree.
        Specified by:
        getMaxHeight in interface TreeNode<D,​N extends TreeNode<D,​N>>
        Returns:
        the height of the lowest leaf in the tree.
      • getHeights

        @Pure
        public int[] getHeights()
        Description copied from interface: TreeNode
        Replies the heights of all the leaf nodes. The order of the heights is given by a depth-first iteration.
        Specified by:
        getHeights in interface TreeNode<D,​N extends TreeNode<D,​N>>
        Returns:
        the heights of the leaf nodes
      • moveTo

        public boolean moveTo​(N newParent,
                              int index)
        Description copied from interface: TreeNode
        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 TreeNode.setChildAt(int, TreeNode) because it fires a limited set of events dedicated to the move the node.

        Specified by:
        moveTo in interface TreeNode<D,​N extends TreeNode<D,​N>>
        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.
      • isLeaf

        @Pure
        public boolean isLeaf()
        Description copied from interface: IterableNode
        Replies if this node is a leaf.
        Specified by:
        isLeaf in interface IterableNode<D>
        Returns:
        true is this node is a leaf, otherwise false
      • removeFromParent

        public N removeFromParent()
        Description copied from interface: IterableNode
        Remove this node from its parent.
        Specified by:
        removeFromParent in interface IterableNode<D>
        Returns:
        the parent node from which the node was removed.