@@ -0,0 +1,2058 @@
+%0Apackage test.design.pattern.behavior;%0A%0Apublic class testState %7B%0A    public static void main(String%5B%5D args) %7B%0A%0A        // %E5%81%87%E8%AE%BE%E8%B7%AF%E7%81%AF%E5%BC%80%E5%A7%8B%E6%98%AF%E7%BB%BF%E7%81%AF%0A        State state = new GreenState();%0A        TrafficLight light = new TrafficLight(state);%0A        light.work();%0A%0A    %7D%0A%7D%0A%0Ainterface State %7B%0A%0A    public void change(TrafficLight light);%0A%7D%0A%0Aclass GreenState implements State %7B%0A    private static final Long SLEEP_TIME = 2000L;%0A%0A    @Override%0A    public void change(TrafficLight light) %7B%0A%0A        System.out.println(%22%E7%8E%B0%E5%9C%A8%E6%98%AF%E7%BB%BF%E7%81%AF%EF%BC%8C%E5%8F%AF%E4%BB%A5%E9%80%9A%E8%A1%8C%22);%0A        // %E7%BB%BF%E7%81%AF%E4%BA%AE1%E7%A7%92%0A        try %7B%0A            Thread.sleep(SLEEP_TIME);%0A        %7D catch (InterruptedException e) %7B%0A            // TODO Auto-generated catch block%0A            e.printStackTrace();%0A        %7D%0A        light.setState(new YellowState());%0A    %7D%0A%0A%7D%0A%0Aclass YellowState implements State %7B%0A    private static final Long SLEEP_TIME = 500L;%0A%0A    @Override%0A    public void change(TrafficLight light) %7B%0A%0A        System.out.println(%22%E7%8E%B0%E5%9C%A8%E6%98%AF%E9%BB%84%E7%81%AF%EF%BC%8C%E8%AD%A6%E7%A4%BA%22);%0A        // %E7%BA%A2%E7%81%AF%E4%BA%AE0.5%E7%A7%92%0A        try %7B%0A            Thread.sleep(SLEEP_TIME);%0A        %7D catch (InterruptedException e) %7B%0A            // TODO Auto-generated catch block%0A            e.printStackTrace();%0A        %7D%0A        light.setState(new RedState());%0A    %7D%0A%0A%7D%0A%0Aclass RedState implements State %7B%0A    private static final Long SLEEP_TIME = 1000L;%0A%0A    @Override%0A    public void change(TrafficLight light) %7B%0A%0A        System.out.println(%22%E7%8E%B0%E5%9C%A8%E6%98%AF%E7%BA%A2%E7%81%AF%EF%BC%8C%E7%A6%81%E6%AD%A2%E9%80%9A%E8%A1%8C%22);%0A        // %E7%BA%A2%E7%81%AF%E4%BA%AE1%E7%A7%92%0A        try %7B%0A            Thread.sleep(SLEEP_TIME);%0A        %7D catch (InterruptedException e) %7B%0A            // TODO Auto-generated catch block%0A            e.printStackTrace();%0A        %7D%0A        light.setState(new GreenState());%0A    %7D%0A%0A%7D%0A%0Aclass TrafficLight %7B%0A%0A    private State state;%0A%0A    private void change() %7B%0A        state.change(this);%0A    %7D%0A%0A    public void work() %7B%0A        while (true) %7B%0A            change();%0A        %7D%0A    %7D%0A%0A    public TrafficLight(State state) %7B%0A        this.state = state;%0A    %7D%0A%0A    public State getState() %7B%0A        return state;%0A    %7D%0A%0A    public void setState(State state) %7B%0A        this.state = state;%0A    %7D%0A%0A%7D%0A

add state pattern