- java.lang.Object
-
- org.arakhne.afc.math.tree.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 Summary
Fields Modifier and Type Field Description static booleanUSE_LINKED_LISTIndicates if the forests are using a linked list by default to store the trees.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractForest(List<Tree<D,?>> internalList)Constructor.protectedAbstractForest(List<Tree<D,?>> internalList, Collection<? extends Tree<D,?>> trees)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(Tree<D,?> tree)booleanaddAll(Collection<? extends Tree<D,?>> newTrees)voidaddForestListener(ForestListener listener)Add forest listener.Iterator<TreeNode<D,?>>broadFirstIterator()Replies a broad first iterator on nodes.voidclear()booleancontains(Object tree)booleancontainsAll(Collection<?> treeCollection)Iterator<D>dataBroadFirstIterator()Replies the broad-first iterator on the tree.Iterator<D>dataDepthFirstIterator()Replies a prefixed depth first iterator on the tree.Iterator<D>dataDepthFirstIterator(int infixPosition)Replies the depth first iterator on the tree.Iterator<D>dataDepthFirstIterator(DepthFirstNodeOrder nodeOrder)Replies a depth first iterator on the tree.Iterator<TreeNode<D,?>>depthFirstIterator()Replies a depth-first iterator on nodes.Iterator<TreeNode<D,?>>depthFirstIterator(DepthFirstNodeOrder nodeOrder)Replies a depth-first iterator on nodes.protected voidfireTreeAddition(Tree<D,?> tree)Fire the addition event.protected voidfireTreeRemoval(Tree<D,?> tree)Fire the removal event.int[]getHeights()Replies the heights of all the leaf nodes.intgetMaxHeight()Replies the maximal height of the forest.intgetMinHeight()Replies the minimal height of the forest.booleanisEmpty()Iterator<Tree<D,?>>iterator()booleanremove(Object obj)booleanremoveAll(Collection<?> tree)voidremoveForestListener(ForestListener listener)Remove forest listener.booleanretainAll(Collection<?> tree)intsize()Object[]toArray()<TT> TT[]toArray(TT[] array)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.util.Collection
equals, hashCode, parallelStream, removeIf, spliterator, stream, toArray
-
-
-
-
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
-
-
Method Detail
-
getMinHeight
@Pure public final int getMinHeight()
Description copied from interface:ForestReplies the minimal height of the forest.- Specified by:
getMinHeightin interfaceForest<D>- Returns:
- the height of the uppest leaf in the forest.
-
getMaxHeight
@Pure public final int getMaxHeight()
Description copied from interface:ForestReplies the maximal height of the forest.- Specified by:
getMaxHeightin interfaceForest<D>- Returns:
- the height of the lowest leaf in the forest.
-
getHeights
@Pure public final int[] getHeights()
Description copied from interface:ForestReplies the heights of all the leaf nodes. The order of the heights is given by a depth-first iteration.- Specified by:
getHeightsin interfaceForest<D>- Returns:
- the heights of the leaf nodes
-
depthFirstIterator
@Pure public final Iterator<TreeNode<D,?>> depthFirstIterator(DepthFirstNodeOrder nodeOrder)
Description copied from interface:ForestReplies a depth-first iterator on nodes.- Specified by:
depthFirstIteratorin interfaceForest<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:ForestReplies a depth-first iterator on nodes.- Specified by:
depthFirstIteratorin interfaceForest<D>- Returns:
- a depth-first iterator.
-
broadFirstIterator
@Pure public final Iterator<TreeNode<D,?>> broadFirstIterator()
Description copied from interface:ForestReplies a broad first iterator on nodes.- Specified by:
broadFirstIteratorin interfaceForest<D>- Returns:
- a broad first iterator.
-
dataDepthFirstIterator
@Pure public final Iterator<D> dataDepthFirstIterator()
Description copied from interface:ForestReplies a prefixed depth first iterator on the tree.- Specified by:
dataDepthFirstIteratorin interfaceForest<D>- Returns:
- a prefixed depth first iterator on data.
-
dataDepthFirstIterator
@Pure public final Iterator<D> dataDepthFirstIterator(DepthFirstNodeOrder nodeOrder)
Description copied from interface:ForestReplies a depth first iterator on the tree.- Specified by:
dataDepthFirstIteratorin interfaceForest<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:ForestReplies the depth first iterator on the tree.- Specified by:
dataDepthFirstIteratorin interfaceForest<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:ForestReplies the broad-first iterator on the tree.- Specified by:
dataBroadFirstIteratorin interfaceForest<D>- Returns:
- the iterator on user data.
-
add
public boolean add(Tree<D,?> tree)
- Specified by:
addin interfaceCollection<D>
-
addAll
public boolean addAll(Collection<? extends Tree<D,?>> newTrees)
- Specified by:
addAllin interfaceCollection<D>
-
clear
public void clear()
- Specified by:
clearin interfaceCollection<D>
-
contains
@Pure public boolean contains(Object tree)
- Specified by:
containsin interfaceCollection<D>
-
containsAll
@Pure public boolean containsAll(Collection<?> treeCollection)
- Specified by:
containsAllin interfaceCollection<D>
-
isEmpty
@Pure public boolean isEmpty()
- Specified by:
isEmptyin interfaceCollection<D>
-
remove
public boolean remove(Object obj)
- Specified by:
removein interfaceCollection<D>
-
removeAll
public boolean removeAll(Collection<?> tree)
- Specified by:
removeAllin interfaceCollection<D>
-
retainAll
public boolean retainAll(Collection<?> tree)
- Specified by:
retainAllin interfaceCollection<D>
-
size
@Pure public int size()
- Specified by:
sizein interfaceCollection<D>
-
toArray
@Pure public Object[] toArray()
- Specified by:
toArrayin interfaceCollection<D>
-
toArray
public <TT> TT[] toArray(TT[] array)
- Specified by:
toArrayin interfaceCollection<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.
-
-