Refactored Wire and finally renamed length to width
[Mograsim.git] / net.mograsim.logic.core / src / net / mograsim / logic / core / components / Merger.java
index c4c7170..07303a2 100644 (file)
@@ -2,14 +2,14 @@ package net.mograsim.logic.core.components;
 
 import java.util.List;
 
+import net.mograsim.logic.core.LogicObservable;
+import net.mograsim.logic.core.LogicObserver;
 import net.mograsim.logic.core.timeline.Timeline;
-import net.mograsim.logic.core.types.BitVector;
 import net.mograsim.logic.core.wires.Wire;
-import net.mograsim.logic.core.wires.WireObserver;
 import net.mograsim.logic.core.wires.Wire.ReadEnd;
 import net.mograsim.logic.core.wires.Wire.ReadWriteEnd;
 
-public class Merger extends Component implements WireObserver
+public class Merger extends Component implements LogicObserver
 {
        private ReadWriteEnd out;
        private ReadEnd[] inputs;
@@ -17,7 +17,7 @@ public class Merger extends Component implements WireObserver
 
        /**
         * 
-        * @param union  The output of merging n {@link Wire}s into one. Must have length = a1.length() + a2.length() + ... + an.length().
+        * @param union  The output of merging n {@link Wire}s into one. Must have width = a1.width() + a2.width() + ... + an.width().
         * @param inputs The inputs to be merged into the union
         */
        public Merger(Timeline timeline, ReadWriteEnd union, ReadEnd... inputs)
@@ -31,13 +31,13 @@ public class Merger extends Component implements WireObserver
                for (int i = 0; i < inputs.length; i++)
                {
                        beginningIndex[i] = length;
-                       length += inputs[i].length();
-                       inputs[i].addObserver(this);
+                       length += inputs[i].width();
+                       inputs[i].registerObserver(this);
                }
 
-               if (length != union.length())
+               if (length != union.width())
                        throw new IllegalArgumentException(
-                                       "The output of merging n WireArrays into one must have length = a1.length() + a2.length() + ... + an.length().");
+                                       "The output of merging n WireArrays into one must have width = a1.width() + a2.width() + ... + an.width().");
        }
 
        public ReadEnd getInput(int index)
@@ -51,14 +51,14 @@ public class Merger extends Component implements WireObserver
        }
 
        @Override
-       public void update(ReadEnd initiator, BitVector oldValues)
+       public void update(LogicObservable initiator)
        {
                int index = find(initiator);
                int beginning = beginningIndex[index];
                out.feedSignals(beginning, inputs[index].getValues());
        }
 
-       private int find(ReadEnd r)
+       private int find(LogicObservable r)
        {
                for (int i = 0; i < inputs.length; i++)
                        if (inputs[i] == r)