X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2Fcomponents%2FManualSwitch.java;fp=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2Fcomponents%2FManualSwitch.java;h=0ad4a76cdcf57f90bd9f7b856e7aad4923f084f8;hb=fb3edf0f514d574d60cc5874b4d53ebaaa34b7e1;hp=c4b4ffa323c9cb9d8f491090d5bc282024f118e1;hpb=e7180dd9040734555e6a07f2561fb688118b7002;p=Mograsim.git diff --git a/era.mi/src/era/mi/logic/components/ManualSwitch.java b/era.mi/src/era/mi/logic/components/ManualSwitch.java index c4b4ffa3..0ad4a76c 100644 --- a/era.mi/src/era/mi/logic/components/ManualSwitch.java +++ b/era.mi/src/era/mi/logic/components/ManualSwitch.java @@ -1,71 +1,71 @@ -package era.mi.logic.components; - -import java.util.List; - -import era.mi.logic.types.Bit; -import era.mi.logic.wires.Wire.WireEnd; - -/** - * This class models a simple on/off (ONE/ZERO) switch for user interaction. - * - * @author Christian Femers - * - */ -public class ManualSwitch implements Component -{ - private WireEnd output; - private boolean isOn; - - public ManualSwitch(WireEnd output) - { - if (output.length() != 1) - throw new IllegalArgumentException("Switch output can be only a single wire"); - this.output = output; - } - - public void switchOn() - { - setState(true); - } - - public void switchOff() - { - setState(false); - } - - public void toggle() - { - setState(!isOn); - } - - public void setState(boolean isOn) - { - if (this.isOn == isOn) - return; - this.isOn = isOn; - output.feedSignals(getValue()); - } - - public boolean isOn() - { - return isOn; - } - - public Bit getValue() - { - return isOn ? Bit.ONE : Bit.ZERO; - } - - @Override - public List getAllInputs() - { - return List.of(); - } - - @Override - public List getAllOutputs() - { - return List.of(output); - } - -} +package era.mi.logic.components; + +import java.util.List; + +import era.mi.logic.types.Bit; +import era.mi.logic.wires.Wire.WireEnd; + +/** + * This class models a simple on/off (ONE/ZERO) switch for user interaction. + * + * @author Christian Femers + * + */ +public class ManualSwitch implements Component +{ + private WireEnd output; + private boolean isOn; + + public ManualSwitch(WireEnd output) + { + if (output.length() != 1) + throw new IllegalArgumentException("Switch output can be only a single wire"); + this.output = output; + } + + public void switchOn() + { + setState(true); + } + + public void switchOff() + { + setState(false); + } + + public void toggle() + { + setState(!isOn); + } + + public void setState(boolean isOn) + { + if (this.isOn == isOn) + return; + this.isOn = isOn; + output.feedSignals(getValue()); + } + + public boolean isOn() + { + return isOn; + } + + public Bit getValue() + { + return isOn ? Bit.ONE : Bit.ZERO; + } + + @Override + public List getAllInputs() + { + return List.of(); + } + + @Override + public List getAllOutputs() + { + return List.of(output); + } + +}