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