DirectedGraph { public Set<Pair<T>> getEdges() { Set<Pair<T>> edges = new HashSet<Pair<T>>(); for (T from : _outboundEdges.keySet()) { for (T to : _outboundEdges.get(from)) edges.add(Tuples.pair(from, to)); } return edges; } DirectedGraph();  DirectedGraph(DirectedGraph<T> graph); Set<T> getNodes(); Set<Pair<T>> getEdges(); Set<T> getInboundNodes(T node); Set<T> getOutboundNodes(T node); boolean isConnected(T from, T to); void addNode(T node); void addEdge(T from, T to); void removeEdge(T from, T to); List<T> getTopologicalSort(Comparator<T> tieBreaker);  }
@Test public void testGetEdges() { DirectedGraph<String> graph = new DirectedGraph<String>(); Set<Pair<String>> e0 = graph.getEdges(); assertEquals(0, e0.size()); graph.addEdge("a", "b"); Set<Pair<String>> e1 = graph.getEdges(); assertEquals(1, e1.size()); assertTrue(e1.contains(Tuples.pair("a", "b"))); graph.addEdge("b", "c"); Set<Pair<String>> e2 = graph.getEdges(); assertEquals(2, e2.size()); assertTrue(e2.contains(Tuples.pair("a", "b"))); assertTrue(e2.contains(Tuples.pair("b", "c"))); graph.addEdge("b", "c"); Set<Pair<String>> e2b = graph.getEdges(); assertEquals(2, e2b.size()); assertTrue(e2b.contains(Tuples.pair("a", "b"))); assertTrue(e2b.contains(Tuples.pair("b", "c"))); graph.addEdge("c", "b"); Set<Pair<String>> e3 = graph.getEdges(); assertEquals(3, e3.size()); assertTrue(e3.contains(Tuples.pair("a", "b"))); assertTrue(e3.contains(Tuples.pair("b", "c"))); assertTrue(e3.contains(Tuples.pair("c", "b"))); graph.removeEdge("b", "c"); Set<Pair<String>> e4 = graph.getEdges(); assertEquals(2, e4.size()); assertTrue(e4.contains(Tuples.pair("a", "b"))); assertTrue(e4.contains(Tuples.pair("c", "b"))); }