boolean (@NotNull JTree tree, @NotNull TreePath parent, @NotNull Predicate<? super TreePath> predicate, @NotNull Consumer<? super TreePath[]> consumer) { ArrayList<TreePath> list = new ArrayList<>(); testDescendants(tree, parent, child -> { if (predicate.test(child)) list.add(child); return true; // visit all descendants }); if (list.isEmpty()) return false; // selection is not changed consumer.accept(toTreePathArray(list)); return true; }