Package de.xima.fc.common.tree
Class TreeReversePostOrderIterable<TItem,TIdentifier>
- java.lang.Object
-
- de.xima.fc.common.tree.TreeReversePostOrderIterable<TItem,TIdentifier>
-
- Type Parameters:
TItem
- Type of the items in the tree.TIdentifier
- Type of the identifier that identifiers the items in the tree.
- All Implemented Interfaces:
Iterable<TItem>
public final class TreeReversePostOrderIterable<TItem,TIdentifier> extends Object implements Iterable<TItem>
An iterable that iterates over a tree-like graph in reverse post order, starting at a given node. Throws an exception in case the graph is not a tree, thus also preventing endless cycles when the graph is cyclic.- Since:
- 8.2.0
- Author:
- XIMA MEDIA GmbH
-
-
Constructor Summary
Constructors Constructor Description TreeReversePostOrderIterable(Iterable<TItem> startItems, ITreeAccessor<TItem,TIdentifier> treeAccessor)
Returns a new iterable over the items in the tree starting at the given item.TreeReversePostOrderIterable(Iterable<TItem> startItems, ITreeAccessor<TItem,TIdentifier> treeAccessor, boolean limitRecursion)
Returns a new iterable over the items in the tree starting at the given item.TreeReversePostOrderIterable(TItem startItem, ITreeAccessor<TItem,TIdentifier> treeAccessor)
Returns a new iterable over the items in the tree starting at the given item.TreeReversePostOrderIterable(TItem startItem, ITreeAccessor<TItem,TIdentifier> treeAccessor, boolean limitRecursion)
Returns a new iterable over the items in the tree starting at the given item.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Iterator<TItem>
iterator()
static <TItem> List<TItem>
toList(TItem startItem, ITreeAccessor<TItem,?> treeAccessor)
Iterates over the node and its children, and returns a list of all iterated nodes.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
TreeReversePostOrderIterable
public TreeReversePostOrderIterable(Iterable<TItem> startItems, ITreeAccessor<TItem,TIdentifier> treeAccessor)
Returns a new iterable over the items in the tree starting at the given item.- Parameters:
startItems
- Root items where to start the traversal. These items are included in the traversal.treeAccessor
- Handler for accessing the children of a node, and its identifier
-
TreeReversePostOrderIterable
public TreeReversePostOrderIterable(Iterable<TItem> startItems, ITreeAccessor<TItem,TIdentifier> treeAccessor, boolean limitRecursion)
Returns a new iterable over the items in the tree starting at the given item.- Parameters:
startItems
- Root items where to start the traversal. These items are included in the traversal.treeAccessor
- Handler for accessing the children of a node, and its identifierlimitRecursion
- Iftrue
, stops iterating when an item is encountered for the second time (as determined byObject.hashCode()
,Object.equals(Object)
) and throws anIllegalStateException
.
-
TreeReversePostOrderIterable
public TreeReversePostOrderIterable(TItem startItem, ITreeAccessor<TItem,TIdentifier> treeAccessor)
Returns a new iterable over the items in the tree starting at the given item.- Parameters:
startItem
- Item where to start the traversal. This item is included in the traversal.treeAccessor
- Handler for accessing the children of a node, and its identifier
-
TreeReversePostOrderIterable
public TreeReversePostOrderIterable(TItem startItem, ITreeAccessor<TItem,TIdentifier> treeAccessor, boolean limitRecursion)
Returns a new iterable over the items in the tree starting at the given item.- Parameters:
startItem
- Item where to start the traversal. This item is included in the traversal.treeAccessor
- Handler for accessing the children of a node, and its identifierlimitRecursion
- Iftrue
, stops iterating when an item is encountered for the second time (as determined byObject.hashCode()
,Object.equals(Object)
) and throws anIllegalStateException
.
-
-
Method Detail
-
toList
public static <TItem> List<TItem> toList(TItem startItem, ITreeAccessor<TItem,?> treeAccessor)
Iterates over the node and its children, and returns a list of all iterated nodes.- Type Parameters:
TItem
- Type of the items in the tree.- Parameters:
startItem
- Node where to start the traversal. This item is included in the returned list.treeAccessor
- Handler for accessing the children of a node, and its identifier.- Returns:
- A list with the given start item and all its children.
-
-