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

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


        "attribute1", "bad",
        "attribute2", "abbbc",
        "attribute3", "axyzb")),
        "attribute1", "bad");
    checkValidation_V(test.validateAttributes(AttributesImpl.EMPTY_MAP));
    checkValidation_ANA(test.validateAttributesUpdate(new AttributesUpdateImpl(
        "bad", "value1", "value1")),
        "bad");
    checkValidation_ANA(test.validateAttributesUpdate(new AttributesUpdateImpl(
        "attribute1", "value1", "value1",
        "bad", "bad", "bad")),
        "bad");
    checkValidation_V(test.validateAttributesUpdate(new AttributesUpdateImpl(
        "attribute1", "value1", "value1")));
    checkValidation_V(test.validateAttributesUpdate(new AttributesUpdateImpl(
        "attribute1", "value1", null)));
    checkValidation_V(test.validateAttributesUpdate(new AttributesUpdateImpl(
        "attribute1", "value1", "value1",
        "attribute2", "abbbc", "abbbc",
        "attribute3", "axyzb", "axyzb")));
    checkValidation_IAV(test.validateAttributesUpdate(new AttributesUpdateImpl(
        "attribute1", "bad", "bad",
        "attribute2", "abbbc", "abbbc",
        "attribute3", "axyzb", "axyzb")),
        "attribute1", "bad");
    checkValidation_V(test.validateAttributesUpdate(AttributesUpdateImpl.EMPTY_MAP));
View Full Code Here


        "attribute2", "abbbc",
        "attribute3", "axyzb")),
        "attribute1");
    checkValidation_MRA(test.validateAttributes(AttributesImpl.EMPTY_MAP),
        "attribute1");
    checkValidation_ANA(test.validateAttributesUpdate(new AttributesUpdateImpl(
        "bad", "value1", "value1")),
        "bad");
    checkValidation_ANA(test.validateAttributesUpdate(new AttributesUpdateImpl(
        "attribute1", "value1", "value1",
        "bad", "bad", "bad")),
        "bad");
    checkValidation_V(test.validateAttributesUpdate(new AttributesUpdateImpl(
        "attribute1", "value1", "value1")));
    checkValidation_RRA(test.validateAttributesUpdate(new AttributesUpdateImpl(
        "attribute1", "value1", null)),
        "attribute1");
    checkValidation_V(test.validateAttributesUpdate(new AttributesUpdateImpl(
        "attribute1", "value1", "value1",
        "attribute2", "abbbc", "abbbc",
        "attribute3", "axyzb", "axyzb")));
    checkValidation_IAV(test.validateAttributesUpdate(new AttributesUpdateImpl(
        "attribute1", "bad", "bad",
        "attribute2", "abbbc", "abbbc",
        "attribute3", "axyzb", "axyzb")),
        "attribute1", "bad");
    checkValidation_IAV(test.validateAttributesUpdate(new AttributesUpdateImpl(
        "attribute1", "value1", "value1",
        "attribute2", "bad", "bad",
        "attribute3", "axyzb", "axyzb")),
        "attribute2", "bad");
    checkValidation_V(test.validateAttributesUpdate(new AttributesUpdateImpl(
        "attribute2", "abbbc", "abbbc",
        "attribute3", "axyzb", "axyzb")));
    checkValidation_V(test.validateAttributesUpdate(AttributesUpdateImpl.EMPTY_MAP));
  }
View Full Code Here

    b.replaceAttributes(new AttributesImpl(), Attributes.EMPTY_MAP);
    // Now we add similar cases for annotation boundaries.  Since consecutive annotation
    // boundaries would make the operation ill-formed, we interleave them with further
    // updateAttributes tests.
    b.annotationBoundary(AnnotationBoundaryMapImpl.builder().build());
    b.updateAttributes(new AttributesUpdateImpl());
    b.annotationBoundary(AnnotationBoundaryMapImpl.builder()
        .updateValues("b", "XZ", "yz", "f-", null, null,
            "g-", "a", null, "k-", "b", "", "r", "", "2")
        .build());
    b.updateAttributes(new AttributesUpdateImpl("a", null, "1"));
    b.annotationBoundary(AnnotationBoundaryMapImpl.builder()
        .initializationEnd("b", "g-", "k-", "r")
        .updateValues("e", "166", null, "f-", null, null)
        .build());
    b.updateAttributes(new AttributesUpdateImpl("P", null, "", ":wq", "ZZ", null));
    b.annotationBoundary(AnnotationBoundaryMapImpl.builder()
        .initializationEnd("e", "f-")
        .build());

    return b.finish();
View Full Code Here

          for (KeyValueUpdate kvu : u.getAttributeUpdate()) {
            triplets[i++] = kvu.getKey();
            triplets[i++] = kvu.hasOldValue() ? kvu.getOldValue() : null;
            triplets[i++] = kvu.hasNewValue() ? kvu.getNewValue() : null;
          }
          output.updateAttributes(new AttributesUpdateImpl(triplets));
        }
      } else {
        // throw new
        // IllegalArgumentException("Unsupported operation component: " + c);
      }
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) {
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

   */
  public static DocOp setAttribute(int size, int location, String name, String oldValue,
      String newValue) {
    return new SimplifyingDocOpBuilder()
        .retain(location)
        .updateAttributes(new AttributesUpdateImpl(name, oldValue, newValue))
        .retain(size - location - 1)
        .build();
  }
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

            return pickRandomNonNullMappedElement(r, p.getAttributeValues(),
                new Mapper<String, Pair<String, String>>() {
              @Override
              public Pair<String, String> map(String value) {
                Attributes b = finalAttrAccu.updateWith(
                    new AttributesUpdateImpl(name, null, value));
                assert b != finalAttrAccu; // assert non-destructiveness
                ValidationResult v = checker.check(b);
                if (valid && !v.isValid() || !valid && v.isIllFormed()) {
                  return null;
                } else {
                  return Pair.of(name, value);
                }
              }
            });
          }
        });
        if (newAttr == null) {
          return attrAccu;
        }
        attrAccu = attrAccu.updateWith(
            new AttributesUpdateImpl(newAttr.getFirst(), null, newAttr.getSecond()));
      }
      return attrAccu;
    }
View Full Code Here

TOP

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

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.