From 77a7946e9c9b4d652037334248665d9c6289d2cb Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 20 Sep 2016 22:26:49 +0100 Subject: [PATCH] NodeItem::findChild: improved Optional idiom --- src/main/java/net/kemitix/node/NodeItem.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/kemitix/node/NodeItem.java b/src/main/java/net/kemitix/node/NodeItem.java index a0c330d..f4f69b6 100644 --- a/src/main/java/net/kemitix/node/NodeItem.java +++ b/src/main/java/net/kemitix/node/NodeItem.java @@ -214,12 +214,9 @@ class NodeItem implements Node { @Override public Optional> findChild(@NonNull final T child) { return children.stream() - .filter(node -> { - final Optional d = node.getData(); - return d.isPresent() && d.get() - .equals(child); - }) - .findAny(); + .filter(node -> child.equals(node.getData() + .orElseGet(() -> null))) + .findFirst(); } @Override