X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=era.mi%2Fsrc%2Fera%2Fmi%2Flogic%2Fcomponents%2FMerger.java;h=1efcf8ad276cf0d6d4922ed92bda4a466af458fc;hb=74aebd92f41d03f4a44c9a455ef8c05465136412;hp=591bfc1bac47da336df2993fc46d7fd7efb5bd1f;hpb=de79184d60c80d6775b368e61d3368de032952e8;p=Mograsim.git diff --git a/era.mi/src/era/mi/logic/components/Merger.java b/era.mi/src/era/mi/logic/components/Merger.java index 591bfc1b..1efcf8ad 100644 --- a/era.mi/src/era/mi/logic/components/Merger.java +++ b/era.mi/src/era/mi/logic/components/Merger.java @@ -9,77 +9,66 @@ import era.mi.logic.wires.WireArray; import era.mi.logic.wires.WireArray.WireArrayInput; import era.mi.logic.wires.WireArrayObserver; -public class Merger implements WireArrayObserver, Component -{ - private WireArrayInput outI; - private WireArray[] inputs; - private int[] beginningIndex; +public class Merger implements WireArrayObserver, Component { + private WireArrayInput outI; + private WireArray[] inputs; + private int[] beginningIndex; - /** - * - * @param union The output of merging n {@link WireArray}s into one. Must have - * length = a1.length() + a2.length() + ... + an.length(). - * @param inputs The inputs to be merged into the union - */ - public Merger(WireArray union, WireArray... inputs) - { - this.inputs = inputs; - this.outI = union.createInput(); - this.beginningIndex = new int[inputs.length]; + /** + * + * @param union The output of merging n {@link WireArray}s into one. Must have length = a1.length() + a2.length() + ... + an.length(). + * @param inputs The inputs to be merged into the union + */ + public Merger(WireArray union, WireArray... inputs) { + this.inputs = inputs; + this.outI = union.createInput(); + this.beginningIndex = new int[inputs.length]; - int length = 0; - for (int i = 0; i < inputs.length; i++) - { - beginningIndex[i] = length; - length += inputs[i].length; - inputs[i].addObserver(this); - } + int length = 0; + for (int i = 0; i < inputs.length; i++) { + beginningIndex[i] = length; + length += inputs[i].length; + inputs[i].addObserver(this); + } - if (length != union.length) - throw new IllegalArgumentException( - "The output of merging n WireArrays into one must have length = a1.length() + a2.length() + ... + an.length()."); - } + if (length != union.length) + throw new IllegalArgumentException( + "The output of merging n WireArrays into one must have length = a1.length() + a2.length() + ... + an.length()."); + } - public WireArray getInput(int index) - { - return inputs[index]; - } + public WireArray getInput(int index) { + return inputs[index]; + } - public WireArray getUnion() - { - return outI.owner; - } + public WireArray getUnion() { + return outI.owner; + } - @Override - public void update(WireArray initiator, Bit[] oldValues) - { - int index = find(initiator); - int beginning = beginningIndex[index]; - outI.feedSignals(beginning, initiator.getValues()); - } + @Override + public void update(WireArray initiator, Bit[] oldValues) { + int index = find(initiator); + int beginning = beginningIndex[index]; + outI.feedSignals(beginning, initiator.getValues()); + } - private int find(WireArray w) - { - for (int i = 0; i < inputs.length; i++) - if (inputs[i] == w) - return i; - return -1; - } + private int find(WireArray w) { + for (int i = 0; i < inputs.length; i++) + if (inputs[i] == w) + return i; + return -1; + } - public WireArray[] getInputs() - { - return inputs.clone(); - } + public WireArray[] getInputs() { + return inputs.clone(); + } @Override - public List getAllInputs() - { + public List getAllInputs() { return Collections.unmodifiableList(Arrays.asList(inputs)); } @Override - public List getAllOutputs() - { + public List getAllOutputs() { return Collections.unmodifiableList(Arrays.asList(outI.owner)); } }