/*
* First step, build the bridge from the intended revision to the latest revision by composing
* all of the doc ops between these ranges. This bridge will be used to update a client doc op
* that's intended to be applied to a document in the past.
*/
DocOp bridgeDocOp = null;
int bridgeBeginIndex = intendedCcRevision + 1;
int bridgeEndIndexInclusive = ccRevision;
for (int i = bridgeBeginIndex; i <= bridgeEndIndexInclusive; i++) {
DocOp curDocOp = docOpHistory.get(i).docOp;
try {
bridgeDocOp = bridgeDocOp == null ? curDocOp : Composer.compose(
ServerDocOpFactory.INSTANCE, bridgeDocOp, curDocOp);
} catch (ComposeException e) {
throw newExceptionForConsumeWithoutLocking("Could not build bridge",
e,
intendedCcRevision,
bridgeBeginIndex,
bridgeEndIndexInclusive,
docOps);
}
}
/*
* Second step, iterate through doc ops from the client and transform each against the bridge.
* Take the server op result of the transformation and make that the new bridge. Record each
* into our map that will be returned to the caller of this method.
*/
SortedMap<Integer, AppliedDocOp> appliedDocOps = new TreeMap<Integer, AppliedDocOp>();
for (int i = 0, n = docOps.size(); i < n; i++) {
DocOp clientDocOp = docOps.get(i);
if (bridgeDocOp != null) {
try {
OperationPair transformedPair =
Transformer.transform(ServerDocOpFactory.INSTANCE, clientDocOp, bridgeDocOp);