public static < V , E > Graph < V , E > loadGraph ( String vertexFilePath , String edgeFilePath , VertexLoader < V > vertexLoader , EdgeLineProcessor < E > edgeLineProcessor , boolean allowMultipleEdges ) throws IOException { //Assume vertices are in one file //And edges are in another file List < Vertex < V >> vertices = vertexLoader . loadVertices ( vertexFilePath ) ; Graph < V , E > graph = new Graph <> ( vertices , allowMultipleEdges ) ; try ( BufferedReader br = new BufferedReader ( new FileReader ( new File ( edgeFilePath ) ) ) ) { String line ; while ( ( line = br . readLine ( ) ) != null ) { Edge < E > edge = edgeLineProcessor . processLine ( line ) ; if ( edge != null ) { graph . addEdge ( edge ) ; } } } return graph ; }
Load graph assuming vertices are in one file and edges are in another file .