int toBeRemoved = 0; // number of events to be removed from the end
int counter = 0; // number of events evaluated
int pos1 = this.sequence1.size() - 1; // current position of the first sequence
int pos2 = this.sequence2.size() - 1; // current position of the second sequence
while (pos1 >= 0 && pos2 >= 0) {
DiffXEvent e1 = this.sequence1.getEvent(pos1);
if (e1.equals(this.sequence2.getEvent(pos2))) {
counter++;
// increase the depth for close, decrease for open
if (e1 instanceof CloseElementEvent) {
depth++;
} else if (e1 instanceof OpenElementEvent) {
depth--;
}
// if depth = 1, it is a direct child of the document element,
// so we can cut off the whole branch
if (depth == 1 || depth == 0) {
toBeRemoved = counter;
}
pos1--; pos2--;
} else {
break;
}
}
// slice the end of the first sequence
int downTo = this.sequence1.size() - toBeRemoved;
for (int k = this.sequence1.size() - 1; k >= downTo; k--) {
DiffXEvent e = this.sequence1.removeEvent(k);
this.end.addEvent(0, e);
}
// slice the end of the second sequence
downTo = this.sequence2.size() - toBeRemoved;
for (int k = this.sequence2.size() - 1; k >= downTo; k--) {