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 @Override
public Optional<Node<T>> findChild(@NonNull final T child) { public Optional<Node<T>> findChild(@NonNull final T child) {
return children.stream() return children.stream()
.filter(node -> { .filter(node -> child.equals(node.getData()
final Optional<T> d = node.getData(); .orElseGet(() -> null)))
return d.isPresent() && d.get() .findFirst();
.equals(child);
})
.findAny();
} }
@Override @Override