| 46 | } |
| 47 | |
| 48 | class Washer extends StateMachine { |
| 49 | private int i = 0; |
| 50 | private Iterator<State> states = |
| 51 | Arrays.asList( |
| 52 | new Wash(), new Spin(), |
| 53 | new Rinse(), new Spin() |
| 54 | ).iterator(); |
| 55 | Washer() { runAll(); } |
| 56 | @Override public boolean changeState() { |
| 57 | if(!states.hasNext()) |
| 58 | return false; |
| 59 | // Set the surrogate reference |
| 60 | // to a new State object: |
| 61 | currentState = states.next(); |
| 62 | return true; |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | public class StateMachineDemo { |
| 67 | public static void main(String[] args) { |