X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Fnature%2FMachineContext.java;fp=plugins%2Fnet.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Fnature%2FMachineContext.java;h=c84e622e2ead0ab00feb3a1f679f1061088fd5af;hb=a60db0eb036058aa47c928653da0b504452aa595;hp=1be6b2aa5ce674736af4654d6a19c23d30968eea;hpb=0d1e26120862bf16b403773247e25a32b0948b40;p=Mograsim.git diff --git a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/MachineContext.java b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/MachineContext.java index 1be6b2aa..c84e622e 100644 --- a/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/MachineContext.java +++ b/plugins/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/MachineContext.java @@ -122,9 +122,10 @@ public class MachineContext */ public final void setActiveMachine(Machine machine) { + Optional oldMachine = activeMachine; activeMachine = Optional.ofNullable(machine); updateStatus(); - notifyActiveMachineListeners(); + notifyActiveMachineListeners(oldMachine, activeMachine); } public final Optional getMachineId() @@ -208,8 +209,9 @@ public class MachineContext { if ((status == DEAD || status == CLOSED) && activeMachine.isPresent()) { + Optional oldMachine = activeMachine; activeMachine = Optional.empty(); - notifyActiveMachineListeners(); + notifyActiveMachineListeners(oldMachine, activeMachine); } } @@ -247,15 +249,15 @@ public class MachineContext } } - private void notifyActiveMachineListeners() + private void notifyActiveMachineListeners(Optional oldMachine, Optional newMachine) { - machineListeners.forEach(ob -> ob.setMachine(activeMachine)); + machineListeners.forEach(ob -> ob.setMachine(oldMachine, newMachine)); } public void addActiveMachineListener(ActiveMachineListener ob) { machineListeners.add(ob); - ob.setMachine(activeMachine); + ob.setMachine(Optional.empty(), activeMachine); } public void removeActiveMachineListener(ActiveMachineListener ob) @@ -282,7 +284,7 @@ public class MachineContext @FunctionalInterface public static interface ActiveMachineListener { - void setMachine(Optional machine); + void setMachine(Optional oldMachine, Optional newMachine); } @FunctionalInterface