- 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 boolean
USE_LINKED_LIST
Indicates if the forests are using a linked list by default to store the trees.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractForest(List<Tree<D,?>> internalList)
Constructor.protected
AbstractForest(List<Tree<D,?>> internalList, Collection<? extends Tree<D,?>> trees)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(Tree<D,?> tree)
boolean
addAll(Collection<? extends Tree<D,?>> newTrees)
void
addForestListener(ForestListener listener)
Add forest listener.Iterator<TreeNode<D,?>>
broadFirstIterator()
Replies a broad first iterator on nodes.void
clear()
boolean
contains(Object tree)
boolean
containsAll(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 void
fireTreeAddition(Tree<D,?> tree)
Fire the addition event.protected void
fireTreeRemoval(Tree<D,?> tree)
Fire the removal event.int[]
getHeights()
Replies the heights of all the leaf nodes.int
getMaxHeight()
Replies the maximal height of the forest.int
getMinHeight()
Replies the minimal height of the forest.boolean
isEmpty()
Iterator<Tree<D,?>>
iterator()
boolean
remove(Object obj)
boolean
removeAll(Collection<?> tree)
void
removeForestListener(ForestListener listener)
Remove forest listener.boolean
retainAll(Collection<?> tree)
int
size()
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:Forest
Replies the minimal height of the forest.- Specified by:
getMinHeight
in interfaceForest<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 interfaceForest<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 interfaceForest<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 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:Forest
Replies a depth-first iterator on nodes.- Specified by:
depthFirstIterator
in interfaceForest<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 interfaceForest<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 interfaceForest<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 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:Forest
Replies the depth first iterator on the tree.- Specified by:
dataDepthFirstIterator
in 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:Forest
Replies the broad-first iterator on the tree.- Specified by:
dataBroadFirstIterator
in interfaceForest<D>
- Returns:
- the iterator on user data.
-
add
public boolean add(Tree<D,?> tree)
- Specified by:
add
in interfaceCollection<D>
-
addAll
public boolean addAll(Collection<? extends Tree<D,?>> newTrees)
- Specified by:
addAll
in interfaceCollection<D>
-
clear
public void clear()
- Specified by:
clear
in interfaceCollection<D>
-
contains
@Pure public boolean contains(Object tree)
- Specified by:
contains
in interfaceCollection<D>
-
containsAll
@Pure public boolean containsAll(Collection<?> treeCollection)
- Specified by:
containsAll
in interfaceCollection<D>
-
isEmpty
@Pure public boolean isEmpty()
- Specified by:
isEmpty
in interfaceCollection<D>
-
remove
public boolean remove(Object obj)
- Specified by:
remove
in interfaceCollection<D>
-
removeAll
public boolean removeAll(Collection<?> tree)
- Specified by:
removeAll
in interfaceCollection<D>
-
retainAll
public boolean retainAll(Collection<?> tree)
- Specified by:
retainAll
in interfaceCollection<D>
-
size
@Pure public int size()
- Specified by:
size
in interfaceCollection<D>
-
toArray
@Pure public Object[] toArray()
- Specified by:
toArray
in interfaceCollection<D>
-
toArray
public <TT> TT[] toArray(TT[] array)
- Specified by:
toArray
in 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.
-
-