int (final List<String> side, final boolean canMismatch) { int distance = 0; if (myOffsetIdxInHunk > 0) { int linesIdx = myIdx - 1; int i = myOffsetIdxInHunk - 1; for (; i >= 0 && linesIdx >= 0; i--, linesIdx--) { if (! myLines.get(linesIdx).equals(side.get(i))) { break; } } // since ok -> === -1 i += 1; if (i > 0 && ! canMismatch) return i; // don't go too deep if we need just == or > 0 distance = i; } int linesEndIdx = myIdx; int j = myOffsetIdxInHunk; for (; j < side.size() && linesEndIdx < myLines.size(); j++, linesEndIdx++) { if (! myLines.get(linesEndIdx).equals(side.get(j))) { break; } } distance += side.size() - j; return distance; }