UpdatedLineRange (int start, int end, int changeStart, int changeEnd, int shift, boolean greedy) { if (end <= changeStart) { // change before return new UpdatedLineRange(start, end, false); } if (start >= changeEnd) { // change after return new UpdatedLineRange(start + shift, end + shift, false); } if (start <= changeStart && end >= changeEnd) { // change inside return new UpdatedLineRange(start, end + shift, false); } // range is damaged. We don't know new boundaries. // But we can try to return approximate new position int newChangeEnd = changeEnd + shift; if (start >= changeStart && end <= changeEnd) { // fully inside change return greedy ? new UpdatedLineRange(changeStart, newChangeEnd, true) : new UpdatedLineRange(newChangeEnd, newChangeEnd, true); } if (start < changeStart) { // bottom boundary damaged return greedy ? new UpdatedLineRange(start, newChangeEnd, true) : new UpdatedLineRange(start, changeStart, true); } else { // top boundary damaged return greedy ? new UpdatedLineRange(changeStart, end + shift, true) : new UpdatedLineRange(newChangeEnd, end + shift, true); } }