X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.logic.core%2Fsrc%2Fnet%2Fmograsim%2Flogic%2Fcore%2Fcomponents%2FManualSwitch.java;h=7f4f2659f9dcab1ffd6d4aaba24d4055ebf318ce;hb=81e5f69d47e06de721d00dd1cd1232c11e252ebc;hp=626804f0b17dc0cd081d05242484cc5fcbb3711d;hpb=d2ae4f1db269806849d4bb415f1e17e206e2a5bc;p=Mograsim.git diff --git a/net.mograsim.logic.core/src/net/mograsim/logic/core/components/ManualSwitch.java b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/ManualSwitch.java index 626804f0..7f4f2659 100644 --- a/net.mograsim.logic.core/src/net/mograsim/logic/core/components/ManualSwitch.java +++ b/net.mograsim.logic.core/src/net/mograsim/logic/core/components/ManualSwitch.java @@ -21,7 +21,6 @@ public class ManualSwitch extends Component implements LogicObservable { private Collection observers; private ReadWriteEnd output; - private boolean isOn; public ManualSwitch(Timeline timeline, ReadWriteEnd output) { @@ -44,36 +43,32 @@ public class ManualSwitch extends Component implements LogicObservable public void toggle() { - setState(!isOn); + setState(!isOn()); } public void setState(boolean isOn) { - if (this.isOn == isOn) - return; - this.isOn = isOn; - output.feedSignals(getValue()); - notifyObservers(); + setToValueOf(isOn ? Bit.ONE : Bit.ZERO); } public void setToValueOf(Bit bit) { - if (bit == Bit.ONE) - switchOn(); - else if (bit == Bit.ZERO) - switchOff(); - else + if (!bit.isBinary()) throw new IllegalArgumentException("Cannot set ManualSwitch to the value of Bit " + bit); + if (bit == output.getInputValue()) + return; + output.feedSignals(bit); + notifyObservers(); } public boolean isOn() { - return isOn; + return output.getInputValue() == Bit.ONE; } public Bit getValue() { - return isOn ? Bit.ONE : Bit.ZERO; + return output.getInputValue(); } @Override