Graphs { public static <V, E> UndirectedGraph<V, E> undirectedSubgraph(Graph<V, E> sup, Collection<V> nodes) { UndirectedGraph<V, E> sub = new UndirectedSparseGraph<V, E>(); List<V> nList = new ArrayList<V> (nodes); for (int i = 0; i < nList.size(); i++) for (int j = i + 1; j < nList.size(); j++) if (sup.isNeighbor(nList.get(i), nList.get(j))) sub.addEdge(getEdge(sup, nList.get(i), nList.get(j)), nList.get(i), nList.get(j)); return sub; }  static UndirectedGraph<Integer, Integer> singLine(File file); static UndirectedGraph<Vertex<Integer>, Edge<Integer>> intGraphFromTSV(File file); static DirectedGraph<Vertex<Integer>, Edge<Integer>> intDirectedGraphFromTSV(File file); static UndirectedGraph<Vertex<String>, Edge<String>> graphFromTSV(File file); static DirectedGraph<Vertex<String>, Edge<String>> graphFromRDF(File rdfFile); static DirectedGraph<Vertex<String>, Edge<String>> graphFromRDF(File rdfFile, RDFFormat format); static DirectedGraph<Vertex<String>, Edge<String>> graphFromRDF(
			File rdfFile,
			RDFFormat format,
			List<String> vWhiteList,
			List<String> eWhiteList); static BufferedImage image(Graph<V, E> graph, int width, int height); static void removeVerticesAndEdges(DirectedGraph<Vertex<String>, Edge<String>> graph, List<String> vBlackList, List<String> eBlackList); static boolean matches(String string, List<Pattern> patterns); static UndirectedGraph<V, E> undirectedSubgraph(Graph<V, E> sup, Collection<V> nodes); static E getEdge(Graph<V, E> graph, V v1, V v2); static double clusteringCoefficient(Graph<V, E> graph);  }
@Test public void testSubGraph() { Graph<String, String> graph = new UndirectedSparseGraph<String, String>(); graph.addEdge("0", "a", "b"); graph.addEdge("1", "b", "c"); graph.addEdge("2", "c", "d"); graph.addEdge("3", "d", "e"); graph.addEdge("4", "e", "a"); graph.addEdge("5", "a", "f"); graph.addEdge("6", "f", "g"); graph.addEdge("7", "g", "h"); graph.addEdge("8", "h", "i"); graph.addEdge("9", "i", "j"); graph.addEdge("10", "j", "k"); Graph<String, String> sub = Graphs.undirectedSubgraph(graph, Arrays.asList("a", "b", "c", "k", "j", "e")); System.out.println(sub); }