INF530 Lesson 2

Intro to State Machine

Take regular expression analysis of url as an example:

  • State:
  • Event:
  • Action:
interface Action {
    State execute(Event e, State s);
}

class ActionFirst implements Action {
    State execute(Event e, State s) {
        ...
    }
}

class Pair {
    State first;
    Event second;

    ...
}

public class Main {
    HashMap stateMachine = new HashMap(Pair<State, Event>, Action);
    stateMachine.put(new Pair<State, Event>, new ActionFirst);
    ...
}