Java Finite State Machine implementation