标签:接下来 tran 精通 ejs msi min noi mtu gms
全文一共1543字,预计阅读时间10分钟
** * 程序员类. * * @author jialin.li * @date 2019-12-30 17:38 */ public class Programmer { private int empiricalValue; public void setEmpiricalValue(int empiricalValue) { this.empiricalValue = empiricalValue; } public void evaluate() { if(empiricalValue < 100){ System.out.println("MT"); }else if(empiricalValue < 200){ System.out.println("开发助理"); }else if(empiricalValue < 300){ System.out.println("初级程序员"); }else if(empiricalValue < 400){ System.out.println("中级程序员"); }else if(empiricalValue < 500){ System.out.println("高级程序员"); }else if(empiricalValue < 600){ System.out.println("技术专家"); } } }
/** * 客户端. * * @author jialin.li * @date 2019-12-30 18:28 */ public class Main { public static void main(String[] args) { Programmer programmer = new Programmer(); programmer.setEmpiricalValue(50); programmer.evaluate(); programmer.setEmpiricalValue(150); programmer.evaluate(); programmer.setEmpiricalValue(250); programmer.evaluate(); programmer.setEmpiricalValue(350); programmer.evaluate(); programmer.setEmpiricalValue(450); programmer.evaluate(); programmer.setEmpiricalValue(550); programmer.evaluate(); } }
MT
开发助理
初级程序员
中级程序员
高级程序员
技术专家
/** * 状态处理接口. * * @author jialin.li * @date 2019-12-30 19:23 */ public interface State { void handle(Programmer programmer); }
/** * 程序员类. * * @author jialin.li * @date 2019-12-30 17:38 */ public class Programmer { /** * 经验值 */ private int empiricalValue; /** * 当前状态 */ private State state = new MTState(); public void setEmpiricalValue(int empiricalValue) { this.empiricalValue = empiricalValue; } public int getEmpiricalValue() { return empiricalValue; } public void setState(State state) { this.state = state; } public void handle() { state.handle(this); } }
/** * MT. * * @author jialin.li * @date 2019-12-30 19:30 */ public class MTState implements State { @Override public void handle(Programmer programmer) { int empiricalValue = programmer.getEmpiricalValue(); if (empiricalValue < 100) { System.out.println("MT"); } else { State juniorProgrammer = new JuniorProgrammer(); programmer.setState(juniorProgrammer); juniorProgrammer.handle(programmer); } } }
/** * 助理程序员. * * @author jialin.li * @date 2019-12-30 19:33 */ public class ProgrammerAssistant implements State{ @Override public void handle(Programmer programmer) { int empiricalValue = programmer.getEmpiricalValue(); if(empiricalValue < 200){ System.out.println("开发助理"); }else{ JuniorProgrammer juniorProgrammer = new JuniorProgrammer(); programmer.setState(juniorProgrammer); juniorProgrammer.handle(programmer); } } }
/** * 初级程序员. * * @author jialin.li * @date 2019-12-30 19:31 */ public class JuniorProgrammer implements State { @Override public void handle(Programmer programmer) { int empiricalValue = programmer.getEmpiricalValue(); if (empiricalValue < 300) { System.out.println("初级程序员"); } else { State middleProgrammer = new MiddleProgrammer(); programmer.setState(middleProgrammer); middleProgrammer.handle(programmer); } } }
/** * 中级程序员. * * @author jialin.li * @date 2019-12-30 19:32 */ public class MiddleProgrammer implements State { @Override public void handle(Programmer programmer) { int empiricalValue = programmer.getEmpiricalValue(); if (empiricalValue < 400) { System.out.println("中级程序员"); } else { SeniorProgrammer seniorProgrammer = new SeniorProgrammer(); programmer.setState(seniorProgrammer); seniorProgrammer.handle(programmer); } } }
/** * 高级程序员. * * @author jialin.li * @date 2019-12-30 19:34 */ public class SeniorProgrammer implements State { @Override public void handle(Programmer programmer) { int empiricalValue = programmer.getEmpiricalValue(); if (empiricalValue < 500) { System.out.println("高级程序员"); } else { Professor professor = new Professor(); programmer.setState(professor); professor.handle(programmer); } } }
/** * @author jialin.li * @date 2019-12-30 19:35 */ public class Professor implements State { @Override public void handle(Programmer programmer) { System.out.println("技术专家"); } }
/** * @author jialin.li * @date 2019-12-30 19:35 */ public class Professor implements State { @Override public void handle(Programmer programmer) { System.out.println("技术专家"); } }
/** * 客户端. * * @author jialin.li * @date 2019-12-30 19:36 */ public class Main { public static void main(String[] args) { Programmer programmer = new Programmer(); programmer.setEmpiricalValue(50); programmer.handle(); programmer.setEmpiricalValue(150); programmer.handle(); programmer.setEmpiricalValue(250); programmer.handle(); programmer.setEmpiricalValue(350); programmer.handle(); programmer.setEmpiricalValue(450); programmer.handle(); programmer.setEmpiricalValue(550); programmer.handle(); } }
MT
初级程序员
初级程序员
中级程序员
高级程序员
技术专家
@Override public final synchronized void init() throws LifecycleException { if (!state.equals(LifecycleState.NEW)) { invalidTransition(Lifecycle.BEFORE_INIT_EVENT); } try { setStateInternal(LifecycleState.INITIALIZING, null, false); initInternal(); setStateInternal(LifecycleState.INITIALIZED, null, false); } catch (Throwable t) { handleSubClassException(t, "lifecycleBase.initFail", toString()); } }
private void invalidTransition(String type) throws LifecycleException { String msg = sm.getString("lifecycleBase.invalidTransition", type, toString(), state); throw new LifecycleException(msg); }
期待您的关注、推荐、收藏,同时也期待您的纠错和批评。
标签:接下来 tran 精通 ejs msi min noi mtu gms
原文地址:https://www.cnblogs.com/nedulee/p/12121573.html