Control extends UnaryInstruction and controls its body by the presence of an event: the body is run only during the instants where the event is present.
public class Control extends UnaryInstruction
implements EventConsts
{
private String eventName;
public Control(String eventName,Instruction body){
this.eventName = eventName;
this.body = body;
}
final public boolean equals(Instruction inst){
return super.equals(inst)
&& eventName.equals(((Control)inst).eventName);
}
final public String toString(){
return "control " + body + " by " + eventName;
}
final protected byte activation(Machine machine)
{
Event event = machine.getEvent(eventName);
switch(event.presence(machine)){
case PRESENT: return body.activ(machine);
case ABSENT: return STOP;
default: return SUSP;
}
}
}