private DocOp composeOperations(DocOp op1, DocOp op2) throws OperationException { target = defaultTarget; int op1Index = 0; int op2Index = 0; while (op1Index < op1.size()) { op1.applyComponent(op1Index++, target); while (target.isPostTarget()) { if (op2Index >= op2.size()) { throw new OperationException( "Document size mismatch: " + "op1 resulting length=" + DocOpUtil.resultingDocumentLength(op1) + ", op2 initial length=" + DocOpUtil.initialDocumentLength(op2)); } op2.applyComponent(op2Index++, target); } } if (op2Index < op2.size()) { target = new FinisherPostTarget(); while (op2Index < op2.size()) { op2.applyComponent(op2Index++, target); } } flushAnnotations(); return normalizer.finish(); }
@Override public void annotationBoundary(AnnotationBoundaryMap map) { cache.flush(); target.annotationBoundary(map); }
@Override public void updateAttributes(AttributesUpdate attrUpdate) { cache.flush(); target.updateAttributes(attrUpdate); }
@Override public void replaceAttributes(Attributes oldAttrs, Attributes newAttrs) { cache.flush(); target.replaceAttributes(oldAttrs, newAttrs); }
@Override public void deleteElementEnd() { cache.flush(); target.deleteElementEnd(); }
@Override public void deleteElementStart(String type, Attributes attrs) { cache.flush(); target.deleteElementStart(type, attrs); }
@Override public T finish() { cache.flush(); return target.finish(); }