}
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);
}