Set<Integer> (final int upNode, final int downNode, boolean strict) { Set<Integer> downWalk = getWalkNodes(upNode, false, integer -> integer > downNode); Set<Integer> upWalk = getWalkNodes(downNode, true, integer -> integer < upNode); downWalk.retainAll(upWalk); if (strict) { downWalk.remove(upNode); downWalk.remove(downNode); } return downWalk; }