Package eu.bandm.tools.message
Class TrafficMessageReceiver
java.lang.Object
eu.bandm.tools.message.TrafficMessageReceiver
- All Implemented Interfaces:
MessageReceiver<Message>
Graphic indication of received messages.
One or more
As long as no message arrives, the intial state is left unchanged.
One or more
TrafficLight
objects can be linked to this kind of
message receiver.
The state of all these is changed to "red" as soon as a critical
message arrives, and to "yellow" as soon as any other message
arrives---provided the state is not red.
As long as no message arrives, the intial state is left unchanged.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addLight
(TrafficLight light) Add the given traffic light a listener to state changes.void
clear()
Convenience: set state of all currently added traffic lights to "green".Convenience: constructs a new traffic light and adds it as listenergetState()
Return the current state.void
Sets state toTrafficLight.State.red
if the received message is critcal, otherwise to yellow, if it is not already red.void
removeLight
(TrafficLight light) Removes the given light as a listener to state changes.protected void
setState
(TrafficLight.State state) Convenience: change the state of all currently added traffic lights to the given state.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface eu.bandm.tools.message.MessageReceiver
ifSubcriticalThen, ifSubcriticalThen, ifSubcriticalThenElse
-
Constructor Details
-
TrafficMessageReceiver
public TrafficMessageReceiver()Only constructor
-
-
Method Details
-
addLight
Add the given traffic light a listener to state changes.- Parameters:
light
- added as listener
-
removeLight
Removes the given light as a listener to state changes.- Parameters:
light
- removed as listener
-
createLight
Convenience: constructs a new traffic light and adds it as listener- Returns:
- a new traffic light
-
clear
public void clear()Convenience: set state of all currently added traffic lights to "green". -
receive
Sets state toTrafficLight.State.red
if the received message is critcal, otherwise to yellow, if it is not already red.- Specified by:
receive
in interfaceMessageReceiver<Message>
- Parameters:
msg
- the message to receive.- See Also:
-
getState
Return the current state.- Returns:
- the current state.
-
setState
Convenience: change the state of all currently added traffic lights to the given state.- Parameters:
state
- the new state of all traffic lights
-