X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2Fcomponents%2Fgates%2FMultiInputGate.java;h=2094b846f6b13a295aad96a559dc8fb698207088;hb=f2cd90fa2b844507bc9697d3af1f3e18aac80b37;hp=bfa33ed6ffe97484e3cd762567b9b00c21895905;hpb=bc46b5d9664f097be44f5147c5cc774d1410ad93;p=Mograsim.git diff --git a/era.mi/src/era/mi/logic/components/gates/MultiInputGate.java b/era.mi/src/era/mi/logic/components/gates/MultiInputGate.java index bfa33ed6..2094b846 100644 --- a/era.mi/src/era/mi/logic/components/gates/MultiInputGate.java +++ b/era.mi/src/era/mi/logic/components/gates/MultiInputGate.java @@ -1,33 +1,31 @@ package era.mi.logic.components.gates; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import era.mi.logic.Bit; import era.mi.logic.components.BasicComponent; import era.mi.logic.wires.WireArray; -import era.mi.logic.wires.WireArray.WireArrayInput; +import era.mi.logic.wires.WireArray.WireArrayEnd; public abstract class MultiInputGate extends BasicComponent { protected WireArray[] in; protected WireArray out; - protected WireArrayInput outI; + protected WireArrayEnd outI; protected final int length; protected Operation op; - + protected MultiInputGate(int processTime, Operation op, WireArray out, WireArray... in) { super(processTime); this.op = op; length = out.length; this.in = in.clone(); - if(in.length < 1) + if (in.length < 1) throw new IllegalArgumentException(String.format("Cannot create gate with %d wires.", in.length)); - for(WireArray w : in) + for (WireArray w : in) { - if(w.length != length) + if (w.length != length) throw new IllegalArgumentException("All wires connected to the gate must be of uniform length."); w.addObserver(this); } @@ -35,27 +33,27 @@ public abstract class MultiInputGate extends BasicComponent outI = out.createInput(); } - @Override public List getAllInputs() { - return Collections.unmodifiableList(Arrays.asList(in)); + return List.of(in); } @Override public List getAllOutputs() { - return Collections.unmodifiableList(Arrays.asList(out)); + return List.of(out); } - + + @Override protected void compute() { Bit[] result = in[0].getValues(); - for(int i = 1; i < in.length; i++) + for (int i = 1; i < in.length; i++) result = op.execute(result, in[i].getValues()); outI.feedSignals(result); } - + protected interface Operation { public Bit[] execute(Bit[] a, Bit[] b);