final DocInitialization exploded = ExplodedDocOp.explode(doc);
final int numDocComponents = exploded.size();
final DocOpCursor opStringifier = createConciseStringBuilder(op, opB);
final DocInitializationBuffer target = new DocInitializationBuffer();
new Runnable() {
int index = 0;
int docItem = 0;
private void runTarget(int itemCount) {
indicesB.append(docItem);
docItem += itemCount;
while (index < numDocComponents && itemCount > 0) {
exploded.applyComponent(index, target);
if (exploded.getType(index) != DocOpComponentType.ANNOTATION_BOUNDARY) {
itemCount--;
}
index++;
}
}
private void matchUp() {
int max = 0;
for (StringBuilder b : builders) {
max = Math.max(max, b.length());
}
for (StringBuilder b : builders) {
while (b.length() < max) {
b.append(' ');
}
}
}
@Override
public void run() {
op.apply(new DocOpCursor() {
@Override
public void deleteCharacters(String chars) {
opStringifier.deleteCharacters(chars);
runTarget(chars.length());
matchUp();
}
@Override
public void deleteElementEnd() {
opStringifier.deleteElementEnd();
runTarget(1);
matchUp();
}
@Override
public void deleteElementStart(String type, Attributes attrs) {
opStringifier.deleteElementStart(type, attrs);
runTarget(1);
matchUp();
}
@Override
public void replaceAttributes(Attributes oldAttrs, Attributes newAttrs) {
opStringifier.replaceAttributes(oldAttrs, newAttrs);
runTarget(1);
matchUp();
}
@Override
public void retain(int itemCount) {
opStringifier.retain(itemCount);
runTarget(itemCount);
matchUp();
}
@Override
public void updateAttributes(AttributesUpdate attrUpdate) {
opStringifier.updateAttributes(attrUpdate);
runTarget(1);
matchUp();
}
@Override
public void annotationBoundary(AnnotationBoundaryMap map) {
opStringifier.annotationBoundary(map);
matchUp();
}
@Override
public void characters(String chars) {
opStringifier.characters(chars);
matchUp();
}
@Override
public void elementEnd() {
opStringifier.elementEnd();
matchUp();
}
@Override
public void elementStart(String type, Attributes attrs) {
opStringifier.elementStart(type, attrs);
}
});
runTarget(1);
}