Class AbstractParentlessTreeNode<D,​N extends AbstractParentlessTreeNode<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:
    Serializable, Comparable<N>, IterableNode<N>, TreeNode<D,​N>, JsonableObject
    Direct Known Subclasses:
    AbstractTreeNode

    public abstract class AbstractParentlessTreeNode<D,​N extends AbstractParentlessTreeNode<D,​N>>
    extends Object
    implements TreeNode<D,​N>, Serializable, JsonableObject
    This is the very generic implementation of a tree node which does not made any implementation choice about how this node is related to its parent node.
    Since:
    13.0
    Version:
    17.0 2020-01-04 14:41:41
    Author:
    Stéphane GALLAND
    See Also:
    Serialized Form
    Maven Group Id:
    org.arakhne.afc.core
    Maven Artifact Id:
    mathtree
    • Field Detail

      • DEFAULT_LINK_LIST_USE

        public static final boolean DEFAULT_LINK_LIST_USE
        By default, does tree nodes use a linked list or not.
        See Also:
        Constant Field Values
      • DEFAULT_COPY_USER_DATA

        public static final boolean DEFAULT_COPY_USER_DATA
        By default, does the user data are copied or not.
        See Also:
        Constant Field Values
      • nodeListeners

        protected transient List<TreeNodeListener> nodeListeners
        List of the event listeners on the tree.
    • Constructor Detail

      • AbstractParentlessTreeNode

        public AbstractParentlessTreeNode​(boolean useLinkedList)
        Construct node.
        Parameters:
        useLinkedList - indicates if a linked list must be used to store the data. If false, an ArrayList will be used.
      • AbstractParentlessTreeNode

        public AbstractParentlessTreeNode​(boolean useLinkedList,
                                          boolean copyDataCollection,
                                          List<D> idata)
        Construct node.
        Parameters:
        useLinkedList - indicates if a linked list must be used to store the data. If false, an ArrayList will be used.
        copyDataCollection - indicates if the given data collection is copied if true or the inner data collection will be the given collection itself if false.
        idata - are the initial user data
      • AbstractParentlessTreeNode

        public AbstractParentlessTreeNode​(boolean useLinkedList,
                                          Collection<D> idata)
        Construct node.
        Parameters:
        useLinkedList - indicates if a linked list must be used to store the data. If false, an ArrayList will be used.
        idata - are the initial user data
      • AbstractParentlessTreeNode

        public AbstractParentlessTreeNode​(boolean useLinkedList,
                                          D idata)
        Construct node.
        Parameters:
        useLinkedList - indicates if a linked list must be used to store the data. If false, an ArrayList will be used.
        idata - are the initial user data
    • Method Detail

      • toN

        @Pure
        public N toN()
        Cast this node to N.
        Returns:
        this
      • 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 AbstractParentlessTreeNode<D,​N>>
        Returns:
        true is this node is valid, otherwise false
      • toJson

        public void toJson​(JsonBuffer buffer)
        Replies the Json representation of this node.
        Specified by:
        toJson in interface JsonableObject
        Parameters:
        buffer - the Json buffer.
        Since:
        14.0
      • 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 AbstractParentlessTreeNode<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.
      • getInternalDataStructureForUserData

        @Pure
        protected final List<D> getInternalDataStructureForUserData()
        Replies the internal data structure which is storing user datas.

        Use with caution because any change applied outside AbstractParentlessTreeNode will not be taken into account (no event...).

        Returns:
        the internal data structure
      • 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 AbstractParentlessTreeNode<D,​N>>
        Parameters:
        data - the data to add.
        Returns:
        true if the the list of user data has changed, otherwise false.
      • addUserData

        public final 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 AbstractParentlessTreeNode<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 final 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 AbstractParentlessTreeNode<D,​N>>
        Parameters:
        data - the data to add.
        Returns:
        true if the data was successfully added, otherwhise false
      • addUserData

        public final 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 AbstractParentlessTreeNode<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 AbstractParentlessTreeNode<D,​N>>
        Parameters:
        data - the data to remove.
        Returns:
        true if the data was successfully removed, otherwhise false
      • removeUserData

        public final 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 AbstractParentlessTreeNode<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.
      • removeUserData

        public final boolean removeUserData​(D data1)
        Description copied from interface: TreeNode
        Remove a user data associated to this node.
        Specified by:
        removeUserData in interface TreeNode<D,​N extends AbstractParentlessTreeNode<D,​N>>
        Parameters:
        data1 - the data to remove.
        Returns:
        true if the data was successfully removed, otherwhise false
      • 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 AbstractParentlessTreeNode<D,​N>>
        Parameters:
        data - the data to put inside.
        Returns:
        true if the data was successfully set, otherwhise false
      • setUserData

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

        protected final void firePropertyDataChanged​(Collection<? extends D> oldData,
                                                     Collection<? extends D> newData)
        Fire the event for the changes of the user data associated to a node.
        Parameters:
        oldData - is the list of old values
        newData - is the list of new values
      • firePropertyDataChanged

        protected final void firePropertyDataChanged​(int delta)
        Fire the event for the changes of the user data associated to a node.
        Parameters:
        delta - is the difference between the size of the data list before change and size after change.
      • firePropertyDataChanged

        void firePropertyDataChanged​(TreeDataEvent event)
        Fire the event for the changes of the user data associated to a node.
        Parameters:
        event - is the event ot fire.
      • 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 AbstractParentlessTreeNode<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 AbstractParentlessTreeNode<D,​N>>
        Returns:
        the count of user data inside the subtree.
      • getHeights

        @Pure
        public final 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 AbstractParentlessTreeNode<D,​N>>
        Returns:
        the heights of the leaf nodes
      • getHeights

        protected abstract void getHeights​(int currentHeight,
                                           List<Integer> heights)
        Replies the heights of all the leaf nodes. The order of the heights is given by a depth-first iteration.
        Parameters:
        currentHeight - is the current height of this node.
        heights - is the list of heights to fill