Package org.waveprotocol.wave.model.util

Examples of org.waveprotocol.wave.model.util.StringSet$StringPredicate


  public ReadableStringSet nextLocation() {
    if (!hasNext()) {
      throw new NoSuchElementException();
    }

    StringSet currentKeys = CollectionUtils.createStringSet();

    currentLocation = locations.peek().location;

    do {
      KeyLocation keyLocation = locations.remove();
      currentKeys.add(keyLocation.key);
      advance(keyLocation);
    } while (!locations.isEmpty() && locations.peek().location == currentLocation);

    return currentKeys;
  }
View Full Code Here


  // unstrip keys - cover everything (both skipped and unskipped keys)
  public void testUnstripKeys() {
    useDocument("<line/>abcd", "link:L:4:6", "spell:S:5:7");
    PasteAnnotationLogic<Node, Element, Text> logic = initDefault();
    final StringSet ended = CollectionUtils.createStringSet();
    Nindo.Builder builder = new Nindo.Builder() {
      @Override public void endAnnotation(String key) {
        ended.add(key);
      }
    };

    ReadableStringSet keyCheck = CollectionUtils.newStringSet("A", "B", "C");
    ReadableStringSet toIgnore = CollectionUtils.newStringSet("B", "D");
    logic.unstripKeys(builder, keyCheck, toIgnore);

    assertEquals(2, ended.countEntries());
    assertTrue(ended.contains("A"));
    assertFalse(ended.contains("B"));
    assertTrue(ended.contains("C"));
    assertFalse(ended.contains("D"));
  }
View Full Code Here

    //   should be added to test left-alignment too.
    useDocument("howdy", "A:a:5:7", "X:x:2:8");
    useCaretAnnotations("X:?", "Y:y");

    // caret annotation already exists, don't supplement:
    StringSet keys = CollectionUtils.createStringSet();
    keys.add("X");
    supplementAnnotations(doc, caret, keys, 5, false);
    assertTrue(caret.hasAnnotation("X"));
    assertEquals("?", caret.getAnnotation("X")); // keeps the caret annotation
    assertTrue(caret.hasAnnotation("Y"));

    // subset of annotations are supplemented, make sure new value is right:
    caret.removeAnnotation("X");
    keys.add("A");
    supplementAnnotations(doc, caret, keys, 5, false);
    assertFalse(caret.hasAnnotation("X"));
    assertTrue(caret.hasAnnotation("A"));
    assertEquals("a", caret.getAnnotation("A"));
  }
View Full Code Here

  /**
   * Removes entire saved object.
   */
  void clear() {
    final StringSet keys = CollectionUtils.createStringSet();
    gadgetSupplements.each(new ProcV<GadgetState>() {
      @Override
      public void apply(String key, GadgetState value) {
        keys.add(key);
      }
    });
    keys.each(new Proc() {
      @Override
      public void apply(String key) {
        gadgetSupplements.get(key).remove();
      }
    });
View Full Code Here

    return annotationsOp;
  }

  @Override
  public StringSet knownKeys() {
    final StringSet knownKeys = CollectionUtils.createStringSet();
    annotations.knownKeysLive().each(new Proc() {
      @Override
      public void apply(String key) {
        if (!Annotations.isLocal(key)) {
          knownKeys.add(key);
        }
      }
    });
    return knownKeys;
  }
View Full Code Here

        // and annoying way for now.

        final List<AnnotationEvent> events = new ArrayList<AnnotationEvent>();
        final Box<ReadableStringMap<String>> annotations = Box.create();
        int currentLocationBackup = currentLocation;
        final StringSet open = CollectionUtils.createStringSet();
        for (AnnotationInterval<String> i :
            annotationIntervals(currentLocation, finalLocation, requestedKeys)) {
          currentLocation = i.start();
          annotations.boxed = i.annotations();
          requestedValues.each(new ProcV<String>() {
            public void apply(String key, String value) {
              String oldVal = annotations.boxed.get(key, null);
              if (ValueUtils.notEqual(value, oldVal)) {
                events.add(new AnnotationStartEvent(currentLocation, key, oldVal));
                open.add(key);
              } else if (open.contains(key)) {
                events.add(new AnnotationEndEvent(currentLocation, key));
                //assert open.contains(key);
                open.remove(key);
              }
            }
          });
        }
        open.each(new Proc() {
          @Override
          public void apply(String key) {
            events.add(new AnnotationEndEvent(finalLocation, key));
          }
        });
View Full Code Here

     */
    // HACK(danilatos): This code is inefficient and does not belong in indexed document.
    private List<AnnotationEvent> deleteAnnotations(int size) {
      final List<AnnotationEvent> events = new ArrayList<AnnotationEvent>();

      final StringSet open = CollectionUtils.createStringSet();
      final StringMap<String> deletionInherit = CollectionUtils.createStringMap();
      deletionValues.each(new ReadableStringMap.ProcV<String>() {
        @Override
        public void apply(String key, String value) {
          deletionInherit.put(key, value);
        }
      });

      final int start = currentLocation;
      final int end = currentLocation + size;

      for (AnnotationInterval<String> i : annotationIntervals(start, end, null)) {
        assert i.end() > start;
        assert i.start() < end;
        final int realStart = Math.max(start, i.start());
        deletionInherit.each(new ReadableStringMap.ProcV<String>() {
          @Override
          public void apply(String key, String value) {
            events.add(
                new AnnotationStartEvent(realStart, key, getAnnotation(realStart, key)));
            open.add(key);
          }
        });
        i.annotations().each(new ReadableStringMap.ProcV<String>() {
          @Override
          public void apply(String key, String value) {
            if (!deletionInherit.containsKey(key)) {
              events.add(
                  new AnnotationStartEvent(realStart, key, value));
              open.add(key);
            }
          }
        });
      }

      // Produce endAnnotation calls for every annotation at the end.
      open.each(new StringSet.Proc() {
        @Override
        public void apply(String key) {
          events.add(new AnnotationEndEvent(end, key));
        }
      });
View Full Code Here

    }
  }

  public void addChildren(String parentType, String ... childTypes) {
    parentType = fixType(parentType);
    StringSet permitted = permittedChildren.get(parentType);
    if (permitted == null) {
      permittedChildren.put(parentType, permitted = CollectionUtils.createStringSet());
    }
    for (String childType : childTypes) {
      checkNotTopLevel(childType);
      permitted.add(childType);
    }
  }
View Full Code Here

    }

    if (permittedValues.length == 0) {
      attrs.put(attrName, null);
    } else {
      StringSet values = attrs.get(attrName);
      if (values == null) {
        attrs.put(attrName, values = CollectionUtils.createStringSet());
      }

      for (String value : permittedValues) {
        values.add(value);
      }
    }
  }
View Full Code Here

  @Override
  public boolean permitsChild(String parentType, String childType) {
    parentType = fixType(parentType);
    checkNotTopLevel(childType);
    StringSet permitted = permittedChildren.get(parentType);
    return permitted != null && permitted.contains(childType);
  }
View Full Code Here

TOP

Related Classes of org.waveprotocol.wave.model.util.StringSet$StringPredicate

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.