import java.util.List;\r
\r
import era.mi.logic.wires.WireArray;\r
-import era.mi.logic.wires.WireArray.WireArrayInput;\r
+import era.mi.logic.wires.WireArray.WireArrayEnd;\r
\r
/**\r
* Models a multiplexer. Takes an arbitrary amount of input {@link WireArray}s, one of which, as determined by select, is put through to the\r
* @author Fabian Stemmler\r
*\r
*/\r
-public class Mux extends BasicComponent {\r
+public class Mux extends BasicComponent\r
+{\r
private WireArray select;\r
- private WireArrayInput outI;\r
+ private WireArrayEnd outI;\r
private WireArray[] inputs;\r
private final int outputSize;\r
\r
* @param select Indexes the input array which is to be mapped to the output. Must have enough bits to index all inputs.\r
* @param inputs One of these inputs is mapped to the output, depending on the select bits\r
*/\r
- public Mux(int processTime, WireArray out, WireArray select, WireArray... inputs) {\r
+ public Mux(int processTime, WireArray out, WireArray select, WireArray... inputs)\r
+ {\r
super(processTime);\r
outputSize = out.length;\r
\r
this.inputs = inputs.clone();\r
- for (int i = 0; i < this.inputs.length; i++) {\r
+ for (int i = 0; i < this.inputs.length; i++)\r
+ {\r
if (inputs[i].length != outputSize)\r
throw new IllegalArgumentException("All MUX wire arrays must be of uniform length!");\r
inputs[i].addObserver(this);\r
outI = out.createInput();\r
}\r
\r
- public WireArray getOut() {\r
+ public WireArray getOut()\r
+ {\r
return outI.owner;\r
}\r
\r
- public WireArray getSelect() {\r
+ public WireArray getSelect()\r
+ {\r
return select;\r
}\r
\r
@Override\r
- public void compute() {\r
+ public void compute()\r
+ {\r
int selectValue;\r
- if (!select.hasNumericValue() || (selectValue = (int) select.getUnsignedValue()) >= inputs.length) {\r
+ if (!select.hasNumericValue() || (selectValue = (int) select.getUnsignedValue()) >= inputs.length)\r
+ {\r
outI.clearSignals();\r
return;\r
}\r
}\r
\r
@Override\r
- public List<WireArray> getAllInputs() {\r
+ public List<WireArray> getAllInputs()\r
+ {\r
ArrayList<WireArray> wires = new ArrayList<WireArray>(Arrays.asList(inputs));\r
wires.add(select);\r
return Collections.unmodifiableList(wires);\r
}\r
\r
@Override\r
- public List<WireArray> getAllOutputs() {\r
+ public List<WireArray> getAllOutputs()\r
+ {\r
return Collections.unmodifiableList(Arrays.asList(outI.owner));\r
}\r
}\r