1 10 11 package com.triactive.jdo.test; 12 13 import javax.jdo.InstanceCallbacks; 14 15 16 public class Widget extends TestObject implements InstanceCallbacks 17 { 18 private boolean booleanField; 19 private Boolean booleanObjField; 20 private byte byteField; 21 private Byte byteObjField; 22 private char charField; 23 private Character charObjField; 24 private short shortField; 25 private Short shortObjField; 26 private int intField; 27 private Integer intObjField; 28 private long longField; 29 private Long longObjField; 30 31 32 public Widget() 33 { 34 } 35 36 37 public boolean getBooleanField() 38 { 39 return booleanField; 40 } 41 42 43 public Boolean getBooleanObjField() 44 { 45 return booleanObjField; 46 } 47 48 49 public byte getByteField() 50 { 51 return byteField; 52 } 53 54 55 public Byte getByteObjField() 56 { 57 return byteObjField; 58 } 59 60 61 public char getCharField() 62 { 63 return charField; 64 } 65 66 67 public Character getCharObjField() 68 { 69 return charObjField; 70 } 71 72 73 public short getShortField() 74 { 75 return shortField; 76 } 77 78 79 public Short getShortObjField() 80 { 81 return shortObjField; 82 } 83 84 85 public int getIntField() 86 { 87 return intField; 88 } 89 90 91 public Integer getIntObjField() 92 { 93 return intObjField; 94 } 95 96 97 public long getLongField() 98 { 99 return longField; 100 } 101 102 103 public Long getLongObjField() 104 { 105 return longObjField; 106 } 107 108 109 public void setByteField(byte byteField) 110 { 111 this.byteField = byteField; 112 } 113 114 115 public void setShortField(short shortField) 116 { 117 this.shortField = shortField; 118 } 119 120 121 public void setIntField(int intField) 122 { 123 this.intField = intField; 124 } 125 126 127 public byte setByteFieldRandom() 128 { 129 byte b = nextByte(); 130 131 this.byteField = b; 132 133 return b; 134 } 135 136 137 142 143 public void fillRandom() 144 { 145 booleanField = r.nextBoolean(); 146 booleanObjField = nextNull() ? null : new Boolean (r.nextBoolean()); 147 byteField = nextByte(); 148 byteObjField = nextNull() ? null : new Byte (nextByte()); 149 charField = nextCharacter(); 150 charObjField = nextNull() ? null : new Character (nextCharacter()); 151 shortField = (short)(r.nextInt(Short.MAX_VALUE * 2) - Short.MAX_VALUE); 152 shortObjField = nextNull() ? null : new Short ((short)(r.nextInt(Short.MAX_VALUE * 2) - Short.MAX_VALUE)); 153 intField = r.nextInt(); 154 intObjField = nextNull() ? null : new Integer (r.nextInt()); 155 longField = r.nextLong(); 156 longObjField = nextNull() ? null : new Long (r.nextLong()); 157 } 158 159 160 171 172 public boolean compareTo(Object obj) 173 { 174 if (obj == this) 175 return true; 176 177 if (!(obj instanceof Widget)) 178 return false; 179 180 Widget w = (Widget)obj; 181 182 if (booleanObjField == null) { if (w.booleanObjField != null) return false; } 183 else if (!booleanObjField.equals(w.booleanObjField)) return false; 184 185 if (byteObjField == null) { if (w.byteObjField != null) return false; } 186 else if (!byteObjField.equals(w.byteObjField)) return false; 187 188 if (charObjField == null) { if (w.charObjField != null) return false; } 189 else if (!charObjField.equals(w.charObjField)) return false; 190 191 if (shortObjField == null) { if (w.shortObjField != null) return false; } 192 else if (!shortObjField.equals(w.shortObjField)) return false; 193 194 if (intObjField == null) { if (w.intObjField != null) return false; } 195 else if (!intObjField.equals(w.intObjField)) return false; 196 197 if (longObjField == null) { if (w.longObjField != null) return false; } 198 else if (!longObjField.equals(w.longObjField)) return false; 199 200 return booleanField == w.booleanField 201 && byteField == w.byteField 202 && charField == w.charField 203 && shortField == w.shortField 204 && intField == w.intField 205 && longField == w.longField; 206 } 207 208 209 215 216 public String toString() 217 { 218 StringBuffer s = new StringBuffer (super.toString()); 219 220 s.append(" booleanField = ").append(booleanField); 221 s.append('\n'); 222 s.append(" booleanObjField = ").append(booleanObjField); 223 s.append('\n'); 224 s.append(" byteField = ").append(byteField); 225 s.append('\n'); 226 s.append(" byteObjField = ").append(byteObjField); 227 s.append('\n'); 228 s.append(" charField = ").append(charField); 229 s.append('\n'); 230 s.append(" charObjField = ").append(charObjField); 231 s.append('\n'); 232 s.append(" shortField = ").append(shortField); 233 s.append('\n'); 234 s.append(" shortObjField = ").append(shortObjField); 235 s.append('\n'); 236 s.append(" intField = ").append(intField); 237 s.append('\n'); 238 s.append(" intObjField = ").append(intObjField); 239 s.append('\n'); 240 s.append(" longField = ").append(longField); 241 s.append('\n'); 242 s.append(" longObjField = ").append(longObjField); 243 s.append('\n'); 244 245 return s.toString(); 246 } 247 248 public void jdoPostLoad() {} 249 250 public void jdoPreClear() {} 251 252 public void jdoPreDelete() {} 253 254 public void jdoPreStore() 255 { 256 262 if (booleanField && intField < 0) 263 nextCharacter(); 264 } 265 } 266 | Popular Tags |