1 package era.mi.logic.components.gates;
5 import era.mi.logic.components.BasicComponent;
6 import era.mi.logic.types.Bit;
7 import era.mi.logic.wires.Wire.WireEnd;
9 public abstract class MultiInputGate extends BasicComponent
11 protected WireEnd[] in;
12 protected WireEnd out;
13 protected final int length;
14 protected Operation op;
16 protected MultiInputGate(int processTime, Operation op, WireEnd out, WireEnd... in)
20 length = out.length();
23 throw new IllegalArgumentException(String.format("Cannot create gate with %d wires.", in.length));
26 if (w.length() != length)
27 throw new IllegalArgumentException("All wires connected to the gate must be of uniform length.");
34 public List<WireEnd> getAllInputs()
40 public List<WireEnd> getAllOutputs()
46 protected void compute()
48 Bit[] result = in[0].getValues();
49 for (int i = 1; i < in.length; i++)
50 result = op.execute(result, in[i].getValues());
51 out.feedSignals(result);
54 protected interface Operation
56 public Bit[] execute(Bit[] a, Bit[] b);