Class AbstractForest<D>

  • Type Parameters:
    D - is the type of the data inside the forest
    All Implemented Interfaces:
    Iterable<Tree<D,​?>>, Collection<Tree<D,​?>>, Forest<D>
    Direct Known Subclasses:
    ArrayForest, LinkedForest

    public abstract class AbstractForest<D>
    extends Object
    implements Forest<D>
    This is the generic implementation of a forest of trees.

    A forest of trees is a collection of trees.

    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
    • Field Detail

      • USE_LINKED_LIST

        public static final boolean USE_LINKED_LIST
        Indicates if the forests are using a linked list by default to store the trees.
        See Also:
        Constant Field Values
    • Constructor Detail

      • AbstractForest

        protected AbstractForest​(List<Tree<D,​?>> internalList)
        Constructor.
        Parameters:
        internalList - is the internal list to use.
      • AbstractForest

        protected AbstractForest​(List<Tree<D,​?>> internalList,
                                 Collection<? extends Tree<D,​?>> trees)
        Constructor.
        Parameters:
        internalList - is the internal list to use.
        trees - is the trees to put inside the forest.
    • Method Detail

      • getMinHeight

        @Pure
        public final int getMinHeight()
        Description copied from interface: Forest
        Replies the minimal height of the forest.
        Specified by:
        getMinHeight in interface Forest<D>
        Returns:
        the height of the uppest leaf in the forest.
      • getMaxHeight

        @Pure
        public final int getMaxHeight()
        Description copied from interface: Forest
        Replies the maximal height of the forest.
        Specified by:
        getMaxHeight in interface Forest<D>
        Returns:
        the height of the lowest leaf in the forest.
      • getHeights

        @Pure
        public final int[] getHeights()
        Description copied from interface: Forest
        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 Forest<D>
        Returns:
        the heights of the leaf nodes
      • depthFirstIterator

        @Pure
        public final Iterator<TreeNode<D,​?>> depthFirstIterator​(DepthFirstNodeOrder nodeOrder)
        Description copied from interface: Forest
        Replies a depth-first iterator on nodes.
        Specified by:
        depthFirstIterator in interface Forest<D>
        Parameters:
        nodeOrder - indicates how the data are treated by the iterator.
        Returns:
        a depth first iterator on nodes
      • depthFirstIterator

        @Pure
        public final Iterator<TreeNode<D,​?>> depthFirstIterator()
        Description copied from interface: Forest
        Replies a depth-first iterator on nodes.
        Specified by:
        depthFirstIterator in interface Forest<D>
        Returns:
        a depth-first iterator.
      • broadFirstIterator

        @Pure
        public final Iterator<TreeNode<D,​?>> broadFirstIterator()
        Description copied from interface: Forest
        Replies a broad first iterator on nodes.
        Specified by:
        broadFirstIterator in interface Forest<D>
        Returns:
        a broad first iterator.
      • dataDepthFirstIterator

        @Pure
        public final Iterator<D> dataDepthFirstIterator()
        Description copied from interface: Forest
        Replies a prefixed depth first iterator on the tree.
        Specified by:
        dataDepthFirstIterator in interface Forest<D>
        Returns:
        a prefixed depth first iterator on data.
      • dataDepthFirstIterator

        @Pure
        public final Iterator<D> dataDepthFirstIterator​(DepthFirstNodeOrder nodeOrder)
        Description copied from interface: Forest
        Replies a depth first iterator on the tree.
        Specified by:
        dataDepthFirstIterator in interface Forest<D>
        Parameters:
        nodeOrder - indicates how the data are treated by the iterator.
        Returns:
        an iterator on the data.
      • dataDepthFirstIterator

        @Pure
        public final Iterator<D> dataDepthFirstIterator​(int infixPosition)
        Description copied from interface: Forest
        Replies the depth first iterator on the tree.
        Specified by:
        dataDepthFirstIterator in interface Forest<D>
        Parameters:
        infixPosition - is the index at which the parent will be treated according to its child set.
        Returns:
        the iterator on user data
        See Also:
        InfixDepthFirstTreeIterator
      • dataBroadFirstIterator

        @Pure
        public final Iterator<D> dataBroadFirstIterator()
        Description copied from interface: Forest
        Replies the broad-first iterator on the tree.
        Specified by:
        dataBroadFirstIterator in interface Forest<D>
        Returns:
        the iterator on user data.
      • add

        public boolean add​(Tree<D,​?> tree)
        Specified by:
        add in interface Collection<D>
      • isEmpty

        @Pure
        public boolean isEmpty()
        Specified by:
        isEmpty in interface Collection<D>
      • size

        @Pure
        public int size()
        Specified by:
        size in interface Collection<D>
      • toArray

        public <TT> TT[] toArray​(TT[] array)
        Specified by:
        toArray in interface Collection<D>
      • addForestListener

        public void addForestListener​(ForestListener listener)
        Add forest listener.
        Parameters:
        listener - the listener.
      • removeForestListener

        public void removeForestListener​(ForestListener listener)
        Remove forest listener.
        Parameters:
        listener - the listener.
      • fireTreeAddition

        protected void fireTreeAddition​(Tree<D,​?> tree)
        Fire the addition event.
        Parameters:
        tree - is the new tree in the forest.
      • fireTreeRemoval

        protected void fireTreeRemoval​(Tree<D,​?> tree)
        Fire the removal event.
        Parameters:
        tree - is the old tree in the forest.