1 2 package simple; 3 4 import java.util.ArrayList ; 5 6 class MyClass5c extends MyClass5a 7 { 8 boolean factory; 9 private boolean preset; 10 private boolean postset; 11 private int value; 12 13 private void preset(Object obj) { 14 if (!(obj instanceof ArrayList )) { 15 throw new IllegalStateException ("factory called with wrong object"); 16 } 17 preset = true; 18 value = 1; 19 } 20 21 private void postset(Object obj) { 22 if (!(obj instanceof ArrayList )) { 23 throw new IllegalStateException ("factory called with wrong object"); 24 } 25 postset = true; 26 if (value == 2) { 27 value = 3; 28 } 29 } 30 31 private void preget(Object obj) { 32 if (!(obj instanceof ArrayList )) { 33 throw new IllegalStateException ("factory called with wrong object"); 34 } 35 value = 2; 36 } 37 38 protected void verify() { 39 if (!factory || !preset || !postset) { 40 throw new IllegalStateException 41 ("factory, pre-set, or post-set method not called"); 42 } 43 } 44 } 45 | Popular Tags |