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

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


      @Override
      RandomizerOperationComponent generate(final DocOpAutomaton a, boolean valid, Stage stage) {
        if (stage != Stage.S1_UNRESTRICTED) {
          return null;
        }
        final Attributes oldAttrs = a.currentElementStartAttributes();
        if (oldAttrs == null) {
          if (valid) {
            return null;
          }
        }
        if (!valid) {
          // TODO: bring this back.
          // 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);
          }
        });

        if (u == null) {
          return null;
        }

        final Attributes newAttrs = oldAttrs.updateWith(u);
        return new RandomizerOperationComponent() {
          @Override
          public void apply(DocOpAutomaton a) {
            a.doReplaceAttributes(oldAttrs, newAttrs);
          }
View Full Code Here


      @Override
      RandomizerOperationComponent generate(final DocOpAutomaton a, boolean valid, Stage stage) {
        if (stage != Stage.S1_UNRESTRICTED) {
          return null;
        }
        final Attributes oldAttrs = a.currentElementStartAttributes();
        if (oldAttrs == null) {
          if (valid) {
            return null;
          }
        }
View Full Code Here

  @Override
  public void add(T value) {
    Preconditions.checkNotNull(value, "value must not be null");
    // Add an element to represent the value
    if (!valueElements.containsKey(value)) {
      Attributes attrs = new AttributesImpl(valueAttrName, serializer.toString(value));
      getDocument().createChildElement(container, entryTagName, attrs);
      deleteObsoleteElements();
    }
  }
View Full Code Here

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

                Attributes attrs = generateRandomAttributes(valid,
                    new AttributesChecker() {
                      @Override
                      public ValidationResult check(Attributes attrs) {
                        return a.checkElementStart(tag, attrs, null);
                      }
                    });
                if (attrs == null) {
                  return null;
                } else {
                  return Pair.of(tag, attrs);
                }
              }
            });
        if (args == null) {
          return null;
        }
        final String tag = args.getFirst();
        final Attributes attributes = args.getSecond();
        return new RandomizerMutationComponent() {
          @Override
          public ValidationResult check(ViolationCollector v) {
            return a.checkElementStart(tag, attributes, v);
          }
View Full Code Here

        extends RandomMutationComponentGenerator {
      abstract ValidationResult check(Attributes attrs, ViolationCollector v);
      abstract void apply(Attributes attrs);
      @Override
      RandomizerMutationComponent generate(boolean valid) {
        final Attributes attrs = generateRandomAttributes(valid, new AttributesChecker() {
          @Override
          public ValidationResult check(Attributes attrs) {
            return AttributesOnlyRandomMutationComponentGenerator.this.check(attrs, null);
          }
        });
View Full Code Here

  // only defined for open
  private Attributes effectiveDocSymbolAttributes() {
    switch (effectiveDocSymbol()) {
      case OPEN: {
        Attributes attributes = doc.attributesAt(effectivePos);
        assert attributes != null;
        return attributes;
      }
      default:
        throw new IllegalStateException("not at element start");
View Full Code Here

    // validity
    if (effectiveDocSymbol() != DocSymbol.OPEN) { return noElementStartToChangeAttributes(v); }
    String type = effectiveDocSymbolTag();
    assert type != null;
    Attributes oldAttrs = effectiveDocSymbolAttributes();
    for (int i = 0; i < u.changeSize(); i++) {
      String key = u.getChangeKey(i);
      String oldValue = u.getOldValue(i);
      if (!equal(oldValue, oldAttrs.get(key))) { return oldAttributesDifferFromDocument(v); }
    }
    {
      ValidationResult r = checkAnnotationsForRetain(v, 1);
      if (!r.isValid()) { return r; }
    }
View Full Code Here

    // validity
    if (effectiveDocSymbol() != DocSymbol.OPEN) { return noElementStartToChangeAttributes(v); }
    String type = effectiveDocSymbolTag();
    assert type != null;
    Attributes actualOldAttrs = effectiveDocSymbolAttributes();
    if (!attributesEqual(actualOldAttrs, oldAttrs)) { return oldAttributesDifferFromDocument(v); }
    {
      ValidationResult r = checkAnnotationsForRetain(v, 1);
      if (!r.isValid()) { return r; }
    }
View Full Code Here

        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);
              }
            });
        if (u == null) {
          return null;
        } else {
          final Attributes attributes = Attributes.EMPTY_MAP.updateWith(u);
          return new RandomizerOperationComponent() {
            @Override
            public ValidationResult check(DocOpAutomaton a, ViolationCollector v) {
              return a.checkElementStart(tag, attributes, v);
            }
View Full Code Here

    interface AttributesChecker {
      ValidationResult check(Attributes attrs);
    }

    Attributes generateRandomAttributes(final boolean valid, final AttributesChecker checker) {
      Attributes attrAccu = Attributes.EMPTY_MAP;
      if (valid && !checker.check(Attributes.EMPTY_MAP).isValid()
          || !valid && checker.check(Attributes.EMPTY_MAP).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(attrAccu).isValid()) {
          assert attrAccu.isEmpty();
          attrAccu = pickRandomNonNullMappedElement(r,
              p.getAttributeNames(), new Mapper<String, Attributes>() {
            @Override
            public Attributes map(final String name) {
              return pickRandomNonNullMappedElement(r, p.getAttributeValues(),
                  new Mapper<String, Attributes> () {
                @Override
                public Attributes map(String value) {
                  Attributes b = new AttributesImpl(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 (attrAccu == null) {
            return null;
          }
        }
        assert !checker.check(attrAccu).isValid();
        // Flip a coin and terminate if the number of attributes was really
        // supposed to be zero.
        if (r.nextBoolean()) {
          return attrAccu;
        }
      }
      while (r.nextBoolean()) {
        final Attributes finalAttrAccu = attrAccu;
        Pair<String, String> newAttr = pickRandomNonNullMappedElement(r,
            p.getAttributeNames(), new Mapper<String, Pair<String, String>>() {
          @Override
          public Pair<String, String> map(final String name) {
            if (finalAttrAccu.containsKey(name)) {
              return null;
            }
            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;
View Full Code Here

TOP

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

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.