From e28b140db82465965ae188ed3c5274a97847ee04 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sun, 4 Sep 2016 19:28:20 +0100 Subject: [PATCH] NodeItem: simplify inserting child into path --- src/main/java/net/kemitix/node/NodeItem.java | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/main/java/net/kemitix/node/NodeItem.java b/src/main/java/net/kemitix/node/NodeItem.java index 519867f..067ef5e 100644 --- a/src/main/java/net/kemitix/node/NodeItem.java +++ b/src/main/java/net/kemitix/node/NodeItem.java @@ -301,15 +301,10 @@ class NodeItem implements Node { } return; } - String item = path[0]; - final Optional> childNamed = findChildByName(item); - Node child; - if (!childNamed.isPresent()) { - child = new NodeItem<>(null, item, this); - } else { - child = childNamed.get(); - } - child.insertInPath(nodeItem, Arrays.copyOfRange(path, 1, path.length)); + val item = path[0]; + findChildByName(item) + .orElseGet(() -> new NodeItem<>(null, item, this)) + .insertInPath(nodeItem, Arrays.copyOfRange(path, 1, path.length)); } @Override