Added id to machine definition (was only set in the extension point)
authorChristian Femers <femers@in.tum.de>
Tue, 24 Sep 2019 03:11:56 +0000 (05:11 +0200)
committerChristian Femers <femers@in.tum.de>
Tue, 24 Sep 2019 03:11:56 +0000 (05:11 +0200)
MachineRegistry will check for consistency

plugins/net.mograsim.logic.model.am2900/src/net/mograsim/logic/model/am2900/machine/Am2900MachineDefinition.java
plugins/net.mograsim.machine/src/net/mograsim/machine/MachineDefinition.java
plugins/net.mograsim.machine/src/net/mograsim/machine/MachineRegistry.java

index e75c79a..1ed0372 100644 (file)
@@ -11,6 +11,14 @@ import net.mograsim.machine.Register;
 //(used for detecting installed machines in plugin.core)
 public class Am2900MachineDefinition implements MachineDefinition
 {
+       public static final String AM2900_MACHINE_ID = "Am2900";
+
+       @Override
+       public String getId()
+       {
+               return AM2900_MACHINE_ID;
+       }
+
        @Override
        public Am2900Machine createNew()
        {
@@ -65,4 +73,5 @@ public class Am2900MachineDefinition implements MachineDefinition
        {
                return Am2900MicroInstructionMemoryDefinition.instance;
        }
+
 }
index 02cf375..8f1ee26 100644 (file)
@@ -6,6 +6,14 @@ import net.mograsim.machine.mi.MicroInstructionMemoryDefinition;
 
 public interface MachineDefinition
 {
+       /**
+        * This returns the MachineDefinitions ID. This must be consistent and coherent with the id in the extension point (Eclipse plugin xml)
+        * providing the definition.
+        * 
+        * @return a human readable, unique id representing the specified machine.
+        * @author Christian Femers
+        */
+       String getId();
 
        /**
         * Creates a new instance of the machine
index 28e7921..52e5d60 100644 (file)
@@ -35,7 +35,11 @@ public class MachineRegistry
                                if (o instanceof MachineDefinition)
                                {
                                        System.out.println("Found " + id);
-                                       installedMachines.put(id, (MachineDefinition) o);
+                                       MachineDefinition md = (MachineDefinition) o;
+                                       if (Objects.equals(id, md.getId()))
+                                               installedMachines.put(id, md);
+                                       else
+                                               System.err.println("Machine definition ids to not match: " + id + " and " + md.getId());
                                } else
                                {
                                        System.err.println("Invalid machine definition: " + o + "(id=" + id + "");