Package com.google.collide.dto

Examples of com.google.collide.dto.DocOp


  }

  public static DocOp compose(DocOpFactory factory, Iterable<DocOp> docOps)
      throws ComposeException {
    Iterator<DocOp> iterator = docOps.iterator();
    DocOp prevDocOp = iterator.next();
    while (iterator.hasNext()) {
      prevDocOp = compose(factory, prevDocOp, iterator.next());
    }

    return prevDocOp;
View Full Code Here


   * @param column old position column
   * @return current position line number and column
   */
  public LineNumberAndColumn migrateToNow(int lineNumber, int column) {
    // TODO: Cache the result.
    DocOp docOp = composeCurrentDocOps();
    if (docOp == null) {
      return LineNumberAndColumn.from(lineNumber, column);
    }
    PositionTransformer positionTransformer =
        new PositionTransformer(lineNumber, column);
View Full Code Here

   * @param column current position column
   * @return old position line number and column
   */
  public LineNumberAndColumn migrateFromNow(int lineNumber, int column) {
    // TODO: Cache the result.
    DocOp docOp = composeCurrentDocOps();
    if (docOp == null) {
      return LineNumberAndColumn.from(lineNumber, column);
    }
    PositionTransformer positionTransformer =
        new PositionTransformer(lineNumber, column);
View Full Code Here

  private DocOp composeCurrentDocOps() {
    if (appliedDocOps.size() < 2) {
      return appliedDocOps.size() > 0 ? appliedDocOps.get(0) : null;
    }
    try {
      DocOp docOp = Composer.compose(docOpFactory, appliedDocOps.asIterable());
      appliedDocOps.clear();
      appliedDocOps.add(docOp);
      return docOp;
    } catch (Composer.ComposeException e) {
      throw new RuntimeException(e);
View Full Code Here

    Receiver receiver = receivers.get(message.getFileEditSessionKey());
    if (receiver == null && bulkReceivers.size() == 0) {
      return;
    }

    DocOp docOp = message.getDocOp2();

    // Send to the registered receiver for the file edit session.
    if (receiver != null) {
      receiver.onDocOpReceived(message, docOp);
    }
View Full Code Here

 
  public static Pair<DocOp, DocOp> composeWithBothStartingStates(DocOpFactory factory, DocOp a,
      DocOp b) throws ComposeException {
   
    ComposeException e1 = null;
    DocOp composedDocOp1 = null;
    try {
      composedDocOp1 = Composer.composeWithStartState(factory, a, b, false);
    } catch (ComposeException e) {
      e1 = e;
    }
   
    ComposeException e2 = null;
    DocOp composedDocOp2 = null;
    try {
      composedDocOp2 = Composer.composeWithStartState(factory, a, b, true);
    } catch (ComposeException e) {
      e2 = e;
    }
View Full Code Here

  }

  public void testMultiLineDeleteVsDelete() throws Exception {
    {
      // Deletion above another deletion
      DocOp c = dob.d(TEN_N).d(TEN_N).d(TEN).eolR(5).rl(10).b();
      DocOp s = dob.rl(5).d(FIVE_N).d(FIVE_N).d(FIVE_N).rl(5).b();
      DocOp cPrime = dob.d(TEN_N).d(TEN_N).d(TEN).eolR(5).rl(7).b();
      DocOp sPrime = dob.rl(3).d(FIVE_N).d(FIVE_N).d(FIVE_N).rl(5).b();
      new ReversibleTestParameters(c, s, cPrime, sPrime).run();
    }

    {
      // Deletion above another deletion (lines adjacent)
      DocOp c = dob.d(TEN_N).d(TEN_N).d(TEN_N).rl(10).b();
      DocOp s = dob.rl(3).d(FIVE_N).d(FIVE_N).d(FIVE_N).rl(7).b();
      DocOp cPrime = dob.d(TEN_N).d(TEN_N).d(TEN_N).rl(7).b();
      DocOp sPrime = dob.d(FIVE_N).d(FIVE_N).d(FIVE_N).rl(7).b();
      new ReversibleTestParameters(c, s, cPrime, sPrime).run();
    }

    {
      // TODO: the delete brought a RL onto a previously modified
      // line, is this legal?
      // Deletion above another deletion (characters adjacent)
      DocOp c = dob.d(TEN_N).d(TEN_N).d(TEN).eolR(6).rl(10).b();
      DocOp s = dob.rl(2).r(10).d(FIVE_N).d(FIVE_N).d(FIVE_N).rl(8).b();
      DocOp cPrime = dob.d(TEN_N).d(TEN_N).d(TEN).rl(8).b();
      DocOp sPrime = dob.d(FIVE_N).d(FIVE_N).d(FIVE_N).rl(8).b();
      new ReversibleTestParameters(c, s, cPrime, sPrime).run();
    }

    {
      // Overlapping deletions (line granularity)
      DocOp c = dob.d(TEN_N).d(TEN_N).d(TEN_N).rl(10).b();
      DocOp s = dob.rl(2).d(TEN_N).d(FIVE_N).d(FIVE_N).rl(8).b();
      DocOp cPrime = dob.d(TEN_N).d(TEN_N).rl(8).b();
      DocOp sPrime = dob.d(FIVE_N).d(FIVE_N).rl(8).b();
      new ReversibleTestParameters(c, s, cPrime, sPrime).run();
    }

    {
      // Overlapping deletions (character granularity)
      DocOp c = dob.d(TEN_N).d(TEN_N).d(TEN).eolR(1).rl(10).b();
      DocOp s = dob.rl(2).d(TEN_N).d(FIVE_N).d(FIVE_N).rl(8).b();
      DocOp cPrime = dob.d(TEN_N).d(TEN_N).rl(8).b();
      DocOp sPrime = dob.d(N).d(FIVE_N).d(FIVE_N).rl(8).b();
      new ReversibleTestParameters(c, s, cPrime, sPrime).run();
    }

    {
      // Subset deletions (character granularity)
      DocOp c = dob.d(TEN_N).d(TEN_N).b();
      DocOp s = dob.rl(1).d(TEN).eolR(1).b();
      DocOp cPrime = dob.d(TEN_N).d(N).b();
      DocOp sPrime = dob.b();
      new ReversibleTestParameters(c, s, cPrime, sPrime).run();
    }

    {
      // Identical deletions
      DocOp c = dob.d(TEN_N).d(TEN_N).b();
      DocOp s = c;
      DocOp cPrime = dob.b();
      DocOp sPrime = cPrime;
      new ReversibleTestParameters(c, s, cPrime, sPrime).run();
    }
  }
View Full Code Here

  }

  public void testMultiLineInsertVsDelete() throws Exception {
    {
      // Insertion above deletion
      DocOp c = dob.rl(2).i(FIVE_N).rl(2).b();
      DocOp s = dob.rl(3).d(TEN_N).b();
      DocOp cPrime = dob.rl(2).i(FIVE_N).rl(1).b();
      DocOp sPrime = dob.rl(4).d(TEN_N).b();
      new ReversibleTestParameters(c, s, cPrime, sPrime).run();
    }

    {
      // Insertion above deletion, but adjacent lines
      DocOp c = dob.rl(2).i(FIVE_N).rl(1).b();
      DocOp s = dob.rl(2).d(TEN_N).b();
      DocOp cPrime = dob.rl(2).i(FIVE_N).b();
      DocOp sPrime = dob.rl(3).d(TEN_N).b();
      new ReversibleTestParameters(c, s, cPrime, sPrime).run();
    }

    {
      // Insertion above/adjacent deletion (the last character of insertion is
      // adjacent to first character of deletion)
      DocOp c = dob.rl(2).i(FIVE_N).i(FIVE).eolR(11).rl(1).b();
      DocOp s = dob.rl(2).d(TEN_N).d(TEN_N).b();
      DocOp cPrime = dob.rl(2).i(FIVE_N).i(FIVE).b();
      DocOp sPrime = dob.rl(3).r(5).d(TEN_N).d(TEN_N).b();
      new ReversibleTestParameters(c, s, cPrime, sPrime).run();
    }

    {
      // Insertion above/adjacent deletion (the last character of insertion is
      // adjacent to first character of deletion)
      DocOp c = dob.rl(2).i(FIVE_N).i(FIVE).eolR(11).rl(1).b();
      DocOp s = dob.rl(2).d(TEN_N).d(TEN_N).b();
      DocOp cPrime = dob.rl(2).i(FIVE_N).i(FIVE).b();
      DocOp sPrime = dob.rl(3).r(5).d(TEN_N).d(TEN_N).b();
      new ReversibleTestParameters(c, s, cPrime, sPrime).run();
    }

    {
      // Insertion inside deletion
      DocOp c = dob.rl(2).i(FIVE_N).i(FIVE_N).rl(2).b();
      DocOp s = dob.d(TEN_N).d(TEN_N).d(TEN_N).d(TEN_N).b();
      DocOp cPrime = dob.i(FIVE_N).i(FIVE_N).b();
      DocOp sPrime = dob.d(TEN_N).d(TEN_N).rl(2).d(TEN_N).d(TEN_N).b();
      new TestParameters(c, s, cPrime, sPrime).run();
    }

    {
      // Insertion starts right after the last char deleted
      DocOp c = dob.rl(1).r(10).i(FIVE_N).i(FIVE).eolR(2).rl(3).b();
      DocOp s = dob.d(TEN_N).d(TEN).eolR(2).rl(3).b();
      DocOp cPrime = dob.i(FIVE_N).i(FIVE).eolR(2).rl(3).b();
      DocOp sPrime = dob.d(TEN_N).d(TEN).eolR(6).rl(4).b();
      new TestParameters(c, s, cPrime, sPrime).run();
    }

    {
      // Insertion starts on the line after the last line deleted
      DocOp c = dob.rl(4).r(10).i(FIVE_N).i(FIVE).eolR(2).rl(3).b();
      DocOp s = dob.d(TEN_N).d(TEN).eolR(2).rl(6).b();
      DocOp cPrime = dob.rl(3).r(10).i(FIVE_N).i(FIVE).eolR(2).rl(3).b();
      DocOp sPrime = dob.d(TEN_N).d(TEN).eolR(2).rl(7).b();
      new TestParameters(c, s, cPrime, sPrime).run();
    }

    {
      // Insertion is later in the document
      DocOp c = dob.rl(5).i(FIVE_N).i(FIVE_N).b();
      DocOp s = dob.d(TEN_N).d(TEN_N).rl(3).b();
      DocOp cPrime = dob.rl(3).i(FIVE_N).i(FIVE_N).b();
      DocOp sPrime = dob.d(TEN_N).d(TEN_N).rl(5).b();
      new TestParameters(c, s, cPrime, sPrime).run();
    }
  }
View Full Code Here

  }

  public void testMultiLineInsertVsInsert() throws Exception {
    {
      // Simple test of a insertion with newline
      DocOp c = dob.rl(3).b();
      DocOp s = dob.rl(1).i(TEN_N).eolR(1).rl(1).b();
      DocOp cPrime = dob.rl(4).b();
      DocOp sPrime = dob.rl(1).i(TEN_N).eolR(1).rl(1).b();
      new ReversibleTestParameters(c, s, cPrime, sPrime).run();
    }

    {
      // A's insertion spatially above B's insertion (simpler to trap bug)
      DocOp c = dob.rl(5).i(FIVE_N).i(FIVE_N).i(TEN).eolR(1).rl(4).b();
      DocOp s = dob.rl(8).i(TEN_N).i(TWENTY_N).rl(2).b();
      DocOp cPrime = dob.rl(5).i(FIVE_N).i(FIVE_N).i(TEN).eolR(1).rl(6).b();
      DocOp sPrime = dob.rl(10).i(TEN_N).i(TWENTY_N).rl(2).b();
      new ReversibleTestParameters(c, s, cPrime, sPrime).run();
    }

    {
      // A's insertion spatially above B's insertion
      DocOp c = dob.rl(5).r(3).i(FIVE_N).i(FIVE_N).i(TEN).eolR(5).rl(4).b();
      DocOp s = dob.rl(8).i(TEN_N).i(TWENTY_N).rl(2).b();
      DocOp cPrime = dob.rl(5).r(3).i(FIVE_N).i(FIVE_N).i(TEN).eolR(5).rl(6).b();
      DocOp sPrime = dob.rl(10).i(TEN_N).i(TWENTY_N).rl(2).b();
      new ReversibleTestParameters(c, s, cPrime, sPrime).run();
    }

    {
      // A's retain gets cut short by B's newline insertion
      DocOp c = dob.eolR(5).b();
      DocOp s = dob.r(2).i(FIVE_N).eolR(3).b();
      DocOp cPrime = dob.eolR(8).eolR(3).b();
      DocOp sPrime = dob.r(2).i(FIVE_N).eolR(3).b();
      new ReversibleTestParameters(c, s, cPrime, sPrime).run();
    }

    {
      // A's insertion's last line touched is the same as B's insertion's first
      // line touched
      DocOp c = dob.rl(5).i(FIVE_N).i(FIVE_N).i(TEN).eolR(5).rl(5).b();
      DocOp s = dob.rl(5).r(2).i(TEN_N).i(TWENTY_N).eolR(3).rl(5).b();
      DocOp cPrime = dob.rl(5).i(FIVE_N).i(FIVE_N).i(TEN).eolR(13).eolR(21).eolR(3).rl(5).b();
      DocOp sPrime = dob.rl(5).eolR(6).eolR(6).r(12).i(TEN_N).i(TWENTY_N).eolR(3).rl(5).b();
      new ReversibleTestParameters(c, s, cPrime, sPrime).run();
    }

    {
      // A's insertion's last character is adjacent to B's insertion's first
      // character (simplified)
      DocOp c = dob.i(FIVE_N).i(FIVE_N).b();
      DocOp s = dob.i(TEN_N).i(TEN_N).b();
      DocOp cPrime = dob.i(FIVE_N).i(FIVE_N).rl(2).b();
      DocOp sPrime = dob.rl(2).i(TEN_N).i(TEN_N).b();
      new TestParameters(c, s, cPrime, sPrime).run();
    }

    {
      // A's insertion's last character is adjacent to B's insertion's first
      // character
      DocOp c = dob.rl(5).i(FIVE_N).i(FIVE_N).i(TEN).eolR(1).rl(5).b();
      DocOp s = dob.rl(5).i(TEN_N).i(TWENTY_N).rl(6).b();
      DocOp cPrime = dob.rl(5).i(FIVE_N).i(FIVE_N).i(TEN).eolR(11).rl(7).b();
      DocOp sPrime = dob.rl(7).r(10).i(TEN_N).i(TWENTY_N).rl(6).b();
      new TestParameters(c, s, cPrime, sPrime).run();
    }
  }
View Full Code Here

  }

  public void testRetainLineMatchingOtherNonEmptyLastLine() throws Exception {
    {
      // Tests that a final retain line matches the other's non-empty last line
      DocOp c = dob.rl(25).r(58).i("a").eolR(35).rl(1).b();
      DocOp s = dob.rl(26).r(58).i("b").b();
      DocOp cPrime = c;
      DocOp sPrime = s;
      new ReversibleTestParameters(c, s, cPrime, sPrime).run();
    }

    {
      // Tests that a retain line for more lines than available throws exception
      DocOp c = dob.rl(25).r(58).i("a").eolR(35).rl(2).b();
      DocOp s = dob.rl(26).r(58).i("b").b();
      DocOp cPrime = c;
      DocOp sPrime = s;
      try {
        new ReversibleTestParameters(c, s, cPrime, sPrime).run();
        fail();
      } catch (Throwable t) {
      }
View Full Code Here

TOP

Related Classes of com.google.collide.dto.DocOp

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.