Set<Integer> (int startNode, boolean isUp, Condition<? super Integer> stopFunction) { Set<Integer> walkNodes = new HashSet<>(); TreeSetNodeIterator walker = new TreeSetNodeIterator(startNode, isUp); while (walker.notEmpty()) { Integer next = walker.pop(); if (!stopFunction.value(next)) { walkNodes.add(next); walker.addAll(getNodes(next, isUp)); } } return walkNodes; }