package traffic.light.trafficlightctrl; import java.util.LinkedList; import java.util.List; import traffic.light.ITimer; public class TrafficLightCtrlStatemachine implements ITrafficLightCtrlStatemachine { protected class SCITrafficLightImpl implements SCITrafficLight { private boolean red; public boolean getRed() { return red; } public void setRed(boolean value) { this.red = value; } private boolean yellow; public boolean getYellow() { return yellow; } public void setYellow(boolean value) { this.yellow = value; } private boolean green; public boolean getGreen() { return green; } public void setGreen(boolean value) { this.green = value; } } protected SCITrafficLightImpl sCITrafficLight; protected class SCInterfaceImpl implements SCInterface { private List listeners = new LinkedList(); public List getListeners() { return listeners; } private boolean color; private String colorValue; public boolean isRaisedColor() { return color; } protected void raiseColor(String value) { color = true; colorValue = value; for (SCInterfaceListener listener : listeners) { listener.onColorRaised(value); } } public String getColorValue() { if (! color ) throw new IllegalStateException("Illegal event value access. Event Color is not raised!"); return colorValue; } protected void clearEvents() { } protected void clearOutEvents() { color = false; } } protected SCInterfaceImpl sCInterface; private boolean initialized = false; public enum State { main_region_Yellow, main_region_Green, main_region_Red, $NullState$ }; private final State[] stateVector = new State[1]; private int nextStateIndex; private ITimer timer; private final boolean[] timeEvents = new boolean[3]; public TrafficLightCtrlStatemachine() { sCITrafficLight = new SCITrafficLightImpl(); sCInterface = new SCInterfaceImpl(); } public void init() { this.initialized = true; if (timer == null) { throw new IllegalStateException("timer not set."); } for (int i = 0; i < 1; i++) { stateVector[i] = State.$NullState$; } clearEvents(); clearOutEvents(); sCITrafficLight.setRed(false); sCITrafficLight.setYellow(false); sCITrafficLight.setGreen(false); } public void enter() { if (!initialized) { throw new IllegalStateException( "The state machine needs to be initialized first by calling the init() function."); } if (timer == null) { throw new IllegalStateException("timer not set."); } enterSequence_main_region_default(); } public void exit() { exitSequence_main_region(); } /** * @see IStatemachine#isActive() */ public boolean isActive() { return stateVector[0] != State.$NullState$; } /** * Always returns 'false' since this state machine can never become final. * * @see IStatemachine#isFinal() */ public boolean isFinal() { return false; } /** * This method resets the incoming events (time events included). */ protected void clearEvents() { sCInterface.clearEvents(); for (int i=0; i