Adding FSM in java