public static < V , E > Graph < V , E > loadGraph ( String path , EdgeLineProcessor < E > lineProcessor , VertexFactory < V > vertexFactory , int numVertices , boolean allowMultipleEdges ) throws IOException { Graph < V , E > graph = new Graph <> ( numVertices , allowMultipleEdges , vertexFactory ) ; try ( BufferedReader br = new BufferedReader ( new FileReader ( new File ( path ) ) ) ) { String line ; while ( ( line = br . readLine ( ) ) != null ) { Edge < E > edge = lineProcessor . processLine ( line ) ; if ( edge != null ) { graph . addEdge ( edge ) ; } } } return graph ; }
Load a graph into memory using a given EdgeLineProcessor . Assume one edge per line