Rename run method to runBuilder in InteractiveConsole and update references; refactor file handling in Plot and SimulationBuilder for improved clarity and consistency
This commit is contained in:
@@ -39,7 +39,7 @@ public class InteractiveConsole {
|
||||
/**
|
||||
* Run the interactive net builder.
|
||||
*/
|
||||
public Net run() {
|
||||
public Net runBuilder() {
|
||||
while (true) {
|
||||
try {
|
||||
var choice = choose(this.net + "\nChoose the next step to do:",
|
||||
|
||||
@@ -31,7 +31,7 @@ public class Main {
|
||||
var plot = new Plot(csv);
|
||||
plot.show();
|
||||
}
|
||||
case "interactive" -> new InteractiveConsole().run();
|
||||
case "interactive" -> new InteractiveConsole().runBuilder();
|
||||
default -> exit("Invalid program!");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
package net.berack.upo.valpre;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.InputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
@@ -194,23 +191,4 @@ public class Parameters {
|
||||
throw new IllegalArgumentException("Invalid arguments");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file or the example file if it is present.
|
||||
*
|
||||
* @param file the file to get
|
||||
* @return the file or the example file
|
||||
* @throws FileNotFoundException if the file is not found
|
||||
*/
|
||||
public static InputStream getFileOrExample(String file) throws FileNotFoundException {
|
||||
if (file == null)
|
||||
return null;
|
||||
|
||||
if (file.startsWith("example")) {
|
||||
var resource = Parameters.class.getClassLoader().getResourceAsStream(file);
|
||||
if (resource != null)
|
||||
return resource;
|
||||
}
|
||||
return new FileInputStream(file);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,12 +41,7 @@ public class Plot {
|
||||
* @throws IOException if anything happens while reading the file
|
||||
*/
|
||||
public Plot(String csv) throws IOException {
|
||||
var stream = Parameters.getFileOrExample(csv);
|
||||
if (stream == null)
|
||||
throw new IllegalArgumentException("CSV file needed!");
|
||||
var results = CsvResult.loadResults(stream);
|
||||
stream.close();
|
||||
|
||||
var results = new CsvResult(csv).loadResults();
|
||||
this.summary = new Result.Summary(results);
|
||||
|
||||
var nodes = this.summary.getNodes().toArray(new String[0]);
|
||||
|
||||
@@ -37,10 +37,8 @@ public class SimulationBuilder {
|
||||
*/
|
||||
public SimulationBuilder(String netFile) throws IOException {
|
||||
try {
|
||||
var file = Parameters.getFileOrExample(netFile);
|
||||
this.net = Net.load(file);
|
||||
this.net = Net.load(netFile);
|
||||
this.confidences = new ConfidenceIndices(this.net);
|
||||
file.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new IllegalArgumentException("Net file needed!");
|
||||
} catch (KryoException e) {
|
||||
|
||||
@@ -141,7 +141,7 @@ public class TestInteractions {
|
||||
var inputs = String.join("\n", commands);
|
||||
var bytes = inputs.getBytes();
|
||||
var in = new ByteArrayInputStream(bytes);
|
||||
return new InteractiveConsole(out, in).run();
|
||||
return new InteractiveConsole(out, in).runBuilder();
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user