当前位置: 首页>>代码示例>>Java>>正文


Java OperationPair类代码示例

本文整理汇总了Java中org.waveprotocol.wave.model.operation.OperationPair的典型用法代码示例。如果您正苦于以下问题:Java OperationPair类的具体用法?Java OperationPair怎么用?Java OperationPair使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


OperationPair类属于org.waveprotocol.wave.model.operation包,在下文中一共展示了OperationPair类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: randomlyCompactingTransformer

import org.waveprotocol.wave.model.operation.OperationPair; //导入依赖的package包/类
public static final TransformQueue.Transformer<DocOp> randomlyCompactingTransformer(
    final int seed) {
  return new TransformQueue.Transformer<DocOp>() {
    final Random r = new Random(seed);

    @Override
    public OperationPair<DocOp> transform(DocOp clientOp, DocOp serverOp) {
      return transformer.transform(clientOp, serverOp);
    }

    @Override
    public List<DocOp> compact(List<DocOp> clientOps) {
      if (r.nextBoolean()) {
        return clientOps;
      } else {
        return transformer.compact(clientOps);
      }
    }
  };
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:21,代码来源:ChannelTestUtil.java

示例2: transform

import org.waveprotocol.wave.model.operation.OperationPair; //导入依赖的package包/类
/**
 * Transforms a pair of blip operations.
 *
 * @param clientOp
 * @param serverOp
 * @return the transformed pair.
 * @throws TransformException
 */
public static OperationPair<BlipOperation> transform(BlipOperation clientOp,
    BlipOperation serverOp) throws TransformException {
  if (clientOp instanceof BlipContentOperation && serverOp instanceof BlipContentOperation) {
    BlipContentOperation clientBlipContentOp = (BlipContentOperation) clientOp;
    BlipContentOperation serverBlipContentOp = (BlipContentOperation) serverOp;
    DocOp clientContentOp = clientBlipContentOp.getContentOp();
    DocOp serverContentOp = serverBlipContentOp.getContentOp();
    OperationPair<? extends DocOp> transformedDocOps =
        Transformer.transform(clientContentOp, serverContentOp);
    clientOp = new BlipContentOperation(clientBlipContentOp.getContext(),
        transformedDocOps.clientOp());
    serverOp = new BlipContentOperation(serverBlipContentOp.getContext(),
        transformedDocOps.serverOp());
  } else {
    // All other blip-op pairs have identity transforms for now.
  }

  // Apply identity transform by default
  return new OperationPair<BlipOperation>(clientOp, serverOp);
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:29,代码来源:Transform.java

示例3: pop

import org.waveprotocol.wave.model.operation.OperationPair; //导入依赖的package包/类
/**
 * Pops an operation from the undo stack and returns the operation that
 * effects the undo and the transformed non-undoable operation.
 *
 * @return a pair containeng the operation that accomplishes the desired undo
 *         and the transformed non-undoable operation
 */
Pair<T, T> pop() {
  if (stack.isEmpty()) {
    return null;
  }
  StackEntry<T> entry = stack.pop();
  T op = algorithms.invert(entry.op);
  if (entry.nonUndoables.isEmpty()) {
    return new Pair<T, T>(op, null);
  }
  OperationPair<T> pair;
  try {
    pair = algorithms.transform(op, algorithms.compose(entry.nonUndoables));
  } catch (TransformException e) {
    throw new IllegalStateException("invalid operation transformation encountered", e);
  }
  // TODO(user): Change the ternary expression to just stack.peek() after
  // switching from Stack to Deque.
  StackEntry<T> nextEntry = stack.isEmpty() ? null : stack.peek();
  if (nextEntry != null) {
    nextEntry.nonUndoables.add(pair.serverOp());
  }
  return new Pair<T, T>(pair.clientOp(), pair.serverOp());
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:31,代码来源:UndoStack.java

示例4: transformAndUpdate

import org.waveprotocol.wave.model.operation.OperationPair; //导入依赖的package包/类
/**
 * Transform stream S against streamC, updating streamC and returning the
 * transform of s.
 *
 * @param streamC
 * @param s
 * @throws TransformException
 */
private static OpCreatorPair transformAndUpdate(List<OpCreatorPair> streamC, OpCreatorPair s)
    throws TransformException {
  // Makes a copy of streamC and clear the original, so that it can be filled with the
  // transformed version.
  List<OpCreatorPair> streamCCopy = new ArrayList<OpCreatorPair>(streamC);
  streamC.clear();

  for (OpCreatorPair c : streamCCopy) {
    OperationPair<OpCreatorPair> transformed = transform(c, s);
    streamC.add(transformed.clientOp());
    s = transformed.serverOp();
  }

  return s;
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:24,代码来源:WaveAggregateOp.java

示例5: addIncomingOpToDraft

import org.waveprotocol.wave.model.operation.OperationPair; //导入依赖的package包/类
public DocOp addIncomingOpToDraft(DocOp operation) {
  if (!draftOps.isEmpty()) {
    try {
      DocOp c = Composer.compose(draftOps);
      OperationPair<DocOp> p = Transformer.transform(c, operation);
      operation = p.serverOp();
      draftOps.clear();
      draftOps.add(p.clientOp());
    }
    catch(TransformException e) {
      DomLogger.logToConsole(e.getMessage());
    }
  }
  
  return operation;
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:17,代码来源:ContentDocument.java

示例6: testEquivalence

import org.waveprotocol.wave.model.operation.OperationPair; //导入依赖的package包/类
public void testEquivalence() throws OperationException, TransformException {
  Random r = new Random(0);
  DocOpGenerator generator = new DocOpGenerator();
  for (int iteration = 0; iteration < NUM_ITERATIONS; ++iteration) {
    System.out.println("Iteration: " + iteration);
    BootstrapDocument document= new BootstrapDocument();
    for (int i = 0; i < INITIAL_MUTATION_COUNT; ++i) {
      document.consume(generator.randomOperation(document, r));
    }
    for (int i = 0; i < FEATURE_ITERATION_COUNT; ++i) {
      DocOp clientOp = generator.randomOperation(document, r);
      DocOp serverOp = generator.randomOperation(document, r);
      OperationPair<DocOp> pair = Transformer.transform(clientOp, serverOp);
      OperationPair<DocOp> referencePair =
          ReferenceTransformer.transform(clientOp, serverOp);
      assertTrue(OpComparators.SYNTACTIC_IDENTITY.equal(
          pair.clientOp(), referencePair.clientOp()));
      assertTrue(OpComparators.SYNTACTIC_IDENTITY.equal(
          pair.serverOp(), referencePair.serverOp()));
      document.consume(clientOp);
      document.consume(pair.serverOp());
    }
  }
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:25,代码来源:DocOpTransformerReferenceLargeTest.java

示例7: transformOps

import org.waveprotocol.wave.model.operation.OperationPair; //导入依赖的package包/类
/**
 * Transforms the specified client operations against the specified server operations,
 * returning the transformed client operations in a new list.
 *
 * @param clientOps may be unmodifiable
 * @param serverOps may be unmodifiable
 * @return transformed client ops
 */
private List<WaveletOperation> transformOps(List<WaveletOperation> clientOps,
    List<WaveletOperation> serverOps) throws OperationException {
  List<WaveletOperation> transformedClientOps = Lists.newArrayList();

  for (WaveletOperation c : clientOps) {
    for (WaveletOperation s : serverOps) {
      OperationPair<WaveletOperation> pair;
      try {
        pair = Transform.transform(c, s);
      } catch (TransformException e) {
        throw new OperationException(e);
      }
      c = pair.clientOp();
    }
    transformedClientOps.add(c);
  }
  return transformedClientOps;
}
 
开发者ID:apache,项目名称:incubator-wave,代码行数:27,代码来源:WaveletContainerImpl.java

示例8: transform

import org.waveprotocol.wave.model.operation.OperationPair; //导入依赖的package包/类
/**
 * Transforms the given aggregate operations.
 *
 * @param clientOp The client operation to transform.
 * @param serverOp The server operation to transform.
 *
 * @return The transform of the two operations.
 * @throws TransformException
 */
static OperationPair<AggregateOperation> transform(AggregateOperation clientOp,
    AggregateOperation serverOp) throws TransformException {
  List<ParticipantId> clientParticipantsToRemove = new ArrayList<ParticipantId>();
  List<ParticipantId> serverParticipantsToRemove = new ArrayList<ParticipantId>();
  List<ParticipantId> clientParticipantsToAdd = new ArrayList<ParticipantId>();
  List<ParticipantId> serverParticipantsToAdd = new ArrayList<ParticipantId>();
  List<DocumentOperations> clientDocOps = new ArrayList<DocumentOperations>();
  List<DocumentOperations> serverDocOps = new ArrayList<DocumentOperations>();
  removeCommonParticipants(clientOp.participantsToRemove, serverOp.participantsToRemove,
      clientParticipantsToRemove, serverParticipantsToRemove);
  removeCommonParticipants(clientOp.participantsToAdd, serverOp.participantsToAdd,
      clientParticipantsToAdd, serverParticipantsToAdd);
  transformDocumentOperations(clientOp.docOps, serverOp.docOps,
      clientDocOps, serverDocOps);
  AggregateOperation transformedClientOp = new AggregateOperation(
      clientParticipantsToRemove, clientParticipantsToAdd, clientDocOps);
  AggregateOperation transformedServerOp = new AggregateOperation(
      serverParticipantsToRemove, serverParticipantsToAdd, serverDocOps);
  return new OperationPair<AggregateOperation>(transformedClientOp, transformedServerOp);
}
 
开发者ID:apache,项目名称:incubator-wave,代码行数:30,代码来源:AggregateOperation.java

示例9: transform

import org.waveprotocol.wave.model.operation.OperationPair; //导入依赖的package包/类
@Override
public OperationPair<WaveletOperation> transform(
    WaveletOperation clientOp, WaveletOperation serverOp) {
  try {
    return Transform.transform(clientOp, serverOp);
  } catch (TransformException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:10,代码来源:WalkaroundOperationChannel.java

示例10: transform

import org.waveprotocol.wave.model.operation.OperationPair; //导入依赖的package包/类
@Override
public OperationPair<DocOp> transform(DocOp clientOp, DocOp serverOp) {
  try {
    return Transformer.transform(clientOp, serverOp);
  } catch (TransformException e) {
    throw new RuntimeException(e);
  }
}
 
开发者ID:ArloJamesBarnes,项目名称:walkaround,代码行数:9,代码来源:ChannelTestUtil.java

示例11: transform

import org.waveprotocol.wave.model.operation.OperationPair; //导入依赖的package包/类
/**
 * Transforms a pair of operations.
 *
 * @param clientOp the operation from the client
 * @param serverOp the operation from the server
 * @return the transformed pair of operations
 * @throws TransformException if a problem was encountered during the
 *         transformation process
 */
public static OperationPair<DocOp> transform(DocOp clientOp,
    DocOp serverOp) throws TransformException {
  try {
    // The transform process consists of decomposing the client and server
    // operations into two constituent operations each and performing four
    // transforms structured as in the following diagram:
    //     ci0     cn0
    // si0     si1     si2
    //     ci1     cn1
    // sn0     sn1     sn2
    //     ci2     cn2
    //
    Pair<DocOp, DocOp> c = Decomposer.decompose(clientOp);
    Pair<DocOp, DocOp> s = Decomposer.decompose(serverOp);
    DocOp ci0 = c.first;
    DocOp cn0 = c.second;
    DocOp si0 = s.first;
    DocOp sn0 = s.second;
    OperationPair<DocOp> r1 = new InsertionTransformer().transformOperations(ci0, si0);
    DocOp ci1 = r1.clientOp();
    DocOp si1 = r1.serverOp();
    OperationPair<DocOp> r2 =
        new InsertionNoninsertionTransformer().transformOperations(ci1, sn0);
    DocOp ci2 = r2.clientOp();
    DocOp sn1 = r2.serverOp();
    OperationPair<DocOp> r3 =
        new InsertionNoninsertionTransformer().transformOperations(si1, cn0);
    DocOp si2 = r3.clientOp();
    DocOp cn1 = r3.serverOp();
    OperationPair<DocOp> r4 = new NoninsertionTransformer().transformOperations(cn1, sn1);
    DocOp cn2 = r4.clientOp();
    DocOp sn2 = r4.serverOp();
    return new OperationPair<DocOp>(
        Composer.compose(ci2, cn2),
        Composer.compose(si2, sn2));
  } catch (OperationException e) {
    throw new TransformException(e);
  }
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:49,代码来源:Transformer.java

示例12: transformOperations

import org.waveprotocol.wave.model.operation.OperationPair; //导入依赖的package包/类
/**
 * Transforms a pair of insertion operations.
 *
 * @param clientOp the operation from the client
 * @param serverOp the operation from the server
 * @return the transformed pair of operations
 * @throws TransformException if a problem was encountered during the
 *         transformation process
 */
OperationPair<DocOp> transformOperations(DocOp clientOp,
    DocOp serverOp) throws TransformException {
  PositionTracker positionTracker = new PositionTracker();

  RelativePosition clientPosition = positionTracker.getPosition1();
  RelativePosition serverPosition = positionTracker.getPosition2();

  // The target responsible for processing components of the client operation.
  Target clientTarget = new Target(clientPosition);

  // The target responsible for processing components of the server operation.
  Target serverTarget = new Target(serverPosition);

  clientTarget.setOtherTarget(serverTarget);
  serverTarget.setOtherTarget(clientTarget);

  // Incrementally apply the two operations in a linearly-ordered interleaving
  // fashion.
  int clientIndex = 0;
  int serverIndex = 0;
  while (clientIndex < clientOp.size()) {
    clientOp.applyComponent(clientIndex++, clientTarget);
    while (clientPosition.get() > 0) {
      if (serverIndex >= serverOp.size()) {
        throw new TransformException("Ran out of " + serverOp.size()
            + " server op components after " + clientIndex + " of " + clientOp.size()
            + " client op components, with " + clientPosition.get() + " spare positions");
      }
      serverOp.applyComponent(serverIndex++, serverTarget);
    }
  }
  while (serverIndex < serverOp.size()) {
    serverOp.applyComponent(serverIndex++, serverTarget);
  }
  clientOp = clientTarget.finish();
  serverOp = serverTarget.finish();
  return new OperationPair<DocOp>(clientOp, serverOp);
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:48,代码来源:InsertionTransformer.java

示例13: transformOperations

import org.waveprotocol.wave.model.operation.OperationPair; //导入依赖的package包/类
/**
 * Transforms an insertion operation and an insertion-free operation.
 *
 * @param insertionOp the insertion operation
 * @param noninsertionOp the insertion-free operation
 * @return the transformed pair of operations
 * @throws TransformException if a problem was encountered during the
 *         transformation process
 */
OperationPair<DocOp> transformOperations(DocOp insertionOp,
    DocOp noninsertionOp) throws TransformException {
  PositionTracker positionTracker = new PositionTracker();

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

  // The target responsible for processing components of the insertion operation.
  InsertionTarget insertionTarget = new InsertionTarget(insertionPosition);

  // The target responsible for processing components of the insertion-free operation.
  NoninsertionTarget noninsertionTarget = new NoninsertionTarget(noninsertionPosition);

  insertionTarget.setOtherTarget(noninsertionTarget);
  noninsertionTarget.setOtherTarget(insertionTarget);

  // Incrementally apply the two operations in a linearly-ordered interleaving
  // fashion.
  int insertionIndex = 0;
  int noninsertionIndex = 0;
  while (insertionIndex < insertionOp.size()) {
    insertionOp.applyComponent(insertionIndex++, insertionTarget);
    while (insertionPosition.get() > 0) {
      if (noninsertionIndex >= noninsertionOp.size()) {
        throw new TransformException("Ran out of " + noninsertionOp.size()
            + " noninsertion op components after " + insertionIndex + " of " + insertionOp.size()
            + " insertion op components, with " + insertionPosition.get() + " spare positions");
      }
      noninsertionOp.applyComponent(noninsertionIndex++, noninsertionTarget);
    }
  }
  while (noninsertionIndex < noninsertionOp.size()) {
    noninsertionOp.applyComponent(noninsertionIndex++, noninsertionTarget);
  }
  insertionOp = insertionTarget.finish();
  noninsertionOp = noninsertionTarget.finish();
  return new OperationPair<DocOp>(insertionOp, noninsertionOp);
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:48,代码来源:InsertionNoninsertionTransformer.java

示例14: transformDocumentOperations

import org.waveprotocol.wave.model.operation.OperationPair; //导入依赖的package包/类
static private void transformDocumentOperations(
    List<DocumentOperations> clientOps,
    List<DocumentOperations> serverOps,
    List<DocumentOperations> transformedClientOps,
    List<DocumentOperations> transformedServerOps) throws TransformException {
  int index = 0;
  outerLoop:
  for (DocumentOperations fromClient : clientOps) {
    while (index < serverOps.size()) {
      DocumentOperations fromServer = serverOps.get(index);
      int comparison = fromClient.id.compareTo(fromServer.id);
      if (comparison < 0) {
        break;
      }
      ++index;
      if (comparison > 0) {
        transformedServerOps.add(fromServer);
      } else {
        DocOp clientOp = fromClient.operations.composeAll();
        DocOp serverOp = fromServer.operations.composeAll();
        OperationPair<DocOp> transformedOps = Transformer.transform(clientOp, serverOp);
        transformedClientOps.add(new DocumentOperations(fromClient.id,
            new DocOpList.Singleton(transformedOps.clientOp())));
        transformedServerOps.add(new DocumentOperations(fromClient.id,
            new DocOpList.Singleton(transformedOps.serverOp())));
        continue outerLoop;
      }
    }
    transformedClientOps.add(fromClient);
  }
  for (; index < serverOps.size(); ++index) {
    transformedServerOps.add(serverOps.get(index));
  }
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:35,代码来源:AggregateOperation.java

示例15: transform

import org.waveprotocol.wave.model.operation.OperationPair; //导入依赖的package包/类
/**
 * Transform the given operations.
 *
 * @param clientOp
 * @param serverOp
 *
 * @throws TransformException
 */
static OperationPair<WaveAggregateOp> transform(WaveAggregateOp clientOp,
    WaveAggregateOp serverOp) throws TransformException {
  // This gets filled with transformed server ops.
  List<OpCreatorPair> transformedServerOps = new ArrayList<OpCreatorPair>();
  // This starts with the original client ops, and gets transformed with each server op.
  List<OpCreatorPair> transformedClientOps = new ArrayList<OpCreatorPair>(clientOp.opPairs);

  for (OpCreatorPair sPair : serverOp.opPairs) {
    transformedServerOps.add(transformAndUpdate(transformedClientOps, sPair));
  }

  return new OperationPair<WaveAggregateOp>(new WaveAggregateOp(transformedClientOps),
      new WaveAggregateOp(transformedServerOps));
}
 
开发者ID:jorkey,项目名称:Wiab.pro,代码行数:23,代码来源:WaveAggregateOp.java


注:本文中的org.waveprotocol.wave.model.operation.OperationPair类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。