Simple state machine implementation for Java