/** Add a transition to the allowed transition map. * * @param transition * @return this to allow chained addTransition calls */ public State addTransition(Transition transition) { allowedTransitions.put(transition.getName(), transition); return this; }
public String toString() { StringBuffer tmp = new StringBuffer("State(name="); tmp.append(name); Iterator i = allowedTransitions.entrySet().iterator(); while( i.hasNext() ) { Map.Entry e = (Map.Entry) i.next(); tmp.append("\n\t on: "); tmp.append(e.getKey()); Transition t = (Transition) e.getValue(); tmp.append(" go to: "); tmp.append(t.getTarget().getName()); } tmp.append(')'); return tmp.toString(); } }
log.debug(msg); Transition t = new Transition(name, target); s.addTransition(t);
/** Transition to the next state given the name of a valid transition. * @param actionName - the name of transition that is valid for the * current state. * @return the next state * @throws IllegalTransitionException */ public State nextState(String actionName) throws IllegalTransitionException { Transition t = currentState.getTransition(actionName); if( t == null ) { String msg = "No transition for action: '" + actionName + "' from state: '" + currentState.getName() + "'"; throw new IllegalTransitionException(msg); } State nextState = t.getTarget(); log.trace("nextState("+actionName+") = "+nextState); currentState = nextState; return currentState; }