public class TreeStreams extends Object
Unless otherwise noted all streams are ordered
and sequential. They are generated lazily,
i.e. the TreeNavigator
is only used to find nodes which are known to be processed by the stream. This is
implies that short-circuiting operation (like limit
) will lead to the evaluation of less
nodes.
The streams are only defined on trees, i.e. connected, directed, acyclic graphs. Creating them on other graphs can lead to unexpected behavior including infinite streams.
Constructor and Description |
---|
TreeStreams() |
Modifier and Type | Method and Description |
---|---|
static <N> Stream<N> |
backwardDfs(TreeNavigator<N> navigator,
N startNode)
Returns a stream which enumerates nodes in a tree in the order of a backwards depth-first search which starts in the specified
node.
|
static <N> Stream<N> |
backwardDfsToRoot(TreeNavigator<N> navigator,
N root,
N startNode)
Returns a stream which enumerates nodes in the (sub-)tree rooted in the specified root in the order of a
backwards depth-first search which starts
in the specified node.
|
static <N> Stream<N> |
byStrategy(TreeIterationStrategy<N> strategy)
Returns a stream which enumerates a tree's nodes according to the specified
TreeIterationStrategy . |
static <N> Stream<N> |
byStrategy(TreeIterationStrategy<N> strategy,
int characteristics,
boolean parallel)
Returns a stream which enumerates a tree's nodes according to the specified
TreeIterationStrategy and
stream characteristics. |
static <N> Stream<N> |
dfsFromRoot(TreeNavigator<N> navigator,
N root)
Returns a stream which enumerates nodes in the (sub-)tree rooted in the specified root in the order of a depth-first search.
|
static <N> Stream<N> |
dfsFromWithin(TreeNavigator<N> navigator,
N startNode)
Returns a stream which enumerates nodes in a tree in the order of a depth-first search which starts in the specified
node.
|
static <N> Stream<N> |
dfsFromWithin(TreeNavigator<N> navigator,
N root,
N startNode)
Returns a stream which enumerates nodes in the (sub-)tree rooted in the specified root in the order of a depth-first search which starts in the specified
start node.
|
public static <N> Stream<N> dfsFromRoot(TreeNavigator<N> navigator, N root)
It is not necessary for the specified node to be the tree's actual root. It will be treated as the root of a subtree and only this subtree will be streamed.
N
- the type of nodes contained in the treenavigator
- the navigator used to navigate the treeroot
- the root node for the searched (sub-)treepublic static <N> Stream<N> dfsFromWithin(TreeNavigator<N> navigator, N startNode)
While the search will start in the specified node it will eventually backtrack above it, i.e. the search is not limited to the subtree rooted in the node. This is equivalent to starting a full depth-first search in the tree's root but ignoring all encountered nodes until the specified start node is found.
N
- the type of nodes contained in the treenavigator
- the navigator used to navigate the treestartNode
- the node in which the search startspublic static <N> Stream<N> dfsFromWithin(TreeNavigator<N> navigator, N root, N startNode)
This is a combination of dfsFromRoot
and
dfsFromWithin
. Only the (sub-)tree rooted in the specified root is
searched (i.e. the search will never backtrack above it) but the root actually startes in the specified start
node.
N
- the type of nodes contained in the treenavigator
- the navigator used to navigate the treeroot
- the root node for the searched (sub-)treestartNode
- the node in which the search startspublic static <N> Stream<N> backwardDfs(TreeNavigator<N> navigator, N startNode)
The stream enumerates the nodes which would be encountered by starting a depth-first search in the tree's root and stopping at the specified node, but in reverse order.
N
- the type of nodes contained in the treenavigator
- the navigator used to navigate the treestartNode
- the node in which the search startspublic static <N> Stream<N> backwardDfsToRoot(TreeNavigator<N> navigator, N root, N startNode)
The stream enumerates the nodes which would be encountered by starting a depth-first search in the specified root and stopping at the specified node, but in reverse order.
N
- the type of nodes contained in the treenavigator
- the navigator used to navigate the treeroot
- the root node for the searched (sub-)treestartNode
- the node in which the search startspublic static <N> Stream<N> byStrategy(TreeIterationStrategy<N> strategy)
TreeIterationStrategy
.N
- the type of nodes contained in the treestrategy
- the strategy used to enumerate the tree's nodespublic static <N> Stream<N> byStrategy(TreeIterationStrategy<N> strategy, int characteristics, boolean parallel)
TreeIterationStrategy
and
stream characteristics.N
- the type of nodes contained in the treestrategy
- the strategy used to enumerate the tree's nodescharacteristics
- the characteristics of the Spliterator
used to create the streamparallel
- if true then the returned stream is a parallel stream; if false the returned stream is a sequential
stream.This documentation is licensed under CC-BY 4.0, attributed to Nicolai Parlog from CodeFX.