### Question:
LightUGraph implements UGraph<L>, FastWalkable<L, UNode<L>> { public static <L> LightUGraph<L> copy(Graph<L> graph) { if(graph instanceof LightUGraph) { LightUGraph<L> other = (LightUGraph<L>) graph; LightUGraph<L> copy = new LightUGraph<L>(); copy.labels = new ArrayList<L>(other.labels); copy.neighbors = new ArrayList<List<Integer>>(other.neighbors.size()); for(List<Integer> nb : other.neighbors) copy.neighbors.add(new ArrayList<Integer>(nb)); copy.numLinks = other.numLinks; copy.hash = other.hash; copy.modCount++; copy.nodeModCount++; if(other.hashMod == null) copy.hashMod = null; else copy.hashMod = other.hashMod == other.modCount ? copy.modCount : copy.modCount - 1; copy.sorted = other.sorted; return copy; } LightUGraph<L> copy = new LightUGraph<L>(graph.size()); for(Node<L> node : graph.nodes()) copy.add(node.label()); for(Link<L> link : graph.links()) copy.get(link.first().index()).connect(copy.get(link.second().index())); copy.compact(0); return copy; } LightUGraph();  LightUGraph(int capacity); @Override int size(); @Override long numLinks(); @Override UNode<L> node(L label); @Override Collection<? extends UNode<L>> nodes(L label); @Override List<? extends UNode<L>> nodes(); @Override Iterable<? extends ULink<L>> links(); @Override UNode<L> add(L label); @Override Set<L> labels(); @Override boolean connected(L from, L to); @Override long state(); String toString(); void compact(int margin); void sort(); static LightUGraph<L> copy(Graph<L> graph); @Override int hashCode(); boolean equals(Object other); @Override UNode<L> get(int i); @SuppressWarnings("unchecked") @Override Class<? extends UGraph<L>> level(); @Override List<UNode<L>> neighborsFast(Node<L> node); static final int NEIGHBOR_CAPACITY; }### Answer:
@Test public void testCopy() { UGraph<String> graph = new MapUTGraph<String, String>(); UNode<String> a = graph.add("a"); UNode<String> b = graph.add("b"); UNode<String> c = graph.add("c"); a.connect(a); b.connect(c); c.connect(a); a.connect(c); a.connect(c); { int numLinks = 0; for(Link<String> link : graph.links()) numLinks++; assertEquals(5, numLinks); assertEquals(graph.numLinks(), numLinks); } graph = LightUGraph.copy(graph); { int numLinks = 0; for(Link<String> link : graph.links()) numLinks++; assertEquals(5, numLinks); assertEquals(graph.numLinks(), numLinks); } graph = LightUGraph.copy(graph); { int numLinks = 0; for(Link<String> link : graph.links()) numLinks++; assertEquals(5, numLinks); assertEquals(graph.numLinks(), numLinks); } }