Copies all nodes/edges into the given empty graph, preserving their ids and properties.
(Graph destination)
| 394 | |
| 395 | /** Copies all nodes/edges into the given empty graph, preserving their ids and properties. */ |
| 396 | public void copyTo(Graph destination) { |
| 397 | if (destination.nodeCount() > 0) throw new AssertionError("destination graph must be empty, but isn't"); |
| 398 | nodes().forEachRemaining(node -> { |
| 399 | destination.addNode(node.id(), node.label(), PropertyHelper.toKeyValueArray(node.propertiesMap())); |
| 400 | }); |
| 401 | nodes().forEachRemaining( node -> { |
| 402 | NodeDb mapped = ((NodeRef<NodeDb>) destination.node(node.id())).get(); |
| 403 | |
| 404 | node.outE().forEachRemaining(edge -> { |
| 405 | NodeRef<?> other = (NodeRef<?>) destination.node(edge.inNode().id()); |
| 406 | mapped.storeAdjacentNode(Direction.OUT, edge.label(), other, PropertyHelper.toKeyValueArray(edge.propertiesMap())); |
| 407 | }); |
| 408 | node.inE().forEachRemaining(edge -> { |
| 409 | NodeRef<?> other = (NodeRef<?>) destination.node(edge.outNode().id()); |
| 410 | mapped.storeAdjacentNode(Direction.IN, edge.label(), other, PropertyHelper.toKeyValueArray(edge.propertiesMap())); |
| 411 | }); |
| 412 | |
| 413 | }); |
| 414 | } |
| 415 | |
| 416 | public void remove(Node node) { |
| 417 | final NodeRef nodeRef = getNodeRef(node); |