Node: streamParents(): added
This commit is contained in:
parent
2d7417afc2
commit
c772e90d68
2 changed files with 13 additions and 0 deletions
|
@ -250,4 +250,11 @@ public interface Node<T> {
|
||||||
* @return a stream of all the nodes in the tree below this node
|
* @return a stream of all the nodes in the tree below this node
|
||||||
*/
|
*/
|
||||||
Stream<Node<T>> streamAll();
|
Stream<Node<T>> streamAll();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a stream of all the node's ancestor nodes.
|
||||||
|
*
|
||||||
|
* @return a stream of the node's parents recursively until the root node
|
||||||
|
*/
|
||||||
|
Stream<Node<T>> streamParents();
|
||||||
}
|
}
|
||||||
|
|
|
@ -375,4 +375,10 @@ class NodeItem<T> implements Node<T> {
|
||||||
return Stream.concat(Stream.of(this), getChildren().stream()
|
return Stream.concat(Stream.of(this), getChildren().stream()
|
||||||
.flatMap(Node::streamAll));
|
.flatMap(Node::streamAll));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Stream<Node<T>> streamParents() {
|
||||||
|
return getParent().map(node -> Stream.concat(Stream.of(node), node.streamParents()))
|
||||||
|
.orElseGet(Stream::empty);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue