1 29 package net.sourceforge.groboutils.mbtf.v1.engine; 30 31 32 import net.sourceforge.groboutils.mbtf.v1.IState; 33 import net.sourceforge.groboutils.mbtf.v1.IValidate; 34 import net.sourceforge.groboutils.mbtf.v1.ITransition; 35 36 37 44 public class StateImpl implements IState 45 { 46 private String name; 47 private ITransition[] trans; 48 private IValidate[] validate; 49 50 51 public StateImpl( String name, ITransition[] t, IValidate[] v ) 52 { 53 if (name == null) 54 { 55 throw new IllegalArgumentException ("no null name"); 56 } 57 58 if (t == null) 59 { 60 t = new ITransition[0]; 61 } 62 else 63 { 64 int len = t.length; 65 ITransition[] tt = new ITransition[ len ]; 66 for (int i = len; --i >= 0;) 67 { 68 if (t[i] == null) 69 { 70 throw new IllegalArgumentException ( 71 "no nulls allowed in ITransition array (index "+i+")"); 72 } 73 tt[i] = t[i]; 75 } 76 t = tt; 77 } 78 79 if (v == null) 80 { 81 v = new IValidate[0]; 82 } 83 else 84 { 85 int len = v.length; 86 IValidate[] vv = new IValidate[ len ]; 87 for (int i = len; --i >= 0;) 88 { 89 if (v[i] == null) 90 { 91 throw new IllegalArgumentException ( 92 "no nulls allowed in IValidate array (index "+i+")"); 93 } 94 vv[i] = v[i]; 96 } 97 v = vv; 98 } 99 100 this.name = name; 101 this.trans = t; 102 this.validate = v; 103 } 104 105 106 112 public String getName() 113 { 114 return this.name; 115 } 116 117 118 124 public ITransition[] getTransitions() 125 { 126 int len = this.trans.length; 127 ITransition t[] = new ITransition[ len ]; 128 System.arraycopy( this.trans, 0, t, 0, len ); 129 return t; 130 } 131 132 133 142 public IValidate[] getValidates() 143 { 144 int len = this.validate.length; 145 IValidate v[] = new IValidate[ len ]; 146 System.arraycopy( this.validate, 0, v, 0, len ); 147 return v; 148 } 149 150 151 public String toString() 152 { 153 return "[State "+getName()+"]"; 154 } 155 } 156 157 | Popular Tags |