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

Examples of org.waveprotocol.wave.model.document.operation.AttributesUpdate


      void resolveUpdateAttributes(AttributesUpdate update) {
        Map<String, String> updated = new HashMap<String, String>();
        for (int i = 0; i < update.changeSize(); ++i) {
          updated.put(update.getChangeKey(i), update.getNewValue(i));
        }
        AttributesUpdate newUpdate = new AttributesUpdateImpl();
        // TODO: This is a little silly. We should do this a better way.
        for (int i = 0; i < this.update.changeSize(); ++i) {
          String key = this.update.getChangeKey(i);
          String newOldValue = updated.containsKey(key) ? updated.get(key)
              : this.update.getOldValue(i);
          newUpdate = newUpdate.composeWith(new AttributesUpdateImpl(key,
              newOldValue, this.update.getNewValue(i)));
        }
        targetDocument.updateAttributes(newUpdate);
        Set<String> keySet = new HashSet<String>();
        for (int i = 0; i < this.update.changeSize(); ++i) {
          keySet.add(this.update.getChangeKey(i));
        }
        AttributesUpdate transformedAttributes = update.exclude(keySet);
        otherTarget.targetDocument.updateAttributes(transformedAttributes);
      }
View Full Code Here


  }

  public void testUpdateAttributes() {
    DocOpBuilder m = new DocOpBuilder();

    AttributesUpdate u = new AttributesUpdateImpl(new String[]{"a", null, "2", "b", "1", null});

    m.retain(4);
    m.updateAttributes(u);
    m.retain(4);
View Full Code Here

          // several cases: invalid because of wrong old attributes, or invalid
          // because of schema violation of new attributes, or because no
          // element start here
          throw new RuntimeException("Not implemented");
        }
        AttributesUpdate u = generateRandomAttributesUpdate(valid,
            oldAttrs, new AttributesUpdateChecker() {
          @Override
          public ValidationResult check(AttributesUpdate u) {
            return a.checkReplaceAttributes(oldAttrs, oldAttrs.updateWith(u), null);
          }
View Full Code Here

          // several cases: invalid because of wrong old attributes, or invalid
          // because of schema violation of new attributes, or because no
          // element start here
          throw new RuntimeException("Not implemented");
        }
        final AttributesUpdate update = generateRandomAttributesUpdate(valid,
            oldAttrs, new AttributesUpdateChecker() {
          @Override
          public ValidationResult check(AttributesUpdate u) {
            return a.checkUpdateAttributes(u, null);
          }
View Full Code Here

        syncAnnotations();
        Map<String, String> updated = new HashMap<String, String>();
        for (int i = 0; i < update.changeSize(); ++i) {
          updated.put(update.getChangeKey(i), update.getNewValue(i));
        }
        AttributesUpdate newUpdate = new AttributesUpdateImpl();
        // TODO: This is a little silly. We should do this a better way.
        for (int i = 0; i < this.update.changeSize(); ++i) {
          String key = this.update.getChangeKey(i);
          String newOldValue = updated.containsKey(key) ? updated.get(key)
              : this.update.getOldValue(i);
          newUpdate = newUpdate.composeWith(new AttributesUpdateImpl(key,
              newOldValue, this.update.getNewValue(i)));
        }
        targetDocument.updateAttributes(newUpdate);
        Set<String> keySet = new HashSet<String>();
        for (int i = 0; i < this.update.changeSize(); ++i) {
          keySet.add(this.update.getChangeKey(i));
        }
        AttributesUpdate transformedAttributes = update.exclude(keySet);
        otherTarget.targetDocument.updateAttributes(transformedAttributes);
      }
View Full Code Here

    target.replaceAttributes(newAttrs, oldAttrs);
  }

  @Override
  public void updateAttributes(AttributesUpdate attrUpdate) {
    AttributesUpdate update = new AttributesUpdateImpl();
    // TODO: This is a little silly. We should do this a better way.
    for (int i = 0; i < attrUpdate.changeSize(); ++i) {
      update = update.composeWith(new AttributesUpdateImpl(attrUpdate.getChangeKey(i),
          attrUpdate.getNewValue(i), attrUpdate.getOldValue(i)));
    }
    target.updateAttributes(update);
  }
View Full Code Here

    preAnnotationQueue.flush();
    postAnnotationQueue.flush();
  }

  private static AttributesUpdate invertUpdate(AttributesUpdate attrUpdate) {
    AttributesUpdate inverseUpdate = new AttributesUpdateImpl();
    // TODO: This is a little silly. We should do this a better way.
    for (int i = 0; i < attrUpdate.changeSize(); ++i) {
      inverseUpdate = inverseUpdate.composeWith(new AttributesUpdateImpl(
          attrUpdate.getChangeKey(i), attrUpdate.getNewValue(i), attrUpdate.getOldValue(i)));
    }
    return inverseUpdate;
  }
View Full Code Here

    // returns null on failure
    AttributesUpdate generateRandomAttributesUpdate(final boolean valid,
        final Attributes oldAttributes,
        final AttributesUpdateChecker checker) {
      AttributesUpdate accu = new AttributesUpdateImpl();
      if (valid && !checker.check(accu).isValid()
          || !valid && checker.check(accu).isIllFormed()) {
        return null;
      }
      if (!valid) {
        // If we want an invalid component, and it's not already invalid without
        // any attributes, make it invalid by adding an invalid attribute first.
        if (checker.check(accu).isValid()) {
          assert accu.changeSize() == 0;
          accu = pickRandomNonNullMappedElement(r,
              p.getAttributeNames(), new Mapper<String, AttributesUpdate>() {
            @Override
            public AttributesUpdate map(final String name) {
              return pickRandomNonNullMappedElement(r, p.getAttributeValues(),
                  new Mapper<String, AttributesUpdate> () {
                @Override
                public AttributesUpdate map(String value) {
                  AttributesUpdate b = new AttributesUpdateImpl(name,
                      oldAttributes.get(name), value);
                  switch (checker.check(b)) {
                    case ILL_FORMED:
                      return null;
                    case INVALID_DOCUMENT:
                    case INVALID_SCHEMA:
                      return b;
                    case VALID:
                      return null;
                    default:
                      throw new RuntimeException("Unexpected validation result");
                  }
                }
              });
            }
          });
          if (accu == null) {
            return null;
          }
        }
        assert !checker.check(accu).isValid();
        // Flip a coin and terminate if the number of attributes was really
        // supposed to be zero.
        if (r.nextBoolean()) {
          return accu;
        }
      }
      while (r.nextBoolean()) {
        final AttributesUpdate finalAccu = accu;
        AttributesUpdate newAccu = pickRandomNonNullMappedElement(r,
            p.getAttributeNames(), new Mapper<String, AttributesUpdate>() {
          @Override
          public AttributesUpdate map(final String name) {
            for (int i = 0; i < finalAccu.changeSize(); i++) {
              if (finalAccu.getChangeKey(i).equals(name)) {
                return null;
              }
            }
            return pickRandomNonNullMappedElement(r, p.getAttributeValues(),
                new Mapper<String, AttributesUpdate>() {
              @Override
              public AttributesUpdate map(String value) {
                AttributesUpdate b = finalAccu.composeWith(new AttributesUpdateImpl(name,
                    oldAttributes.get(name), value));
                assert b != finalAccu; // assert non-destructiveness
                ValidationResult v = checker.check(b);
                if (valid && !v.isValid() || !valid && v.isIllFormed()) {
                  return null;
View Full Code Here

            // Early exit if we can't build an element start with this tag.
            return null;
          }
        }

        AttributesUpdate u = generateRandomAttributesUpdate(valid, Attributes.EMPTY_MAP,
            new AttributesUpdateChecker() {
              @Override
              public ValidationResult check(AttributesUpdate u) {
                Attributes attrs = Attributes.EMPTY_MAP.updateWith(u);
                return a.checkElementStart(tag, attrs, null);
View Full Code Here

        syncAnnotations();
        Map<String, String> updated = new HashMap<String, String>();
        for (int i = 0; i < update.changeSize(); ++i) {
          updated.put(update.getChangeKey(i), update.getNewValue(i));
        }
        AttributesUpdate newUpdate = new AttributesUpdateImpl();
        // TODO: This is a little silly. We should do this a better way.
        for (int i = 0; i < this.update.changeSize(); ++i) {
          String key = this.update.getChangeKey(i);
          String newOldValue = updated.containsKey(key) ? updated.get(key)
              : this.update.getOldValue(i);
          newUpdate = newUpdate.composeWith(new AttributesUpdateImpl(key,
              newOldValue, this.update.getNewValue(i)));
        }
        targetDocument.updateAttributes(newUpdate);
        Set<String> keySet = new HashSet<String>();
        for (int i = 0; i < this.update.changeSize(); ++i) {
          keySet.add(this.update.getChangeKey(i));
        }
        AttributesUpdate transformedAttributes = update.exclude(keySet);
        otherTarget.targetDocument.updateAttributes(transformedAttributes);
      }
View Full Code Here

TOP

Related Classes of org.waveprotocol.wave.model.document.operation.AttributesUpdate

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.