{Abstract}NodeItem: reduce complexity of findInPath()
This commit is contained in:
parent
afdaa082cc
commit
62d9d28fe1
2 changed files with 6 additions and 16 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue