if (differences.length > 0) {
int diffIndex = 0;
int leftLineCount = leftComparator.getRangeCount();
do {
RangeDifference diff = differences[diffIndex];
if (diff.kind() == RangeDifference.CHANGE) {
int nextChangedLine = diff.leftStart();
// output contextLineCount number of lines (if available) or all lines if contextLineCount == -1
if (pos != 0) { // at start of file, skip immediately to first changes
int beginContextEndPos = pos + config.getLinesBeforeSkip();
while (((pos < beginContextEndPos) || (config.getLinesBeforeSkip() == -1))
&& (pos + MIN_EQUAL_LINES < nextChangedLine)) {
output.startLine(DiffLineType.UNCHANGED);
output.addUnchangedText(leftComparator.getLine(pos));
output.endLine();
pos++;
}
}
// skip a number of lines
if (config.getLinesBeforeSkip() >= 0) {
int endContextStartPos = nextChangedLine - config.getLinesBeforeSkip();
if (endContextStartPos >= pos + MIN_EQUAL_LINES) {
output.skippedLines(endContextStartPos - pos);
pos = endContextStartPos;
}
}
// output contextLineCount number of lines
while (pos < nextChangedLine) {
output.startLine(DiffLineType.UNCHANGED);
output.addUnchangedText(leftComparator.getLine(pos));
output.endLine();
pos++;
}
StringBuffer leftBlock = null;
StringBuffer rightBlock = null;
if ((diff.leftLength() > 0) && (diff.rightLength() > 0)) {
leftBlock = concatLines(leftComparator, diff.leftStart(), diff.leftLength());
rightBlock = concatLines(rightComparator, diff.rightStart(), diff.rightLength());
}
if (leftBlock == null) {
for (int i = 0; i < diff.leftLength(); i++) {
int currentLine = diff.leftStart() + i;
output.startLine(DiffLineType.REMOVED);
output.addUnchangedText(leftComparator.getLine(currentLine));
output.endLine();
}
} else {
diffBlock(leftBlock, rightBlock, output, DiffLineType.REMOVED);
}
if (leftBlock == null) {
for (int i = 0; i < diff.rightLength(); i++) {
int currentLine = diff.rightStart() + i;
output.startLine(DiffLineType.ADDED);
output.addUnchangedText(rightComparator.getLine(currentLine));
output.endLine();
}
} else {