NodeItem::findChild: improved Optional idiom

This commit is contained in:
Paul Campbell 2016-09-20 22:26:49 +01:00
parent 753b37cc1d
commit 77a7946e9c

View file

@ -214,12 +214,9 @@ class NodeItem<T> implements Node<T> {
@Override
public Optional<Node<T>> findChild(@NonNull final T child) {
return children.stream()
.filter(node -> {
final Optional<T> d = node.getData();
return d.isPresent() && d.get()
.equals(child);
})
.findAny();
.filter(node -> child.equals(node.getData()
.orElseGet(() -> null)))
.findFirst();
}
@Override