Control verbose output

This commit is contained in:
2022-02-27 16:03:57 -06:00
parent 40c743308b
commit 3d1f8668ee

View File

@@ -1,3 +1,5 @@
import org.jgrapht.Graph;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@@ -7,6 +9,7 @@ public class GraphDataObjectWriter {
private GraphWithMapData data; private GraphWithMapData data;
private String filename; private String filename;
private boolean verbose = true;
public GraphDataObjectWriter(String filename, GraphWithMapData data) { public GraphDataObjectWriter(String filename, GraphWithMapData data) {
if(!filename.matches(".*\\.ser")){ if(!filename.matches(".*\\.ser")){
@@ -16,13 +19,24 @@ public class GraphDataObjectWriter {
this.data = data; this.data = data;
} }
public GraphDataObjectWriter(String filename, GraphWithMapData data, boolean verbose) {
this.verbose = verbose;
if(!filename.matches(".*\\.ser")){
filename = filename + ".ser";
}
this.filename = filename;
this.data = data;
}
public void writeDataToFile() { public void writeDataToFile() {
try (BufferedOutputStream bufferedOut = new BufferedOutputStream(new FileOutputStream(filename)); try (BufferedOutputStream bufferedOut = new BufferedOutputStream(new FileOutputStream(filename));
ObjectOutputStream out = new ObjectOutputStream(bufferedOut); ObjectOutputStream out = new ObjectOutputStream(bufferedOut);
){ ){
System.out.println("Writing graph and occupancy data to file. This may take some time."); if(verbose) {
System.out.println("File I/O time is not included in results."); System.out.println("Writing graph and occupancy data to file. This may take some time.");
System.out.println("File I/O time is not included in results.");
}
out.writeObject(data); out.writeObject(data);
} catch (IOException ex) { } catch (IOException ex) {
ex.printStackTrace(); ex.printStackTrace();