if (oldRootObject == null && jsonNodes != null) {
return parse(jsonNodes);
}
JsonTreeNode root = oldRootObject;
JsonTreeNode parent = null;
JsonTreeNode head = root;
List<Integer> childIterStack = new ArrayList<Integer>();
try {
Integer childIter = 0;
for (JsonNode jsonNode : jsonNodes) {
//System.out.println(jsonNode);
if (isNodeOfType(jsonNode, JsonType.End)) {
// TODO: Check no more children if so remove
List<JsonTreeNode> nodesToRemove = new LinkedList<JsonTreeNode>();
while(childIter < parent.getChildren().size()) {
head = parent.getChildren().get(childIter);
nodesToRemove.add(head);
childIter++;
}
//System.out.println(nodesToRemove.size());
for (JsonTreeNode nodeToRemove: nodesToRemove) {
nodeToRemove.removeFromParent();
}
if (childIterStack.size() > 0) {
childIter = childIterStack.remove(0);
} else {
childIter = root.getChildren().size();
}
parent = parent.getParent();
if (parent == null) {
parent = root;
}
continue;
}
if (parent != null && childIter < parent.getChildren().size()) {
head = parent.getChildren().get(childIter);
//System.out.println("Next");
childIter++;
} else if (head != root || (head == root && parent != null)) {
//System.out.println("Null");
head = null;
}
if (head == null) {
head = new JsonTreeNode(jsonNode, parent);
parent.addChild(head);
childIter++;
}
if (!jsonNode.equals(head.getJsonNode())) {
head.setJsonNode(jsonNode);
}
if (isNodeOfType(jsonNode, JsonType.Object, JsonType.Array)) {
parent = head;
childIterStack.add(0, childIter);
childIter = 0;
} else {
if (head.hasChildren()) {
head.clearChildren();
}
}
}
// System.out.println("returning");
} catch (Exception e) {