diff --git a/src/main/java/net/kemitix/node/AbstractNodeItem.java b/src/main/java/net/kemitix/node/AbstractNodeItem.java index 3097d4a..1fe6eab 100644 --- a/src/main/java/net/kemitix/node/AbstractNodeItem.java +++ b/src/main/java/net/kemitix/node/AbstractNodeItem.java @@ -105,14 +105,17 @@ abstract class AbstractNodeItem implements Node { if (path.isEmpty()) { return Optional.empty(); } - Optional> found = findChild(path.get(0)); - if (found.isPresent()) { - if (path.size() > 1) { - return found.get().findInPath(path.subList(1, path.size())); + Node current = this; + for (T item : path) { + final Optional> child = current.findChild(item); + if (child.isPresent()) { + current = child.get(); + } else { + current = null; + break; } - return found; } - return Optional.empty(); + return Optional.ofNullable(current); } @Override diff --git a/src/main/java/net/kemitix/node/NodeItem.java b/src/main/java/net/kemitix/node/NodeItem.java index 2ed9b02..519867f 100644 --- a/src/main/java/net/kemitix/node/NodeItem.java +++ b/src/main/java/net/kemitix/node/NodeItem.java @@ -263,14 +263,17 @@ class NodeItem implements Node { if (path.isEmpty()) { return Optional.empty(); } - Optional> found = findChild(path.get(0)); - if (found.isPresent()) { - if (path.size() > 1) { - return found.get().findInPath(path.subList(1, path.size())); + Node current = this; + for (T item : path) { + final Optional> child = current.findChild(item); + if (child.isPresent()) { + current = child.get(); + } else { + current = null; + break; } - return found; } - return Optional.empty(); + return Optional.ofNullable(current); } @Override