Examples of JzonArray


Examples of foodev.jsondiff.jsonwrap.JzonArray

      if (key.startsWith(MOD)) {
        JzonElement partialInstructions = entry.getValue();
        if (!partialInstructions.isJsonArray()) {
          throw new IllegalArgumentException();
        }
        JzonArray array = (JzonArray) partialInstructions;
        JzonElement applyTo;
        if (key.equals(MOD)) {
          applyTo = origEl;
        } else if (origEl.isJsonArray()) {
          int index = Integer.parseInt(key.substring(1));
          applyTo = ((JzonArray) origEl).get(index);
        } else {
          applyTo = ((JzonObject) origEl).get(key.substring(1));
        }
        for (int i = 0; i < array.size(); i++) {
          JzonElement partial = array.get(i);
          if (!partial.isJsonObject()) {
            throw new IllegalArgumentException();
          }
          Entry<String, JzonElement> childentry = ((JzonObject) partial).entrySet().iterator().next();
          String childKey = childentry.getKey();
View Full Code Here

Examples of foodev.jsondiff.jsonwrap.JzonArray

        leaf.children.add(child);
      }

    } else if (el.isJsonArray()) {

      JzonArray arr = (JzonArray) el;
      for (int i = 0, n = arr.size(); i < n; i++) {

        ArrNode newParent = new ArrNode(parent, i);

        // this array saves a reference to all arrnodes
        // which is used to adjust arr node indexes.
        arrs.put(newParent.doHash(true), newParent);

        Leaf child = findLeaves(newParent, arr.get(i), leaves, arrs);
        leaf.children.add(child);
      }

    }
    leaf.init();
View Full Code Here

Examples of foodev.jsondiff.jsonwrap.JzonArray

  }

  JsonDiff visitor;

  JzonArray createPatch(JzonObject patch) {
    JzonArray instructions = factory.createJsonArray();
    if (oper != Oper.DELETE) {
      checkCancellations();
      int i = 0, deletes = 0;
      for (Iterator<Leaf> it = newStructure.iterator(); it.hasNext();) {
        Leaf child = it.next();
        String key = child.parent.toString();
        String reIndexedKey = key;
        if (child.parent instanceof ArrNode) {
          ((ArrNode) child.parent).index = i - deletes;
          reIndexedKey = child.parent.toString();
        }
        JzonObject insert = factory.createJsonObject();
        boolean deeper = true;
        if (child.oper == Oper.INSERT) {
          insert.add("+" + reIndexedKey, child.val);
          instructions.insert(instructions.size(), insert);
          deeper = false;
        } else if (child.oper == Oper.SET) {
          insert.add(reIndexedKey, child.val);
          instructions.insert(instructions.size(), insert);
          deeper = false;
        } else if (child.oper == Oper.DELETE) {
          insert.addProperty("-" + reIndexedKey, 0);
          instructions.insert(instructions.size(), insert);
          deeper = false;
        }
        if (deeper) {
          JzonObject childPatch = factory.createJsonObject();
          JzonArray childInstructions = child.createPatch(childPatch);
          if (childInstructions.size() > 0) {
            if (visitor != null && !child.val.isJsonPrimitive() && !visitor.accept(child, childInstructions, childPatch)) {
              continue;
            }
            patch.add("~" + key, childInstructions);
          }
View Full Code Here

Examples of foodev.jsondiff.jsonwrap.JzonArray

    } else if (oper == Oper.SET) {
      patch.add(parent.toString(), val);
    } else if (oper == Oper.DELETE) {
      patch.add("-" + parent.toString(), val);
    } else {
      JzonArray childInstructions = createPatch(patch);
      if (childInstructions.size() > 0) {
        patch.add("~", childInstructions);
      }
    }
    return patch;
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.