void (final List<? extends BeforeAfter<List<String>>> steps) { final Consumer<BeforeAfter<List<String>>> stepConsumer = listBeforeAfter -> { if (myDistance == 0) { // until this point, it all had being doing well if (listBeforeAfter.getBefore().isEmpty()) { // just take it return; } final FragmentMatcher fragmentMatcher = new FragmentMatcher(myIdx, listBeforeAfter); final Pair<Integer, Boolean> pair = fragmentMatcher.find(true); myDistance = pair.getFirst(); if (myDistance == 0) { myIdx += pair.getSecond() ? listBeforeAfter.getBefore().size() : listBeforeAfter.getAfter().size(); } else { myIdx += (pair.getSecond() ? listBeforeAfter.getBefore().size() : listBeforeAfter.getAfter().size()) - pair.getFirst(); } myUsesAlreadyApplied = !pair.getSecond(); } else { // we just count the distance myDistance += listBeforeAfter.getBefore().size(); } }; if (myForward) { for (BeforeAfter<List<String>> step : steps) { stepConsumer.consume(step); } } else { for (int i = steps.size() - 1; i >= 0; i--) { BeforeAfter<List<String>> step = steps.get(i); stepConsumer.consume(step); } } }