Skip to content

Commit

Permalink
Change path-parent resolving to use recursion instead of iteration fo…
Browse files Browse the repository at this point in the history
…r cleaner code
  • Loading branch information
tokee committed Aug 9, 2023
1 parent 7ad6964 commit 9f10dbf
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,9 @@ static Stream<Path> getContainerCandidates(String resource) {
* @return a stream of the path followed by all parents.
*/
private static Stream<Path> allLevels(Path path) {
List<Path> levels = new ArrayList<>();
levels.add(path);
while ((path = path.getParent()) != null) {
levels.add(path);
}
return levels.stream();
return path.getParent() != null ?
Stream.concat(Stream.of(path), allLevels(path.getParent())) :
Stream.of(path);
}

/**
Expand Down

0 comments on commit 9f10dbf

Please sign in to comment.