一个流程执行器的简单实现
推荐
原创
©著作权归作者所有:来自51CTO博客作者leizhimin的原创作品,请联系作者获取转载授权,否则将追究法律责任
/**
* 过程执行器
*
* @author leizhimin 2014/8/7 17:15
*/
public class Test {
public static void main(String[] args) {
dotask(new Task(0));
System.out.println("------------------");
dotask(new Task(2));
System.out.println("------------------");
dotask(new Task(4));
}
private static void dotask(Task task) {
switch (task.getState()) {
case 0:
do1(task);
break;
case 1:
do2(task);
break;
case 2:
do3(task);
break;
case 3:
do4(task);
break;
case 4:
do5(task);
break;
default:
break;
}
}
private static void do1(Task task) {
System.out.println("do1...");
task.setState(1);
dotask(task);
}
private static void do2(Task task) {
System.out.println("do2...");
task.setState(2);
dotask(task);
}
private static void do3(Task task) {
System.out.println("do3...");
task.setState(3);
dotask(task);
}
private static void do4(Task task) {
System.out.println("do4...");
task.setState(4);
dotask(task);
}
private static void do5(Task task) {
System.out.println("do5...");
task.setState(5);
dotask(task);
}
}
class Task {
private int state;
Task(int state) {
this.state = state;
}
public int getState() {
return state;
}
public void setState(int state) {
this.state = state;
}
}
do1...
do2...
do3...
do4...
do5...
------------------
do3...
do4...
do5...
------------------
do5...
Process finished with exit code 0