diff --git a/src/main/java/net/kemitix/node/AbstractNodeItem.java b/src/main/java/net/kemitix/node/AbstractNodeItem.java index 7954f1d..5f6e5d5 100644 --- a/src/main/java/net/kemitix/node/AbstractNodeItem.java +++ b/src/main/java/net/kemitix/node/AbstractNodeItem.java @@ -139,14 +139,9 @@ abstract class AbstractNodeItem implements Node { return Optional.empty(); } Node current = this; - for (T item : path) { - final Optional> 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); } diff --git a/src/main/java/net/kemitix/node/NodeItem.java b/src/main/java/net/kemitix/node/NodeItem.java index 5afea63..0e92dfb 100644 --- a/src/main/java/net/kemitix/node/NodeItem.java +++ b/src/main/java/net/kemitix/node/NodeItem.java @@ -283,14 +283,9 @@ class NodeItem implements Node { return Optional.empty(); } Node current = this; - for (T item : path) { - final Optional> 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); }