Iterator<Alignment> rightIterator = rightAlignmentList.iterator();
int leftSourceCharNr = 0;
int leftTargetCharNr = 0;
int rightSourceCharNr = 0;
int rightTargetCharNr = 0;
Alignment leftAlignment = null;
Alignment rightAlignment = null;
String leftMergedSourceSegment = null;
String leftMergedTargetSegment = null;
String rightMergedSourceSegment = null;
String rightMergedTargetSegment = null;
while(leftIterator.hasNext() && rightIterator.hasNext()) {
//Przechodzi po obu tylko jeśli source i target są równe.
//W przeciwnym wypadku przechodzi po tym co ma mniejsze source
//a gdy są równe to target.
boolean moveLeft = (leftSourceCharNr < rightSourceCharNr) ||
(leftSourceCharNr == rightSourceCharNr &&
leftTargetCharNr <= rightTargetCharNr);
boolean moveRight = (leftSourceCharNr > rightSourceCharNr) ||
(leftSourceCharNr == rightSourceCharNr &&
leftTargetCharNr >= rightTargetCharNr);
if (moveLeft) {
leftAlignment = leftIterator.next();
leftMergedSourceSegment =
merger.merge(leftAlignment.getSourceSegmentList());
leftMergedTargetSegment =
merger.merge(leftAlignment.getTargetSegmentList());
leftSourceCharNr += leftMergedSourceSegment.length();
leftTargetCharNr += leftMergedTargetSegment.length();
}
if (moveRight) {
rightAlignment = rightIterator.next();
rightMergedSourceSegment =
merger.merge(rightAlignment.getSourceSegmentList());
rightMergedTargetSegment =
merger.merge(rightAlignment.getTargetSegmentList());
rightSourceCharNr += rightMergedSourceSegment.length();
rightTargetCharNr += rightMergedTargetSegment.length();
}
if ((leftMergedSourceSegment.equals(rightMergedSourceSegment)) &&
(leftMergedTargetSegment.equals(rightMergedTargetSegment))) {