Refactored Wire and finally renamed length to width
[Mograsim.git] / net.mograsim.logic.core / src / net / mograsim / logic / core / components / Splitter.java
index 9eb5b2c..04658fe 100644 (file)
@@ -2,13 +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.WireObserver;
 import net.mograsim.logic.core.wires.Wire.ReadEnd;
 import net.mograsim.logic.core.wires.Wire.ReadWriteEnd;
 
-public class Splitter extends Component implements WireObserver
+public class Splitter extends Component implements LogicObserver
 {
        private ReadEnd input;
        private ReadWriteEnd[] outputs;
@@ -18,14 +19,14 @@ public class Splitter extends Component implements WireObserver
                super(timeline);
                this.input = input;
                this.outputs = outputs;
-               input.addObserver(this);
-               int length = 0;
+               input.registerObserver(this);
+               int width = 0;
                for (ReadEnd out : outputs)
-                       length += out.length();
+                       width += out.width();
 
-               if (input.length() != length)
+               if (input.width() != width)
                        throw new IllegalArgumentException(
-                                       "The input of splitting one into n WireArrays must have length = a1.length() + a2.length() + ... + an.length().");
+                                       "The input of splitting one into n WireArrays must have width = a1.width() + a2.width() + ... + an.width().");
        }
 
        protected void compute()
@@ -34,13 +35,13 @@ public class Splitter extends Component implements WireObserver
                int startIndex = 0;
                for (int i = 0; i < outputs.length; i++)
                {
-                       outputs[i].feedSignals(inputBits.subVector(startIndex, startIndex + outputs[i].length()));
-                       startIndex += outputs[i].length();
+                       outputs[i].feedSignals(inputBits.subVector(startIndex, startIndex + outputs[i].width()));
+                       startIndex += outputs[i].width();
                }
        }
 
        @Override
-       public void update(ReadEnd initiator, BitVector oldValues)
+       public void update(LogicObservable initiator)
        {
                compute();
        }