protected Operation transform(InsertOperation insA, DeleteOperation delB) { int posA = insA.getPosition(); int posB = delB.getPosition(); int lenB = delB.getTextLength(); if (posA <= posB) { /* * Operation A starts before or at the same position like operation */ return insA; } else if (posA > (posB + lenB)) { /* * Operation A starts after operation B. Index of operation A' must * be reduced by the length of the text of operation B. */ return new InsertOperation(posA - lenB, insA.getText(), insA.getOrigin()); } else { /* * Operation A starts in operation B. Index of A' must be the index * of operation B. */ return new InsertOperation(posB, insA.getText(), insA.getOrigin()); } }
protected Operation transform( InsertOperation insA, InsertOperation insB, boolean isTransformPrivileged) { int posA = insA.getPosition(); int posB = insB.getPosition(); int lenB = insB.getTextLength(); if ((posA < posB) || ((posA == posB) && (insA.getOrigin() < insB.getOrigin())) || ((posA == posB) && (insA.getOrigin() == insB.getOrigin()) && isTransformPrivileged)) { /* * Operation A starts before operation B. */ return insA; } else { /* * Operation A starts in or behind operation B. Index of operation * A' must be increased by the length of the text of operation B. */ return new InsertOperation(posA + lenB, insA.getText(), insA.getOrigin()); } }