{Abstract}NodeItem: reduce complexity of findInPath()

This commit is contained in:
Paul Campbell 2016-09-13 22:47:41 +01:00
parent afdaa082cc
commit 62d9d28fe1
2 changed files with 6 additions and 16 deletions

View file

@ -139,14 +139,9 @@ abstract class AbstractNodeItem<T> implements Node<T> {
return Optional.empty();
}
Node<T> current = this;
for (T item : path) {
final Optional<Node<T>> child = current.findChild(item);
if (child.isPresent()) {
current = child.get();
} else {
current = null;
break;
}
for (int i = 0, pathSize = path.size(); i < pathSize && current != null; i++) {
current = current.findChild(path.get(i))
.orElse(null);
}
return Optional.ofNullable(current);
}

View file

@ -283,14 +283,9 @@ class NodeItem<T> implements Node<T> {
return Optional.empty();
}
Node<T> current = this;
for (T item : path) {
final Optional<Node<T>> child = current.findChild(item);
if (child.isPresent()) {
current = child.get();
} else {
current = null;
break;
}
for (int i = 0, pathSize = path.size(); i < pathSize && current != null; i++) {
current = current.findChild(path.get(i))
.orElse(null);
}
return Optional.ofNullable(current);
}