1 28 29 package com.idaremedia.antx.go; 30 31 import java.util.Collections ; 32 import java.util.Iterator ; 33 import java.util.List ; 34 35 import org.apache.tools.ant.Project; 36 import com.idaremedia.apis.FixtureStarter; 37 import com.idaremedia.antx.helpers.Tk; 38 39 51 52 public final class Go 53 { 54 66 public interface Test 67 { 68 73 boolean pass(Project P); 74 75 79 String getParameter(); 80 81 85 String getParameterName(); 86 } 87 88 89 100 public static abstract class TestSkeleton implements Test 101 { 102 107 protected TestSkeleton() { 108 } 109 110 114 protected TestSkeleton(String param) { 115 setParameter(param); 116 } 117 118 122 public final void setParameter(String parameter) { 123 m_param = parameter; 124 } 125 126 130 public final String getParameter() { 131 return m_param; 132 } 133 134 137 public String getParameterName() { 138 return Tk.lowercaseFrom(Tk.leafNameFrom(getClass())); 139 } 140 141 145 protected void verifyInited() { 146 if (getParameter()==null) { 147 throw new IllegalStateException (); 148 } 149 } 150 151 156 public String toString() { 157 return getParameterName()+"='"+getParameter()+"'"; 158 } 159 160 private String m_param; 161 } 162 163 164 173 public static final class TestList 174 { 175 179 public static TestList newList() { 180 return new TestList(false,4); 181 } 182 183 187 public static TestList newList(int iniCapacity) { 188 return new TestList(false,iniCapacity); 189 } 190 191 195 public static TestList newSynchronizedList() { 196 return new TestList(true,4); 197 } 198 199 203 public static TestList newSynchronizedList(int iniCapacity) { 204 return new TestList(true,iniCapacity); 205 } 206 207 210 TestList(boolean mtsafe, int iniCapacity) { 211 if (mtsafe) { 212 m_tests = FixtureStarter.newSynchronizedList(iniCapacity); 213 } else { 214 m_tests = FixtureStarter.newList(iniCapacity); 215 } 216 } 217 218 221 public boolean isEmpty() { 222 return m_tests.isEmpty(); 223 } 224 225 230 public void add(Go.Test t) { 231 if (t==null) { 232 throw new IllegalArgumentException (); 233 } 234 m_tests.add(t); 235 } 236 237 242 public void add(TestList l) { 243 if (l==null) { 244 throw new IllegalArgumentException (); 245 } 246 if (!l.isEmpty()) { 247 m_tests.addAll(l.m_tests); 248 } 249 } 250 251 255 public void clear() { 256 m_tests.clear(); 257 } 258 259 262 public int size() { 263 return m_tests.size(); 264 } 265 266 269 public Go.Test get(int i) { 270 return (Go.Test)m_tests.get(i); 271 } 272 273 278 public Go.Test get(Class c) 279 { 280 if (c==null) { 281 throw new IllegalArgumentException (); 282 } 283 synchronized(m_tests) { 284 for (int i=0,N=size();i<N;i++) { 285 Go.Test t= (Go.Test)m_tests.get(i); 286 if (c.isInstance(t)) { 287 return t; 288 } 289 } 290 } 291 return null; 292 } 293 294 295 300 public boolean contains(Class c) 301 { 302 return get(c)!=null; 303 } 304 305 310 public Iterator iterator() 311 { 312 return Collections.unmodifiableList(m_tests).iterator(); 313 } 314 315 320 public boolean equals(Object o) { 321 if (o==this) { 322 return true; 323 } 324 if (o==null) { 325 return false; 326 } 327 if (o.getClass()==TestList.class) { 328 return m_tests.equals(((TestList)o).m_tests); 329 } 330 return false; 331 } 332 333 337 public int hashCode() 338 { 339 return m_tests.hashCode(); 340 } 341 342 private final List m_tests; 343 } 344 345 346 349 private Go() 350 { 351 } 352 } 353 354 355 356 | Popular Tags |