Added project specific format; Default values in WireArray are now U
[Mograsim.git] / era.mi / src / era / mi / logic / components / gates / XorGate.java
index b13dd2b..ad2f829 100644 (file)
@@ -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<WireArray> getAllInputs()
-       {
-               return Collections.unmodifiableList(Arrays.asList(a, b));
-       }
-
-       @Override
-       public List<WireArray> getAllOutputs()
-       {
-               return Collections.unmodifiableList(Arrays.asList(out));
-       }
 }