void (IntFunction<Object> function, int min, int max, List<TreePath> list, TreePath path) { if (path == null) path = new TreePath(function.apply(0)); // create path to root node int count = path.getPathCount(); if (min <= count) list.add(path); if (max <= count) return; for (int i = 0; i <= count; i++) { addPaths(function, min, max, list, path.pathByAddingChild(function.apply(i))); } }