X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2Fcomponents%2Fgates%2FXorGate.java;h=ad2f829671380457d796746718ae6a0f1ecdfdd8;hb=4712d3e6ee08461b7754dbfba1c9e82372bb474d;hp=b13dd2bc9a2b78633418e8b1e4bd6280dca4e59f;hpb=bcf8d773c7a836c2ee17e17a49c296ebf31d2777;p=Mograsim.git diff --git a/era.mi/src/era/mi/logic/components/gates/XorGate.java b/era.mi/src/era/mi/logic/components/gates/XorGate.java index b13dd2bc..ad2f8296 100644 --- a/era.mi/src/era/mi/logic/components/gates/XorGate.java +++ b/era.mi/src/era/mi/logic/components/gates/XorGate.java @@ -1,58 +1,18 @@ package era.mi.logic.components.gates; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - import era.mi.logic.Util; -import era.mi.logic.components.BasicComponent; import era.mi.logic.wires.WireArray; -import era.mi.logic.wires.WireArray.WireArrayInput; -public class XorGate extends BasicComponent +/** + * Outputs 1 when the number of 1 inputs is odd. + * + * @author Fabian Stemmler + */ +public class XorGate extends MultiInputGate { - private WireArray a, b, out; - private WireArrayInput outI; - - public XorGate(int processTime, WireArray a, WireArray b, WireArray out) + public XorGate(int processTime, WireArray out, WireArray... in) { - super(processTime); - this.a = a; - a.addObserver(this); - this.b = b; - b.addObserver(this); - this.out = out; + super(processTime, Util::xor, out, in); } - protected void compute() - { - outI.feedSignals(Util.xor(a.getValues(), b.getValues())); - } - - public WireArray getA() - { - return a; - } - - public WireArray getB() - { - return b; - } - - public WireArray getOut() - { - return out; - } - - @Override - public List getAllInputs() - { - return Collections.unmodifiableList(Arrays.asList(a, b)); - } - - @Override - public List getAllOutputs() - { - return Collections.unmodifiableList(Arrays.asList(out)); - } }