+ return val;
+ }
+
+ /**
+ * Included for convenient use on {@link WireArray}s of length 1.
+ *
+ * @return The value of bit 0.
+ *
+ * @author Fabian Stemmler
+ */
+ public Bit getValue()
+ {
+ return getValue(0);
+ }
+
+ /**
+ *
+ * @param index Index of the requested bit.
+ * @return The value of the indexed bit.
+ *
+ * @author Fabian Stemmler
+ */
+ public Bit getValue(int index)
+ {
+ return values[index];
+ }
+
+ public Bit[] getValues(int start, int end)
+ {
+ int length = end - start;
+ Bit[] bits = new Bit[length];
+ System.arraycopy(values, start, bits, 0, length);
+ return bits;
+ }
+
+ /**
+ * @return An array of length n containing the values of the n bits in the
+ * {@link WireArray}. Can be safely modified.
+ *
+ * @author Fabian Stemmler
+ */
+ public Bit[] getValues()
+ {
+ return values.clone();
+ }
+
+ /**
+ * Adds an {@link WireArrayObserver}, who will be notified when the value of the
+ * {@link WireArray} is updated.
+ *
+ * @param ob The {@link WireArrayObserver} to be notified of changes.
+ * @return true if the given {@link WireArrayObserver} was not already
+ * registered, false otherwise
+ *
+ * @author Fabian Stemmler
+ */
+ public boolean addObserver(WireArrayObserver ob)
+ {
+ return observers.add(ob);
+ }
+
+ private void notifyObservers()
+ {
+ for (WireArrayObserver o : observers)
+ o.update(this);
+ }
+
+ /**
+ * Create and register a {@link WireArrayInput} object, which is tied to this
+ * {@link WireArray}.
+ */
+ public WireArrayInput createInput()
+ {
+ return new WireArrayInput(this);
+ }
+
+ private void registerInput(WireArrayInput toRegister)
+ {
+ inputs.add(toRegister);
+ }
+
+ /**
+ * A {@link WireArrayInput} feeds a constant signal into the {@link WireArray}
+ * it is tied to. The combination of all inputs determines the
+ * {@link WireArray}s final value. X dominates all other inputs Z does not
+ * affect the final value, unless there are no other inputs than Z 0 and 1 turn
+ * into X when they are mixed
+ *
+ * @author Fabian Stemmler
+ */
+ public class WireArrayInput
+ {
+ public final WireArray owner;
+ private Bit[] values;
+
+ private WireArrayInput(WireArray owner)