Creates a mutable copy of {@code graph} with the same nodes and edges.
(Graph<N> graph)
| 638 | |
| 639 | /** Creates a mutable copy of {@code graph} with the same nodes and edges. */ |
| 640 | public static <N> MutableGraph<N> copyOf(Graph<N> graph) { |
| 641 | MutableGraph<N> copy = GraphBuilder.from(graph).expectedNodeCount(graph.nodes().size()).build(); |
| 642 | for (N node : graph.nodes()) { |
| 643 | copy.addNode(node); |
| 644 | } |
| 645 | for (EndpointPair<N> edge : graph.edges()) { |
| 646 | copy.putEdge(edge.nodeU(), edge.nodeV()); |
| 647 | } |
| 648 | return copy; |
| 649 | } |
| 650 | |
| 651 | /** Creates a mutable copy of {@code graph} with the same nodes, edges, and edge values. */ |
| 652 | public static <N, V> MutableValueGraph<N, V> copyOf(ValueGraph<N, V> graph) { |