public void saveGraph(Graph graph, boolean isFilterGraph) { int Counter = 0; JsonObject attrJson; // clear existing graph if (!isFilterGraph) { nodesMap.clear(); edgesMap.clear(); } else { nodesMapFilter.clear(); edgesMapFilter.clear(); } /* * Nodes Iteration */ for (Node node : graph.getNodes()) { attrJson = new JsonObject(); for (String attrKey : node.getAttributeKeys()) { attrJson.put(attrKey, node.getAttribute(attrKey)); } attrJson.put("x", node.x()); attrJson.put("y", node.y()); attrJson.put("cR", node.r()); attrJson.put("cG", node.g()); attrJson.put("cB", node.b()); attrJson.put("size", node.size()); if (!isFilterGraph) { nodesMap.put(Counter++, attrJson); } else { nodesMapFilter.put(Counter++, attrJson); } } Counter = 0; /* * Edges Iteration */ for (Edge edge : graph.getEdges()) { attrJson = new JsonObject(); for (String attrKey : edge.getAttributeKeys()) { attrJson.put(attrKey, edge.getAttribute(attrKey)); } attrJson.put("source", edge.getSource().getId()); attrJson.put("target", edge.getTarget().getId()); attrJson.put("cR", edge.r()); attrJson.put("cG", edge.g()); attrJson.put("cB", edge.b()); attrJson.put("size", edge.getWeight()); if (!isFilterGraph) { edgesMap.put(Counter++, attrJson); } else { edgesMapFilter.put(Counter++, attrJson); } } }