class GraphUtil {

    public static <V, E> void removeIsolatedVertices(UndirectedGraph<V, E> graph) {
        Objects.requireNonNull(graph, "Graph is null.");

        TIntSet connectedVertices = new TIntHashSet();
        for (int e : graph.getEdges()) {
            connectedVertices.add(graph.getEdgeVertex1(e));
            connectedVertices.add(graph.getEdgeVertex2(e));
        }

        for (int v : graph.getVertices()) {
            if (!connectedVertices.contains(v) && graph.getVertexObject(v) == null) {
                graph.removeVertex(v);
            }
        }
    }

    private  GraphUtil();

}