int (int increment) { List<Place> places = new ArrayList<>(); int first; synchronized (this) { first = myCurrentPos + increment; for (int idx = first; idx >= 0 && idx < myHistory.size(); idx += increment) { places.add(myHistory.get(idx)); } } int index = ContainerUtil.indexOf(places, place -> myRoot.isValid(place)); return index == -1 ? -1 : first + index * increment; }