Package de.xima.fc.common.tree
Class TreeParentIterable<Node,Id>
- java.lang.Object
 - 
- de.xima.fc.common.tree.TreeParentIterable<Node,Id>
 
 
- 
- Type Parameters:
 Node- Type of the items in the tree.Id- Type of the identifier that identifiers the items in the tree.
- All Implemented Interfaces:
 Iterable<Node>
public final class TreeParentIterable<Node,Id> extends Object implements Iterable<Node>
An iterable that iterates over a tree-like graph, starting at a given node, and accessing each parent. 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 TreeParentIterable(Node startItem, boolean includeStartItem, ITreeParentAccessor<Node,Id> treeAccessor)Returns a new iterable over the parents in the tree, starting at the given item.TreeParentIterable(Node startItem, ITreeParentAccessor<Node,Id> treeAccessor)Returns a new iterable over the parents in the tree, starting at the given item. 
- 
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <Node> NodeclosestParentExcludingStart(Node startItem, ITreeParentAccessor<Node,?> treeAccessor, Predicate<? super Node> filter)Finds the closest parent of the given item that matches the given filter.static <Node> NodeclosestParentIncludingStart(Node startItem, ITreeParentAccessor<Node,?> treeAccessor, Predicate<? super Node> filter)Finds the closest parent of the given item that matches the given filter.Iterator<Node>iterator()static <Node> List<Node>toList(Node startItem, boolean includeStartItem, ITreeParentAccessor<Node,?> treeAccessor)Iterates over the node and its parents, and returns a list of all iterated nodes.static <Node> Set<Node>toSet(Node startItem, boolean includeStartItem, ITreeParentAccessor<Node,?> treeAccessor)Iterates over the node and its parents, and returns a set 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
- 
TreeParentIterable
public TreeParentIterable(Node startItem, boolean includeStartItem, ITreeParentAccessor<Node,Id> treeAccessor)
Returns a new iterable over the parents in the tree, starting at the given item.- Parameters:
 startItem- Child item where to start the traversal.includeStartItem- Whether to include the start item in the iteration.treeAccessor- Handler for accessing the parent of a node and its ID.
 
- 
TreeParentIterable
public TreeParentIterable(Node startItem, ITreeParentAccessor<Node,Id> treeAccessor)
Returns a new iterable over the parents in the tree, starting at the given item.- Parameters:
 startItem- Child item where to start the traversal. This item is inluded in the traversal.treeAccessor- Handler for accessing the parent of a node and its ID.
 
 - 
 
- 
Method Detail
- 
closestParentExcludingStart
public static <Node> Node closestParentExcludingStart(Node startItem, ITreeParentAccessor<Node,?> treeAccessor, Predicate<? super Node> filter)Finds the closest parent of the given item that matches the given filter. Does not include the start node in the list of candidates. A null filter is treated as no filter, i.e. so this method returns the first parent.- Type Parameters:
 Node- Type of the items in the tree.- Parameters:
 startItem- Node where to start the traversal.treeAccessor- Handler for accessing the parent of a node, and its identifier.filter- Predicate to filter the nodes.- Returns:
 - The closest parent of the given item that matches the given filter. null if no such parent exists.
 
 
- 
closestParentIncludingStart
public static <Node> Node closestParentIncludingStart(Node startItem, ITreeParentAccessor<Node,?> treeAccessor, Predicate<? super Node> filter)Finds the closest parent of the given item that matches the given filter. Include the start node in the list of candidates. A null filter is treated as no filter, i.e. this method returns the start node itself.- Type Parameters:
 Node- Type of the items in the tree.- Parameters:
 startItem- Node where to start the traversal.treeAccessor- Handler for accessing the parent of a node, and its identifier.filter- Predicate to filter the nodes.- Returns:
 - The closest parent of the given item that matches the given filter. null if no such parent exists.
 
 
- 
toList
public static <Node> List<Node> toList(Node startItem, boolean includeStartItem, ITreeParentAccessor<Node,?> treeAccessor)
Iterates over the node and its parents, and returns a list of all iterated nodes.- Type Parameters:
 Node- Type of the items in the tree.- Parameters:
 startItem- Node where to start the traversal. This item is included in the returned list.includeStartItem- Whether to include the start item in the iteration.treeAccessor- Handler for accessing the parent of a node, and its identifier.- Returns:
 - A list with the given start item and all its parents.
 
 
- 
toSet
public static <Node> Set<Node> toSet(Node startItem, boolean includeStartItem, ITreeParentAccessor<Node,?> treeAccessor)
Iterates over the node and its parents, and returns a set of all iterated nodes.- Type Parameters:
 Node- Type of the items in the tree.- Parameters:
 startItem- Node where to start the traversal. This item is included in the returned list.includeStartItem- Whether to include the start item in the iteration.treeAccessor- Handler for accessing the parent of a node, and its identifier.- Returns:
 - A set with the given start item and all its parents.
 
 
 - 
 
 -