/** * Computes the cost of the given document. */ public int computeCost(DocInitialization doc) { final int[] accu = { 0 }; doc.apply(new DocInitializationCursor() { @Override public void annotationBoundary(AnnotationBoundaryMap map) { accu[0] += objectOverhead + computeCost(map); } @Override public void characters(String chars) { accu[0] += objectOverhead + computeCost(chars); } @Override public void elementStart(String type, Attributes attrs) { accu[0] += objectOverhead + computeCost(type) + computeCost(attrs); } @Override public void elementEnd() { accu[0] += objectOverhead; } }); return accu[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++; } }
final int numDocComponents = exploded.size();
op.apply(new DocInitializationCursor() { Map<String, String> currentAnnotations = new HashMap<String, String>(); TreeMap<String, String> changes = new TreeMap<String, String>();
@Override public DocInitialization asOperation() { DocInitializationBuffer builder = new DocInitializationBuffer(); document.asOperation().apply(builder); return builder.finish(); }
/** * Creates a <code>SchemaPattern</code> from its representation as a * <code>DocInitialization</code>. * * @param schemaDescription the schema represented as a * <code>DocInitialization</code> * @return the constructed <code>SchemaPattern</code> * @throws InvalidSchemaException if the given <code>DocInitialization</code> * does not represent a valid schema */ public static SchemaPattern createSchemaPattern(DocInitialization schemaDescription) throws InvalidSchemaException { SchemaBuilder builder = new SchemaBuilder(); try { schemaDescription.apply(builder); } catch (BoxedSchemaException e) { throw e.unbox(); } return builder.buildSchema(); }
/** Creates an op that restores the doc's current state. */ private DocOp createRestoreOp() { UncheckedDocOpBuffer builder = new UncheckedDocOpBuffer(); doc.toInitialization().apply(builder); return builder.finish(); }
@Override public DocOp asOperation(BootstrapDocument state) { EvaluatingDocOpCursor<DocOp> builder = new DocOpBuffer(); state.asOperation().apply(builder); return builder.finish(); }
@Override public DocOp asOperation(BootstrapDocument state) { EvaluatingDocOpCursor<DocOp> builder = new DocOpBuffer(); state.asOperation().apply(builder); return builder.finish(); }
/** Creates an op that restores the doc's current state. */ private DocOp createRestoreOp() { UncheckedDocOpBuffer builder = new UncheckedDocOpBuffer(); doc.toInitialization().apply(builder); return builder.finish(); }
public static DocInitialization normalize(DocInitialization in) { EvaluatingDocOpCursor<DocOp> n = new AnnotationsNormalizer<DocOp>( new RangeNormalizer<DocOp>(new DocOpBuffer())); in.apply(n); return asInitialization(n.finish()); }
/** Creates an op that deletes the doc's current state. */ private DocOp createErasureOp() { UncheckedDocOpBuffer builder = new UncheckedDocOpBuffer(); doc.toInitialization().apply(builder); return DocOpInverter.invert(builder.finish()); }
/** Creates an op that deletes the doc's current state. */ private DocOp createErasureOp() { UncheckedDocOpBuffer builder = new UncheckedDocOpBuffer(); doc.toInitialization().apply(builder); return DocOpInverter.invert(builder.finish()); }
private void restore(Document doc) { // No comment. UncheckedDocOpBuffer builder = new UncheckedDocOpBuffer(); doc.toInitialization().apply(builder); DocOp state = builder.finish(); DocOp erasure = DocOpInverter.invert(state); DocOp restoration; try { restoration = Composer.compose(erasure, state); } catch (OperationException e) { // If the code above fails, then there is a bug in the operation code, not // these tests. Fail with an exception, not with a JUnit fail(). throw new RuntimeException(e); } doc.hackConsume(Nindo.fromDocOp(restoration, false)); } }
private void restore(Document doc) { // No comment. UncheckedDocOpBuffer builder = new UncheckedDocOpBuffer(); doc.toInitialization().apply(builder); DocOp state = builder.finish(); DocOp erasure = DocOpInverter.invert(state); DocOp restoration; try { restoration = Composer.compose(erasure, state); } catch (OperationException e) { // If the code above fails, then there is a bug in the operation code, not // these tests. Fail with an exception, not with a JUnit fail(). throw new RuntimeException(e); } doc.hackConsume(Nindo.fromDocOp(restoration, false)); } }
if (testAsOperation) { for (IsDocOp d : docs) { d.asOperation().apply(new DocOpBuffer());
if (testAsOperation) { for (IsDocOp d : docs) { d.asOperation().apply(new DocOpBuffer());