This is the syntax highlighted version of Wire.java.
/*************************************************************************
* Compilation: javac Wire.java
*
* ADT for circuit wire.
*
*************************************************************************/
public class Wire {
private Wire to; // next wire in chain
private Ternary signal; // value of the wire
private Circuit circuit; // circuit in which this wire lives
public Wire(Circuit circuit) {
this.circuit = circuit;
this.signal = Ternary.UNKNOWN;
this.to = null;
}
public void solderTo(Wire x) { to = x; } // connect this Wire to x
public Ternary isOn() { return signal; } // return the value of this Wire
// set the value of this Wire, and propage its value recursively to
// neighboring wire or enclosing circuit
public void turnOn() { setSignal(Ternary.TRUE); }
public void turnOff() { setSignal(Ternary.FALSE); }
public void setSignal(Ternary s) {
if (s != signal) {
signal = s;
if (to != null) to.setSignal(signal);
if (circuit != null) circuit.propagate();
}
}
}
Last updated: Mon May 24 12:02:56 EDT 2004
.
Copyright © 2004, Robert Sedgewick and Kevin Wayne.