/** * * Creates a new graph object containing the nodes of the argument It does not clone the nodes / * edges. It just creates a new graph and adds them to the collection of graph's nodes and edges * * @return a graph object */ @SuppressWarnings("unchecked") public <G extends EvolutionGraph<V, E>> G toGraphE(List<V> nodes) { G subGraph; try { subGraph = (G) this.getClass().newInstance(); for (V vertex : nodes) { subGraph.addVertex(vertex); Collection<E> incidentEdges = this.getIncidentEdges(vertex); for (E edge : incidentEdges) { Pair<V> endpoints = this.getEndpoints(edge); if (nodes.containsAll(endpoints)) { // put this edge into the subgraph subGraph.addEdge(edge, endpoints.getFirst(), endpoints.getSecond()); } } } return subGraph; } catch (InstantiationException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } return null; }