{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();
|
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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue