X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2Fcomponents%2FManualSwitch.java;h=93c1319f6403a70965db82a032af2fda7c095fb5;hb=72b00816f86e5d34d871c87fea76a94ffca25246;hp=142c55d96839d4683bcbc6db0079b3b6f2748bd9;hpb=1cfc4888cbde080210f64682607cf89febdbb0ba;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 142c55d9..93c1319f 100644 --- a/era.mi/src/era/mi/logic/components/ManualSwitch.java +++ b/era.mi/src/era/mi/logic/components/ManualSwitch.java @@ -12,50 +12,42 @@ import era.mi.logic.wires.WireArray.WireArrayInput; * @author Christian Femers * */ -public final class ManualSwitch implements Component -{ +public class ManualSwitch implements Component { private WireArray output; private WireArrayInput outputI; private boolean isOn; - - public ManualSwitch(WireArray output) - { - if(output.length != 1) + + public ManualSwitch(WireArray output) { + if (output.length != 1) throw new IllegalArgumentException("Switch output can be only a single wire"); this.output = output; this.outputI = output.createInput(); } - - public void switchOn() - { + + public void switchOn() { setState(true); } - - public void switchOff() - { + + public void switchOff() { setState(false); } - - public void toggle() - { + + public void toggle() { setState(!isOn); } - - public void setState(boolean isOn) - { - if(this.isOn == isOn) + + public void setState(boolean isOn) { + if (this.isOn == isOn) return; this.isOn = isOn; outputI.feedSignals(getValue()); } - - public boolean isOn() - { + + public boolean isOn() { return isOn; } - - public Bit getValue() - { + + public Bit getValue() { return isOn ? Bit.ONE : Bit.ZERO; }