1 6 7 package org.jfox.ioc.common; 8 9 12 13 public final class State { 14 15 public final static State ORIGINAL = new State(0, "Original"); 16 17 20 public final static State INITIALIZING = new State(1, "Initializing"); 21 22 25 public final static State INITIALIZED = new State(2, "Initialized"); 26 27 30 public final static State STARTING = new State(3, "Starting"); 31 32 35 public final static State STARTED = new State(4, "Started"); 36 37 40 public final static State STOPPING = new State(5, "Stopping"); 41 42 45 public final static State STOPPED = new State(6, "Stopped"); 46 47 50 public final static State DESTROYING = new State(7, "Destroying"); 51 52 55 public final static State DESTROYED = new State(8, "Destroyed"); 56 57 60 public final static State INTERRUPTED = new State(9, "Interrupted"); 61 62 63 public int id = 0; 64 public String name = ""; 65 66 public State(int id, String name) { 67 this.id = id; 68 this.name = name; 69 } 70 71 public int getId() { 72 return id; 73 } 74 75 public String getName() { 76 return name; 77 } 78 79 public int hashCode() { 80 return (id + "").hashCode() + name.hashCode(); 81 } 82 83 public String toString() { 84 return id + " [" + name + "]"; 85 } 86 87 public boolean equals(Object obj) { 88 if(obj instanceof State) { 89 State state = (State) obj; 90 return state.id == id && state.name.equals(name); 91 } 92 return false; 93 94 } 95 96 public static boolean canInit(State state) { 97 if(state == State.ORIGINAL || state == State.DESTROYED) { 98 return true; 99 } 100 return false; 101 } 102 103 public static boolean canStart(State state) { 104 if(state == State.STOPPED || state == State.INITIALIZED) { 105 return true; 106 } 107 return false; 108 } 109 110 public static boolean canStop(State state) { 111 if(state == State.STARTED) { 112 return true; 113 } 114 return false; 115 } 116 117 public static boolean canDestroy(State state) { 118 if(state == State.INITIALIZED || state == State.STOPPED || state == State.INTERRUPTED) { 119 return true; 120 } 121 return false; 122 } 123 124 } 125 126 | Popular Tags |