1 22 package org.jboss.util.state; 23 24 import java.util.HashMap ; 25 import java.util.Map ; 26 import java.util.Iterator ; 27 28 33 public class State 34 { 35 36 private String name; 37 38 private HashMap allowedTransitions = new HashMap (); 39 40 private Object data; 41 42 public State(String name) 43 { 44 this(name, null); 45 } 46 public State(String name, Map transitions) 47 { 48 this.name = name; 49 if( transitions != null ) 50 { 51 allowedTransitions.putAll(transitions); 52 } 53 } 54 55 58 public String getName() 59 { 60 return name; 61 } 62 63 public Object getData() 64 { 65 return data; 66 } 67 public void setData(Object data) 68 { 69 this.data = data; 70 } 71 72 75 public boolean isAcceptState() 76 { 77 return allowedTransitions.size() == 0; 78 } 79 80 85 public State addTransition(Transition transition) 86 { 87 allowedTransitions.put(transition.getName(), transition); 88 return this; 89 } 90 91 96 public Transition getTransition(String name) 97 { 98 Transition t = (Transition) allowedTransitions.get(name); 99 return t; 100 } 101 102 105 public Map getTransitions() 106 { 107 return allowedTransitions; 108 } 109 110 public String toString() 111 { 112 StringBuffer tmp = new StringBuffer ("State(name="); 113 tmp.append(name); 114 Iterator i = allowedTransitions.entrySet().iterator(); 115 while( i.hasNext() ) 116 { 117 Map.Entry e = (Map.Entry ) i.next(); 118 tmp.append("\n\t on: "); 119 tmp.append(e.getKey()); 120 Transition t = (Transition) e.getValue(); 121 tmp.append(" go to: "); 122 tmp.append(t.getTarget().getName()); 123 } 124 tmp.append(')'); 125 return tmp.toString(); 126 } 127 } 128 | Popular Tags |