}
}
} else {
if (nextSize <= nextPosition) {
// all next items are scanned, but prev items are remaining
patches.add(new RemoveChild(context, prev.items.get(prevPosition++)));
} else {
// prev and next items are remaining
VirtualNode prevItem = prev.items.get(prevPosition);
VirtualNode nextItem = next.items.get(nextPosition);
if (prevItem.id == nextItem.id) {
// same item
if (prevItem instanceof VirtualElement) {
VirtualElement prevElement = (VirtualElement) prevItem;
VirtualElement nextElement = (VirtualElement) nextItem;
patches.addAll(diff(prevElement, nextElement));
} else {
/**
* {@link VirtualNode#dom}
* <p>
* We passes the Real DOM from the previous Virtual DOM to the next
* Virtual DOM. To tell the truth, we don't want to manipulate Real DOM
* in here. But here is the best place to pass the reference.
* </p>
*/
nextItem.dom = prevItem.dom;
}
actualManipulationPosition++;
prevPosition++;
nextPosition++;
} else {
// different item
int nextItemInPrev = prev.indexOf(nextItem);
int prevItemInNext = next.indexOf(prevItem);
if (nextItemInPrev == -1) {
if (prevItemInNext == -1) {
if (prevItem instanceof VirtualText && nextItem instanceof VirtualText) {
nextItem.dom = prevItem.dom;
patches.add(new ReplaceText(prevItem, (VirtualText) nextItem));
} else {
patches.add(new ReplaceChild(context, prevItem, nextItem));
}
prevPosition++;
} else {
patches.add(new InsertChild(context, prevItem.dom, nextItem));
}
nextPosition++;
actualManipulationPosition++;
} else {
if (prevItemInNext == -1) {
patches.add(new RemoveChild(context, prevItem));
} else {
// both items are found in each other list
// hold and skip the current value
actualManipulationPosition++;
}