FragmentResult (final int lineInTheMiddle, final int offsetInStep, final BeforeAfter<List<String>> step, final boolean inBefore) { final List<String> lines = inBefore ? step.getBefore() : step.getAfter(); final List<String> start = lines.subList(0, offsetInStep); int startDistance = 0; if (! start.isEmpty()) { if (lineInTheMiddle - 1 < 0) { startDistance = start.size(); } else { startDistance = getDistanceBack(lineInTheMiddle - 1, start); } } final List<String> end = lines.subList(offsetInStep, lines.size()); int endDistance = 0; if (! end.isEmpty()) { endDistance = getDistance(lineInTheMiddle, end); } final FragmentResult fragmentResult = new FragmentResult(lineInTheMiddle - (start.size() - startDistance), lineInTheMiddle + (end.size() - endDistance) - 1, !inBefore); fragmentResult.addDistance(startDistance + endDistance); fragmentResult.setStartAtEdge(startDistance == 0); fragmentResult.setEndAtEdge(endDistance == 0); return fragmentResult; }