Using Builder pattern for CoreModelParameters now
authorDaniel Kirschten <daniel.kirschten@gmx.de>
Wed, 7 Oct 2020 20:34:01 +0000 (22:34 +0200)
committerDaniel Kirschten <daniel.kirschten@gmx.de>
Wed, 7 Oct 2020 20:34:01 +0000 (22:34 +0200)
plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900Machine.java
plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/examples/CountGatesPerComponent.java
plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/SimpleLogicUIStandalone.java
plugins/net.mograsim.logic.model/src/net/mograsim/logic/model/modeladapter/CoreModelParameters.java
plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/SimulationPreview.java
tests/net.mograsim.logic.model.am2900.tests/src/net/mograsim/logic/model/am2900/util/TestEnvironmentHelper.java

index a7f7379..3d486f4 100644 (file)
@@ -16,6 +16,7 @@ import net.mograsim.logic.model.model.LogicModelModifiable;
 import net.mograsim.logic.model.model.components.ModelComponent;
 import net.mograsim.logic.model.model.components.atomic.ModelClock;
 import net.mograsim.logic.model.modeladapter.CoreModelParameters;
+import net.mograsim.logic.model.modeladapter.CoreModelParameters.CoreModelParametersBuilder;
 import net.mograsim.logic.model.modeladapter.LogicCoreAdapter;
 import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
 import net.mograsim.machine.AssignableMainMemory;
@@ -55,10 +56,12 @@ public class Am2900Machine implements Machine
                                "resloader:Am2900Loader:jsonres:net/mograsim/logic/model/am2900/components/Am2900.json", "Am2900");
                this.amicListeners = new HashSet<>();
 
-               CoreModelParameters params = new CoreModelParameters();
-               params.gateProcessTime = 50;
-               params.hardcodedComponentProcessTime = params.gateProcessTime * 5;
-               params.wireTravelTime = 10;
+               CoreModelParametersBuilder paramsBuilder = new CoreModelParametersBuilder();
+               paramsBuilder.gateProcessTime = 50;
+               paramsBuilder.hardcodedComponentProcessTime = paramsBuilder.gateProcessTime * 5;
+               paramsBuilder.wireTravelTime = 10;
+               CoreModelParameters params = paramsBuilder.build();
+
                mainMemory = new AssignableMainMemory(new StandardMainMemory(am2900MachineDefinition.getMainMemoryDefinition()));
                instMemory = new AssignableMicroInstructionMemory(
                                new StandardMicroInstructionMemory(am2900MachineDefinition.getMicroInstructionMemoryDefinition()));
index cac3aa7..b9c7398 100755 (executable)
@@ -8,7 +8,7 @@ import java.util.Map.Entry;
 import net.mograsim.logic.model.am2900.Am2900Loader;
 import net.mograsim.logic.model.model.LogicModelModifiable;
 import net.mograsim.logic.model.model.components.ModelComponent;
-import net.mograsim.logic.model.modeladapter.CoreModelParameters;
+import net.mograsim.logic.model.modeladapter.CoreModelParameters.CoreModelParametersBuilder;
 import net.mograsim.logic.model.modeladapter.LogicCoreAdapter;
 import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
 
@@ -29,7 +29,7 @@ public class CountGatesPerComponent
                IndirectModelComponentCreator.createComponent(model, componentID);
 
                LogicCoreAdapter.gateCountsPerComponentClass.clear();
-               LogicCoreAdapter.convert(model, new CoreModelParameters());
+               LogicCoreAdapter.convert(model, new CoreModelParametersBuilder().build());
 
                System.out.println(componentID + ':');
                for (Entry<Class<? extends ModelComponent>, Integer> e : LogicCoreAdapter.gateCountsPerComponentClass.entrySet())
index 829abaa..dab4584 100644 (file)
@@ -5,6 +5,7 @@ import java.util.function.Consumer;
 import net.mograsim.logic.core.timeline.Timeline;
 import net.mograsim.logic.model.model.LogicModelModifiable;
 import net.mograsim.logic.model.modeladapter.CoreModelParameters;
+import net.mograsim.logic.model.modeladapter.CoreModelParameters.CoreModelParametersBuilder;
 import net.mograsim.logic.model.modeladapter.LogicCoreAdapter;
 import net.mograsim.logic.model.preferences.DefaultRenderPreferences;
 
@@ -17,11 +18,11 @@ public class SimpleLogicUIStandalone
 
        public static void executeVisualisation(Consumer<LogicModelModifiable> setupLogicModel, Consumer<VisualisationObjects> beforeRun)
        {
-               CoreModelParameters params = new CoreModelParameters();
-               params.gateProcessTime = 50;
-               params.hardcodedComponentProcessTime = params.gateProcessTime * 5;
-               params.wireTravelTime = 10;
-               executeVisualisation(setupLogicModel, params, beforeRun);
+               CoreModelParametersBuilder paramsBuilder = new CoreModelParametersBuilder();
+               paramsBuilder.gateProcessTime = 50;
+               paramsBuilder.hardcodedComponentProcessTime = paramsBuilder.gateProcessTime * 5;
+               paramsBuilder.wireTravelTime = 10;
+               executeVisualisation(setupLogicModel, paramsBuilder.build(), beforeRun);
        }
 
        public static void executeVisualisation(Consumer<LogicModelModifiable> setupLogicModel, CoreModelParameters params)
index 96be5c2..6111e0b 100644 (file)
@@ -2,7 +2,51 @@ package net.mograsim.logic.model.modeladapter;
 
 public class CoreModelParameters
 {
-       public int wireTravelTime;
-       public int gateProcessTime;
-       public int hardcodedComponentProcessTime;
+       public final int wireTravelTime;
+       public final int gateProcessTime;
+       public final int hardcodedComponentProcessTime;
+
+       public CoreModelParameters(int wireTravelTime, int gateProcessTime, int hardcodedComponentProcessTime)
+       {
+               this.wireTravelTime = wireTravelTime;
+               this.gateProcessTime = gateProcessTime;
+               this.hardcodedComponentProcessTime = hardcodedComponentProcessTime;
+       }
+
+       private CoreModelParameters(CoreModelParametersBuilder builder)
+       {
+               this.wireTravelTime = builder.wireTravelTime;
+               this.gateProcessTime = builder.gateProcessTime;
+               this.hardcodedComponentProcessTime = builder.hardcodedComponentProcessTime;
+       }
+
+       public static class CoreModelParametersBuilder
+       {
+               public int wireTravelTime;
+               public int gateProcessTime;
+               public int hardcodedComponentProcessTime;
+
+               public CoreModelParametersBuilder wireTravelTime(int wireTravelTime)
+               {
+                       this.wireTravelTime = wireTravelTime;
+                       return this;
+               }
+
+               public CoreModelParametersBuilder gateProcessTime(int gateProcessTime)
+               {
+                       this.gateProcessTime = gateProcessTime;
+                       return this;
+               }
+
+               public CoreModelParametersBuilder hardcodedComponentProcessTime(int hardcodedComponentProcessTime)
+               {
+                       this.hardcodedComponentProcessTime = hardcodedComponentProcessTime;
+                       return this;
+               }
+
+               public CoreModelParameters build()
+               {
+                       return new CoreModelParameters(this);
+               }
+       }
 }
\ No newline at end of file
index 03a0e34..45d5540 100644 (file)
@@ -16,6 +16,7 @@ import net.mograsim.logic.model.model.components.atomic.ModelOrGate;
 import net.mograsim.logic.model.model.wires.ModelWire;
 import net.mograsim.logic.model.model.wires.ModelWireCrossPoint;
 import net.mograsim.logic.model.modeladapter.CoreModelParameters;
+import net.mograsim.logic.model.modeladapter.CoreModelParameters.CoreModelParametersBuilder;
 import net.mograsim.logic.model.modeladapter.LogicCoreAdapter;
 import net.mograsim.logic.model.preferences.RenderPreferences;
 import net.mograsim.plugin.preferences.EclipseRenderPreferences;
@@ -33,10 +34,12 @@ public class SimulationPreview implements IThemePreview
                                MograsimActivator.instance().getPreferenceStore());
 
                LogicModelModifiable model = new LogicModelModifiable();
-               CoreModelParameters params = new CoreModelParameters();
-               params.gateProcessTime = 50;
-               params.hardcodedComponentProcessTime = params.gateProcessTime * 5;
-               params.wireTravelTime = 10;
+
+               CoreModelParametersBuilder paramsBuilder = new CoreModelParametersBuilder();
+               paramsBuilder.gateProcessTime = 50;
+               paramsBuilder.hardcodedComponentProcessTime = paramsBuilder.gateProcessTime * 5;
+               paramsBuilder.wireTravelTime = 10;
+               CoreModelParameters params = paramsBuilder.build();
 
                ModelManualSwitch rIn = new ModelManualSwitch(model, 1);
                rIn.moveTo(10, 10);
index 54321cb..071bd78 100644 (file)
@@ -27,7 +27,7 @@ import net.mograsim.logic.model.model.components.atomic.ModelManualSwitch;
 import net.mograsim.logic.model.model.components.submodels.SubmodelComponent;
 import net.mograsim.logic.model.model.wires.ModelWire;
 import net.mograsim.logic.model.model.wires.Pin;
-import net.mograsim.logic.model.modeladapter.CoreModelParameters;
+import net.mograsim.logic.model.modeladapter.CoreModelParameters.CoreModelParametersBuilder;
 import net.mograsim.logic.model.modeladapter.LogicCoreAdapter;
 import net.mograsim.logic.model.preferences.DefaultRenderPreferences;
 import net.mograsim.logic.model.serializing.IndirectModelComponentCreator;
@@ -89,11 +89,11 @@ public class TestEnvironmentHelper
                component.getPins().values().forEach(this::extendModelPin);
 
                // Create core model
-               CoreModelParameters params = new CoreModelParameters();
-               params.gateProcessTime = 50;
-               params.hardcodedComponentProcessTime = params.gateProcessTime * 5;
-               params.wireTravelTime = 10;
-               timeline = LogicCoreAdapter.convert(logicModel, params);
+               CoreModelParametersBuilder paramsBuilder = new CoreModelParametersBuilder();
+               paramsBuilder.gateProcessTime = 50;
+               paramsBuilder.hardcodedComponentProcessTime = paramsBuilder.gateProcessTime * 5;
+               paramsBuilder.wireTravelTime = 10;
+               timeline = LogicCoreAdapter.convert(logicModel, paramsBuilder.build());
                timelineField.ifPresent(f -> setField(f, timeline));
 
                // Bind switches/displays to this test class