import org.jgrapht.graph.SimpleWeightedGraph;
import org.jgrapht.nio.graphml.GraphMLImporter;

import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

public class GraphFileReader {

    private String filename;
    private SimpleWeightedGraph graph;

    public GraphFileReader(String filename, SimpleWeightedGraph graph) {
        this.filename = filename;
        this.graph = graph;

        try(//don't need to close reader bc of try-with-resources auto-closing
            BufferedReader reader = Files.newBufferedReader(Path.of(filename));
        ){
            GraphMLImporter<SimpleWeightedGraph, BufferedReader> importer = new GraphMLImporter<>();
            importer.importGraph(graph, reader);
        }
        catch (IOException ex) {
            System.out.println("Graph file " + filename + " not found.");
            System.err.println(ex);
        }
    }

    public SimpleWeightedGraph getGraph() { return graph; }

}
