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.
|
* Run the interactive net builder.
|
||||||
*/
|
*/
|
||||||
public Net run() {
|
public Net runBuilder() {
|
||||||
while (true) {
|
while (true) {
|
||||||
try {
|
try {
|
||||||
var choice = choose(this.net + "\nChoose the next step to do:",
|
var choice = choose(this.net + "\nChoose the next step to do:",
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ public class Main {
|
|||||||
var plot = new Plot(csv);
|
var plot = new Plot(csv);
|
||||||
plot.show();
|
plot.show();
|
||||||
}
|
}
|
||||||
case "interactive" -> new InteractiveConsole().run();
|
case "interactive" -> new InteractiveConsole().runBuilder();
|
||||||
default -> exit("Invalid program!");
|
default -> exit("Invalid program!");
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
package net.berack.upo.valpre;
|
package net.berack.upo.valpre;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
@@ -194,23 +191,4 @@ public class Parameters {
|
|||||||
throw new IllegalArgumentException("Invalid arguments");
|
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
|
* @throws IOException if anything happens while reading the file
|
||||||
*/
|
*/
|
||||||
public Plot(String csv) throws IOException {
|
public Plot(String csv) throws IOException {
|
||||||
var stream = Parameters.getFileOrExample(csv);
|
var results = new CsvResult(csv).loadResults();
|
||||||
if (stream == null)
|
|
||||||
throw new IllegalArgumentException("CSV file needed!");
|
|
||||||
var results = CsvResult.loadResults(stream);
|
|
||||||
stream.close();
|
|
||||||
|
|
||||||
this.summary = new Result.Summary(results);
|
this.summary = new Result.Summary(results);
|
||||||
|
|
||||||
var nodes = this.summary.getNodes().toArray(new String[0]);
|
var nodes = this.summary.getNodes().toArray(new String[0]);
|
||||||
|
|||||||
@@ -37,10 +37,8 @@ public class SimulationBuilder {
|
|||||||
*/
|
*/
|
||||||
public SimulationBuilder(String netFile) throws IOException {
|
public SimulationBuilder(String netFile) throws IOException {
|
||||||
try {
|
try {
|
||||||
var file = Parameters.getFileOrExample(netFile);
|
this.net = Net.load(netFile);
|
||||||
this.net = Net.load(file);
|
|
||||||
this.confidences = new ConfidenceIndices(this.net);
|
this.confidences = new ConfidenceIndices(this.net);
|
||||||
file.close();
|
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
throw new IllegalArgumentException("Net file needed!");
|
throw new IllegalArgumentException("Net file needed!");
|
||||||
} catch (KryoException e) {
|
} catch (KryoException e) {
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ public class TestInteractions {
|
|||||||
var inputs = String.join("\n", commands);
|
var inputs = String.join("\n", commands);
|
||||||
var bytes = inputs.getBytes();
|
var bytes = inputs.getBytes();
|
||||||
var in = new ByteArrayInputStream(bytes);
|
var in = new ByteArrayInputStream(bytes);
|
||||||
return new InteractiveConsole(out, in).run();
|
return new InteractiveConsole(out, in).runBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user