{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(); return Optional.empty();
} }
Node<T> current = this; Node<T> current = this;
for (T item : path) { for (int i = 0, pathSize = path.size(); i < pathSize && current != null; i++) {
final Optional<Node<T>> child = current.findChild(item); current = current.findChild(path.get(i))
if (child.isPresent()) { .orElse(null);
current = child.get();
} else {
current = null;
break;
}
} }
return Optional.ofNullable(current); return Optional.ofNullable(current);
} }

View file

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