Package org.waveprotocol.wave.model.document.operation.impl

Examples of org.waveprotocol.wave.model.document.operation.impl.DocOpBuffer


   * Scrubs the given operation. Ill-formed input is permitted but may lead to
   * ill-formed output. Invalid characters will be clearly noted.
   */
  public static DocOp scrub(final DocOp op) {
    try {
      DocOpBuffer b = new DocOpBuffer();
      op.apply(createScrubber(b));
      return b.finishUnchecked();
    } catch (RuntimeException e) {
      // This should not really happen unless perhaps the input operation has some
      // diabolically broken implementation of apply ofr of attribute or annotation datastructures.
      return new DocOpBuilder().characters("Scrub exploded: " + e).build();
    }
View Full Code Here


  public void testNullable() {
    OpEquator eq = OpComparators.SYNTACTIC_IDENTITY;

    assertTrue(eq.equalNullable((DocOp) null, null));
    assertFalse(eq.equalNullable(null, new DocOpBuffer().finish()));
    assertFalse(eq.equalNullable(new DocOpBuffer().finish(), null));

    try {
      eq.equal(new DocOpBuffer().finish(), null);
      fail();
    } catch (NullPointerException e) {
      // ok
    }

    try {
      eq.equal(null, new DocOpBuffer().finish());
      fail();
    } catch (NullPointerException e) {
      // ok
    }
  }
View Full Code Here

  }

  public void testDocOp() {
    OpEquator eq = OpComparators.SYNTACTIC_IDENTITY;

    DocOpBuffer ba1 = new DocOpBuffer();
    ba1.characters("a");
    DocOp a1 = ba1.finish();

    DocOpBuffer ba2 = new DocOpBuffer();
    ba2.characters("a");
    DocOp a2 = ba2.finish();

    DocOpBuffer bb1 = new DocOpBuffer();
    bb1.deleteCharacters("a");
    DocOp b1 = bb1.finish();

    DocOpBuffer bb2 = new DocOpBuffer();
    bb2.deleteCharacters("a");
    DocOp b2 = bb1.finish();

    assertTrue(eq.equal(a1, a1));
    assertTrue(eq.equal(a1, a2));
    assertTrue(eq.equal(a2, a1));
View Full Code Here

  }

  @Override
  public DocOp invert(DocOp operation) {
    EvaluatingDocOpCursor<DocOp> inverter =
        new DocOpInverter<DocOp>(new DocOpBuffer());
    operation.apply(inverter);
    return inverter.finish();
  }
View Full Code Here

    return inverter.finish();
  }

  @Override
  public DocOp asOperation(BootstrapDocument state) {
    EvaluatingDocOpCursor<DocOp> builder = new DocOpBuffer();
    state.asOperation().apply(builder);
    return builder.finish();
  }
View Full Code Here

      @Override
      public int nextInt(int upperBound) {
        return random.nextInt(upperBound);
      }
    };
    EvaluatingDocOpCursor<DocOp> builder = new DocOpBuffer();
    RandomDocOpGenerator.generate(randomProvider, new RandomDocOpGenerator.Parameters(),
        state).apply(builder);
    return builder.finish();
  }
View Full Code Here

    RelativePosition insertionPosition = positionTracker.getPosition1();
    RelativePosition preservationPosition = positionTracker.getPosition2();

    // The target responsible for processing components of the insertion operation.
    InsertionTarget insertionTarget = new InsertionTarget(
        new RangeNormalizer<DocOp>(new DocOpBuffer()), insertionPosition);

    // The target responsible for processing components of the preservation operation.
    NoninsertionTarget preservationTarget =
        new NoninsertionTarget(
            OperationNormalizer.createNormalizer(new DocOpBuffer()), preservationPosition);

    insertionTarget.setOtherTarget(preservationTarget);
    preservationTarget.setOtherTarget(insertionTarget);

    // Incrementally apply the two operations in a linearly-ordered interleaving
View Full Code Here

  private CoreWaveletData wavelet;
  private CoreWaveletData originalWavelet;

  public CoreWaveletOperationTest() {
    DocOpBuffer docOpBuilder;

    addOp = new CoreAddParticipant(PARTICIPANT_ID);
    removeOp = new CoreRemoveParticipant(PARTICIPANT_ID);
    noOp = CoreNoOp.INSTANCE;

    docOpBuilder = new DocOpBuffer();
    docOpBuilder.characters(TEXT);
    docOpCharacters = new CoreWaveletDocumentOperation(DOC_ID, docOpBuilder.finish());

    docOpBuilder = new DocOpBuffer();
    docOpBuilder.deleteCharacters(TEXT);
    docOpDeleteCharacters = new CoreWaveletDocumentOperation(DOC_ID, docOpBuilder.finish());

    docOpBuilder = new DocOpBuffer();
    docOpBuilder.retain(TEXT.length());
    docOpBuilder.characters(TEXT);
    docOpRetainAndCharacters = new CoreWaveletDocumentOperation(DOC_ID, docOpBuilder.finish());

    docOpBuilder = new DocOpBuffer();
    docOpBuilder.retain(TEXT.length());
    docOpBuilder.deleteCharacters(TEXT);
    docOpRetainAndDeleteCharacters = new CoreWaveletDocumentOperation(DOC_ID, docOpBuilder.finish());

    docOpBuilder = new DocOpBuffer();
    docOpBuilder.elementStart("name1",
        new AttributesImpl(CollectionUtils.immutableMap("key1", "val1", "key2", "val2")));
    docOpBuilder.characters(TEXT);
    docOpBuilder.elementStart("name2",
        new AttributesImpl(CollectionUtils.immutableMap("key3", "val3", "key4", "val4")));
    docOpBuilder.characters(TEXT + TEXT);
    docOpBuilder.elementEnd();
    docOpBuilder.characters(TEXT + TEXT + TEXT);
    docOpBuilder.elementEnd();
    docOpComplex = new CoreWaveletDocumentOperation(DOC_ID, docOpBuilder.finish());
  }
View Full Code Here

    OpEquator eq = OpComparators.SYNTACTIC_IDENTITY;

    CoreWaveletOperation a = CoreNoOp.INSTANCE;
    CoreWaveletOperation b = new CoreAddParticipant(new ParticipantId(""));
    CoreWaveletOperation c = new CoreRemoveParticipant(new ParticipantId(""));
    CoreWaveletOperation d = new CoreWaveletDocumentOperation("", new DocOpBuffer().finish());

    assertTrue (a.equals(a));
    assertFalse(a.equals(b));
    assertFalse(a.equals(c));
    assertFalse(a.equals(d));
View Full Code Here

  }

  public void testWaveletDocumentOperationDocumentId() {
    OpEquator eq = OpComparators.SYNTACTIC_IDENTITY;

    DocOpBuffer b = new DocOpBuffer();
    b.characters("a");
    DocOp d = b.finish();

    CoreWaveletDocumentOperation a1 = new CoreWaveletDocumentOperation("a", d);
    CoreWaveletDocumentOperation a2 = new CoreWaveletDocumentOperation("a", d);
    CoreWaveletDocumentOperation b1 = new CoreWaveletDocumentOperation("b", d);
    CoreWaveletDocumentOperation b2 = new CoreWaveletDocumentOperation("b", d);
View Full Code Here

TOP

Related Classes of org.waveprotocol.wave.model.document.operation.impl.DocOpBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.