前页 | 后页 |
从旧版StateMachine模板生成的Java代码
私有枚举StateType:int
{
ProcessOrder_Delivered,
ProcessOrder_Packed,
ProcessOrder_Closed,
ProcessOrder_Dispatched,
ProcessOrder_New,
ST_NOSTATE
}
私有枚举TransitionType:int
{
ProcessOrder_Delivered_to_ProcessOrder_Closed,
TT_NOTRANSITION
}
私有枚举CommandType
{
做,
条目,
出口
}
私有StateType currState;
私有StateType nextState;
私有TransitionType currTransition;
私有布尔超越;
私有StateType ProcessOrder_history;
私有无效processOrder_Delivered(CommandType命令)
{
开关(命令)
{
案例:
{
//做行为..
setStatus(已交付);
//国家的转型
if((状态==已交付))
{
nextState = StateType.ProcessOrder_Closed;
currTransition = TransitionType.ProcessOrder_Delivered_to_ProcessOrder_Closed;
}
打破;
}
默认:
{
打破;
}
}
}
私有无效processOrder_Packed(CommandType命令)
{
开关(命令)
{
案例:
{
//做行为..
setStatus(Packed);
//国家的转型
nextState = StateType.ProcessOrder_Dispatched;
打破;
}
默认:
{
打破;
}
}
}
私有无效processOrder_Closed(CommandType命令)
{
开关(命令)
{
案例:
{
//做行为..
//国家的转型
打破;
}
默认:
{
打破;
}
}
}
私有无效processOrder_Dispatched(CommandType命令)
{
开关(命令)
{
案例:
{
//做行为..
setStatus(Dispatched);
//国家的转型
nextState = StateType.ProcessOrder_Delivered;
打破;
}
默认:
{
打破;
}
}
}
私有无效processOrder_New(CommandType命令)
{
开关(命令)
{
案例:
{
//做行为..
setStatus(new);
//国家的转型
nextState = StateType.ProcessOrder_Packed;
打破;
}
默认:
{
打破;
}
}
}
私有无效StatesProc(StateType currState,CommandType命令)
{
开关(currState)
{
案例ProcessOrder_Delivered:
{
processOrder_Delivered(command);
打破;
}
案例ProcessOrder_Packed:
{
processOrder_Packed(命令);
打破;
}
案例ProcessOrder_Closed:
{
processOrder_Closed(command);
打破;
}
案例ProcessOrder_Dispatched:
{
processOrder_Dispatched(command);
打破;
}
案例ProcessOrder_New:
{
processOrder_New(command);
打破;
}
默认:
打破;
}
}
私有void TransitionsProc(TransitionType transition)
{
开关(转换)
{
案例ProcessOrder_Delivered_to_ProcessOrder_Closed:
{
setStatus(closed);
打破;
}
默认:
打破;
}
}
私人无效initalizeStateMachine()
{
currState = StateType.ProcessOrder_New;
nextState = StateType.ST_NOSTATE;
currTransition = TransitionType.TT_NOTRANSITION;
}
私有无效runStateMachine()
{
而(真)
{
如果(currState == StateType.ST_NOSTATE)
{
打破;
}
currTransition = TransitionType.TT_NOTRANSITION;
StatesProc(currState,CommandType.Do);
//然后检查在do行为之后是否分配了任何有效的过渡
如果(nextState == StateType.ST_NOSTATE)
{
打破;
}
如果(currTransition!= TransitionType.TT_NOTRANSITION)
{
TransitionsProc(currTransition);
}
如果(currState!= nextState)
{
StatesProc(currState,CommandType.Exit);
StatesProc(nextState,CommandType.Entry);
currState = nextState;
}
}
}