Package com.goodow.realtime.json

Examples of com.goodow.realtime.json.JsonArray


    if (childOrNull == null) {
      return;
    }
    if (childOrNull.getNumber(0) == JsonSerializer.REFERENCE_TYPE) {
      String childId = childOrNull.getString(1);
      JsonArray list = parents.getArray(childId);
      if (isAdd) {
        if (list == null) {
          list = Json.createArray();
          parents.set(childId, list);
        }
        list.push(parentId);
      } else {
        assert list != null && list.indexOf(parentId) != -1;
        list.removeValue(parentId);
        if (list.length() == 0) {
          parents.remove(childId);
        }
      }
    }
  }
View Full Code Here


  void transformCursor(final AbstractListComponent op, final String userId,
                       final String sessionId) {
    if (indexReferences == null) {
      return;
    }
    JsonArray cursors = indexReferences.getArray(op.id);
    if (cursors != null) {
      cursors.forEach(new ListIterator<String>() {
        @Override
        public void call(int idx, String indexReferenceId) {
          IndexReferenceImpl indexReference = getObject(indexReferenceId);
          int currentIndex = indexReference.index();
          int newIndex = op.transformIndexReference(currentIndex, true,
View Full Code Here

  private void registerIndexReference(String indexReference, String referencedObject) {
    if (indexReferences == null) {
      indexReferences = Json.createObject();
    }
    JsonArray list = indexReferences.getArray(referencedObject);
    if (list == null) {
      list = Json.createArray();
      indexReferences.set(referencedObject, list);
    }
    list.push(indexReference);
  }
View Full Code Here

  @Override public Registration onValuesSet(Handler<ValuesSetEvent> handler) {
    return addEventListener(EventType.VALUES_SET, handler, false);
  }

  @Override public JsonArray asArray() {
    final JsonArray objects = Json.createArray();
    snapshot.forEach(new ListIterator<JsonArray>() {
      @Override
      public void call(int index, JsonArray value) {
        objects.push(get(index));
      }
    });
    return objects;
  }
View Full Code Here

  }

  @Override
  public int indexOf(Object value, Comparator<Object> opt_comparator) {
    if (opt_comparator == null) {
      JsonArray serializedValue;
      try {
        serializedValue = JsonSerializer.serializeObject(value);
      } catch (ClassCastException e) {
        return -1;
      }
View Full Code Here

    assert values != null;
    checkIndex(index, true);
    if (values.length() == 0) {
      return;
    } else {
      JsonArray array = JsonSerializer.serializeObjects(values);
      JsonInsertComponent op = new JsonInsertComponent(id, index, array);
      consumeAndSubmit(op);
    }
  }
View Full Code Here

  }

  @Override
  public int lastIndexOf(Object value, Comparator<Object> opt_comparator) {
    if (opt_comparator == null) {
      JsonArray serializedValue;
      try {
        serializedValue = JsonSerializer.serializeObject(value);
      } catch (ClassCastException e) {
        return -1;
      }
View Full Code Here

  @Override public void removeRange(int startIndex, int endIndex) {
    if (startIndex < 0 || startIndex >= endIndex || endIndex > length()) {
      throw new ArrayIndexOutOfBoundsException("StartIndex: " + startIndex + ", EndIndex: "
          + endIndex + ", Size: " + length());
    }
    JsonArray values = subValues(startIndex, endIndex - startIndex);
    JsonDeleteComponent op = new JsonDeleteComponent(id, startIndex, values);
    consumeAndSubmit(op);
  }
View Full Code Here

    if (values.length() == 0) {
      throw new UnsupportedOperationException(
          "At least one value must be specified for a set mutation.");
    }
    checkIndex(index + values.length(), true);
    JsonArray oldValues = subValues(index, values.length());
    JsonArray newValues = JsonSerializer.serializeObjects(values);
    if (oldValues.equals(newValues)) {
      return;
    }
    JsonReplaceComponent op = new JsonReplaceComponent(id, index, oldValues, newValues);
    consumeAndSubmit(op);
View Full Code Here

    removeRange(length, total);
  }

  @Override
  public JsonArray toJson() {
    final JsonArray json = Json.createArray();
    snapshot.forEach(new ListIterator<JsonArray>() {
      @Override
      public void call(int index, JsonArray value) {
        Object val = get(index);
        if (val == null) {
          json.push(null);
        } else if (val instanceof CollaborativeObjectImpl) {
          json.push(((CollaborativeObject) val).toJson());
        } else {
          json.push(snapshot.getArray(index).get(1));
        }
      }
    });
    return json;
  }
View Full Code Here

TOP

Related Classes of com.goodow.realtime.json.JsonArray

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.