DirectedWeightedMultigraph<Node, DefaultLink> graph =
new DirectedWeightedMultigraph<Node, DefaultLink>(LabeledLink.class);
Node n, source, target;
DefaultLink l;
Double[] weight = new Double[1];
HashMap<String, Node> idToNodes = new HashMap<String, Node>();
reader.beginObject();
while (reader.hasNext()) {
String key = reader.nextName();
if (key.equals("nodes") && reader.peek() != JsonToken.NULL) {
reader.beginArray();
while (reader.hasNext()) {
n = readNode(reader);
if (n != null) {
idToNodes.put(n.getId(), n);
graph.addVertex(n);
}
}
reader.endArray();
} else if (key.equals("links") && reader.peek() != JsonToken.NULL) {
reader.beginArray();
while (reader.hasNext()) {
l = readLink(reader, weight);
if (l != null) {
source = idToNodes.get(LinkIdFactory.getLinkSourceId(l.getId()));
target = idToNodes.get(LinkIdFactory.getLinkTargetId(l.getId()));
if (source != null && target != null) {
graph.addEdge(source, target, l);
if (weight[0] != null) graph.setEdgeWeight(l, weight[0].doubleValue());
}
}