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; return;
} }
String item = path[0]; val item = path[0];
final Optional<Node<T>> childNamed = findChildByName(item); findChildByName(item)
Node<T> child; .orElseGet(() -> new NodeItem<>(null, item, this))
if (!childNamed.isPresent()) { .insertInPath(nodeItem, Arrays.copyOfRange(path, 1, path.length));
child = new NodeItem<>(null, item, this);
} else {
child = childNamed.get();
}
child.insertInPath(nodeItem, Arrays.copyOfRange(path, 1, path.length));
} }
@Override @Override