package simulator.payloads;
import simulator.framework.*;
/**
* Network message indicates whether a hall call has been requested at
* Hallway[f,b] for direction d, and a framework message indicates whether the
* button is currently held down. Set to False at initialization in both
* cases.
*
* @author jdevale
*/
public class HallCallPayload extends PhysicalPayload {
public final int floor;
public final Hallway hallway;
public final Direction direction;
public boolean pressed;
public HallCallPayload(int floor, Hallway hallway, Direction direction) {
super(PhysicalPayload.HallCallEvent,
ReplicationComputer.computeReplicationId(floor, hallway,
direction));
this.floor = floor;
this.hallway = hallway;
this.direction = direction;
pressed = false;
setName(
"HallCallPayload[" + floor + "," + hallway + "," + direction
+ "]");
}
public HallCallPayload set(boolean pressed) {
this.pressed = pressed;
return this;
}
@Override
public void copyFrom(Payload p) {
super.copyFrom(p);
HallCallPayload c = (HallCallPayload) p;
if (this.floor != c.floor || this.hallway != c.hallway
|| this.direction != c.direction) {
throw new RuntimeException("Wrong replication instance of " + this);
}
pressed = c.pressed;
}
@Override
public String toString() {
StringBuffer sb = new StringBuffer(super.toString());
sb.append("(" + pressed + ")");
return sb.toString();
}
@Override
public void deliverTo(Networkable networkable) {
networkable.receive(this);
}
@Override
public Payload clone() {
HallCallPayload c = new HallCallPayload(floor, hallway, direction);
c.copyFrom(this);
return c;
}
}
|