Reformatted everything. Eclipse built-in Linewrapping/Comments 140 chars
[Mograsim.git] / era.mi / src / era / mi / logic / components / Splitter.java
index 58d48e7..360ff43 100644 (file)
@@ -2,52 +2,39 @@ package era.mi.logic.components;
 
 import era.mi.logic.Bit;
 import era.mi.logic.wires.WireArray;
+import era.mi.logic.wires.WireArray.WireArrayInput;
 import era.mi.logic.wires.WireArrayObserver;
 
-public class Splitter implements WireArrayObserver
-{
+public class Splitter implements WireArrayObserver {
        private WireArray input;
-       private WireArray[] outputs;
-       
-       public Splitter(WireArray input, WireArray... outputs)
-       {
+       private WireArrayInput[] outputs;
+
+       public Splitter(WireArray input, WireArray... outputs) {
                this.input = input;
-               this.outputs = outputs;
+               this.outputs = WireArray.extractInputs(outputs);
                input.addObserver(this);
                int length = 0;
-               for(WireArray out : outputs)
+               for (WireArray out : outputs)
                        length += out.length;
-               
-               if(input.length != length)
-                       throw new IllegalArgumentException("The input of splitting one into n WireArrays must have length = a1.length() + a2.length() + ... + an.length().");
+
+               if (input.length != length)
+                       throw new IllegalArgumentException(
+                                       "The input of splitting one into n WireArrays must have length = a1.length() + a2.length() + ... + an.length().");
        }
 
-       protected void compute()
-       {
+       protected void compute() {
                int startIndex = 0;
                Bit[] inputBits = input.getValues();
-               for(int i = 0; i < outputs.length; i++)
-               {
-                       Bit[] outputBits = new Bit[outputs[i].length];
-                       System.arraycopy(inputBits, startIndex, outputBits, 0, outputs[i].length);
+               for (int i = 0; i < outputs.length; i++) {
+                       Bit[] outputBits = new Bit[outputs[i].owner.length];
+                       System.arraycopy(inputBits, startIndex, outputBits, 0, outputs[i].owner.length);
                        outputs[i].feedSignals(outputBits);
-                       startIndex += outputs[i].length;
+                       startIndex += outputs[i].owner.length;
                }
        }
 
-       public WireArray getInput()
-       {
-               return input;
-       }
-       
-       public WireArray[] getOutputs()
-       {
-               return outputs.clone();
-       }
-       
        @Override
-       public void update(WireArray initiator)
-       {
+       public void update(WireArray initiator, Bit[] oldValues) {
                compute();
        }
 }