NodeItem: simplify inserting child into path

This commit is contained in:
Paul Campbell 2016-09-04 19:28:20 +01:00
parent 91c57f098e
commit e28b140db8

View file

@ -301,15 +301,10 @@ class NodeItem<T> implements Node<T> {
}
return;
}
String item = path[0];
final Optional<Node<T>> childNamed = findChildByName(item);
Node<T> 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