X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2Fcomponents%2Fgates%2FMultiInputGate.java;h=d26297be2d6d1396d20460ad9f38cfa0584b8c53;hb=4712d3e6ee08461b7754dbfba1c9e82372bb474d;hp=f7af52e1c09377c7cba8027e1a7348ff0b145edb;hpb=74aebd92f41d03f4a44c9a455ef8c05465136412;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 f7af52e1..d26297be 100644 --- a/era.mi/src/era/mi/logic/components/gates/MultiInputGate.java +++ b/era.mi/src/era/mi/logic/components/gates/MultiInputGate.java @@ -7,23 +7,26 @@ 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 { +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) { + 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) 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) throw new IllegalArgumentException("All wires connected to the gate must be of uniform length."); w.addObserver(this); @@ -33,23 +36,27 @@ public abstract class MultiInputGate extends BasicComponent { } @Override - public List getAllInputs() { + public List getAllInputs() + { return Collections.unmodifiableList(Arrays.asList(in)); } @Override - public List getAllOutputs() { + public List getAllOutputs() + { return Collections.unmodifiableList(Arrays.asList(out)); } - protected void compute() { + protected void compute() + { Bit[] result = in[0].getValues(); for (int i = 1; i < in.length; i++) result = op.execute(result, in[i].getValues()); outI.feedSignals(result); } - protected interface Operation { + protected interface Operation + { public Bit[] execute(Bit[] a, Bit[] b); } }