1 7 package tests.jfun.yan.testmodel; 8 9 15 public class StatefulResource implements SimpleResource, 16 Engine{ 17 private int init = 0; 18 private int destroyed = 0; 19 private final Engine sr; 20 public StatefulResource(final Engine sr) { 21 this.sr = sr; 22 } 23 24 public int getDestroyedCount() { 25 return destroyed; 26 } 27 public int getInitCount() { 28 return init; 29 } 30 31 public void destroy() { 32 if(sr.isDestroyed()){ 33 throw new IllegalStateException ("parts destroyed prematurely"); 34 } 35 destroyed ++; 36 } 37 public void initialize() { 38 if(!sr.isInitialized()) 39 throw new IllegalStateException ("parts not initialized yet"); 40 init++; 41 } 42 public boolean isInitialized(){ 43 return init>0; 44 } 45 public boolean isDestroyed(){ 46 return destroyed > 0; 47 } 48 public void start(){ 49 throw new UnsupportedOperationException ("start"); 50 } 51 52 public void stop(){ 53 throw new UnsupportedOperationException ("stop"); 54 } 55 public boolean isStarted(){ 56 throw new UnsupportedOperationException ("isStarted"); 57 } 58 59 public boolean isStopped(){ 60 throw new UnsupportedOperationException ("isStopped"); 61 } 62 63 } 64 | Popular Tags |