import era.mi.logic.wires.WireArray;\r
import era.mi.logic.wires.WireArray.WireArrayInput;\r
\r
-public abstract class MultiInputGate extends BasicComponent\r
-{\r
+public abstract class MultiInputGate extends BasicComponent {\r
protected WireArray[] in;\r
protected WireArray out;\r
protected WireArrayInput outI;\r
protected final int length;\r
protected Operation op;\r
- \r
- protected MultiInputGate(int processTime, Operation op, WireArray out, WireArray... in)\r
- {\r
+\r
+ protected MultiInputGate(int processTime, Operation op, WireArray out, WireArray... in) {\r
super(processTime);\r
this.op = op;\r
length = out.length;\r
this.in = in.clone();\r
- if(in.length < 1)\r
+ if (in.length < 1)\r
throw new IllegalArgumentException(String.format("Cannot create gate with %d wires.", in.length));\r
- for(WireArray w : in)\r
- {\r
- if(w.length != length)\r
+ for (WireArray w : in) {\r
+ if (w.length != length)\r
throw new IllegalArgumentException("All wires connected to the gate must be of uniform length.");\r
w.addObserver(this);\r
}\r
outI = out.createInput();\r
}\r
\r
-\r
@Override\r
- public List<WireArray> getAllInputs()\r
- {\r
+ public List<WireArray> getAllInputs() {\r
return Collections.unmodifiableList(Arrays.asList(in));\r
}\r
\r
@Override\r
- public List<WireArray> getAllOutputs()\r
- {\r
+ public List<WireArray> getAllOutputs() {\r
return Collections.unmodifiableList(Arrays.asList(out));\r
}\r
- \r
- protected void compute()\r
- {\r
+\r
+ protected void compute() {\r
Bit[] result = in[0].getValues();\r
- for(int i = 1; i < in.length; i++)\r
+ for (int i = 1; i < in.length; i++)\r
result = op.execute(result, in[i].getValues());\r
outI.feedSignals(result);\r
}\r
- \r
- protected interface Operation\r
- {\r
+\r
+ protected interface Operation {\r
public Bit[] execute(Bit[] a, Bit[] b);\r
}\r
}\r