From d537728679d4749cb87cedcd4aa0d35d44a68a08 Mon Sep 17 00:00:00 2001 From: Berack96 Date: Tue, 11 Feb 2025 09:18:31 +0100 Subject: [PATCH] Refactor SimulationBuilder to initialize fields and simplify end criteria parsing --- .../berack/upo/valpre/SimulationBuilder.java | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/berack/upo/valpre/SimulationBuilder.java b/src/main/java/net/berack/upo/valpre/SimulationBuilder.java index 16d3f32..db36fcd 100644 --- a/src/main/java/net/berack/upo/valpre/SimulationBuilder.java +++ b/src/main/java/net/berack/upo/valpre/SimulationBuilder.java @@ -19,13 +19,13 @@ import net.berack.upo.valpre.sim.stats.CsvResult; * and runs the simulation with the given parameters. */ public class SimulationBuilder { - private String csv; - private int runs; - private long seed; - private Net net; - private EndCriteria[] endCriteria; - private ConfidenceIndices confidences; + private String csv = null; + private int runs = 1; + private long seed = 0; + private EndCriteria[] endCriteria = new EndCriteria[0]; private Type type = Type.Normal; + private Net net; + private ConfidenceIndices confidences; /** * Create a new simulation for the given net. @@ -93,7 +93,7 @@ public class SimulationBuilder { * @return this simulation */ public SimulationBuilder setParallel(boolean parallel) { - if (parallel && !this.confidences.isEmpty()) + if (parallel && this.confidences.isEmpty()) this.type = Type.Parallel; return this; } @@ -142,10 +142,8 @@ public class SimulationBuilder { * @throws IllegalArgumentException If one of the criteria is not valid. */ public SimulationBuilder parseEndCriteria(String criterias) { - if (criterias == null || criterias.isEmpty()) { - this.endCriteria = new EndCriteria[0]; + if (criterias == null || criterias.isEmpty()) return this; - } var criteria = criterias.split(";"); this.endCriteria = new EndCriteria[criteria.length]; @@ -171,7 +169,6 @@ public class SimulationBuilder { * Add a confidence index for the given node and stat. * The confidence index is used to determine when the simulation should stop. * - * * @param node the node * @param stat the stat to calculate the confidence index for * @param confidence the confidence level expressed as a percentage [0,1]