1 26 27 package net.groboclown.util.states.v1; 28 29 import java.util.Vector ; 30 31 32 38 public class StateSet 39 { 40 43 44 47 48 51 52 55 56 59 60 63 64 private StateCategory states = new StateCategory(); 65 private Vector statefuls = new Vector (); 66 private State currentState = null; 67 68 69 72 73 76 public StateSet() 77 { 78 } 80 81 82 83 84 85 88 91 public State createNextState() 92 { 93 return this.states.getNextState(); 94 } 95 96 97 100 public void addStateful( Stateful s ) 101 { 102 if (s == null) 103 { 104 throw new IllegalArgumentException ( "no null args" ); 105 } 106 s.initialize( this.states ); 107 this.statefuls.addElement( s ); 108 } 109 110 111 114 public void removeStateful( Stateful s ) 115 { 116 if (s == null) 117 { 118 throw new IllegalArgumentException ( "no null args" ); 119 } 120 this.statefuls.removeElement( s ); 121 } 122 123 124 127 public void setState( State s ) 128 { 129 if (!this.states.isOfCategory( s )) 130 { 131 throw new IllegalStateException ("wrong state category"); 132 } 133 this.currentState = s; 134 for (int i = this.statefuls.size(); --i >= 0;) 135 { 136 ((Stateful)this.statefuls.elementAt(i)).setState( s ); 137 } 138 } 139 140 141 144 145 148 149 } 150 151 | Popular Tags |