public Graph copy() { WeightedArcSet list = new WeightedArcSet(); Constructor[] cons = WeightedArc.class.getDeclaredConstructors(); for (int i = 0; i < cons.length; i++) cons[i].setAccessible(true); ArcLabelledNodeIterator it = graph.nodeIterator(); while (it.hasNext()) { Integer aux1 = it.nextInt(); Integer aux2 = null; ArcLabelledNodeIterator.LabelledArcIterator suc = it.successors(); while ((aux2 = suc.nextInt()) != null && aux2 >= 0 && (aux2 < graph.numNodes())) try { if (commit++ % COMMIT_SIZE == 0) { list.commit(); } WeightedArc arc = (WeightedArc) cons[0].newInstance(aux2, aux1, suc.label().getFloat()); list.add(arc); } catch (Exception ex) { throw new Error(ex); } } Graph result = new Graph(list.toArray(new WeightedArc[0])); result.nodes.clear(); result.nodesReverse.clear(); for (Integer n : this.nodes.keySet()) { if (commit++ % COMMIT_SIZE == 0) { result.commit(); } result.nodesReverse.put(this.nodes.get(n), n); result.nodes.put(n, this.nodes.get(n)); } return result; }