KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > triactive > jdo > test > Widget


1 /*
2  * Copyright 2002 (C) TJDO.
3  * All rights reserved.
4  *
5  * This software is distributed under the terms of the TJDO License version 1.0.
6  * See the terms of the TJDO License in the documentation provided with this software.
7  *
8  * $Id: Widget.java,v 1.4 2003/03/17 07:02:53 jackknifebarber Exp $
9  */

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 JavaDoc booleanObjField;
20     private byte byteField;
21     private Byte JavaDoc byteObjField;
22     private char charField;
23     private Character JavaDoc charObjField;
24     private short shortField;
25     private Short JavaDoc shortObjField;
26     private int intField;
27     private Integer JavaDoc intObjField;
28     private long longField;
29     private Long JavaDoc longObjField;
30
31
32     public Widget()
33     {
34     }
35
36
37     public boolean getBooleanField()
38     {
39         return booleanField;
40     }
41
42
43     public Boolean JavaDoc getBooleanObjField()
44     {
45         return booleanObjField;
46     }
47
48
49     public byte getByteField()
50     {
51         return byteField;
52     }
53
54
55     public Byte JavaDoc getByteObjField()
56     {
57         return byteObjField;
58     }
59
60
61     public char getCharField()
62     {
63         return charField;
64     }
65
66
67     public Character JavaDoc getCharObjField()
68     {
69         return charObjField;
70     }
71
72
73     public short getShortField()
74     {
75         return shortField;
76     }
77
78
79     public Short JavaDoc getShortObjField()
80     {
81         return shortObjField;
82     }
83
84
85     public int getIntField()
86     {
87         return intField;
88     }
89
90
91     public Integer JavaDoc getIntObjField()
92     {
93         return intObjField;
94     }
95
96
97     public long getLongField()
98     {
99         return longField;
100     }
101
102
103     public Long JavaDoc 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     /**
138      * Fills all of the object's fields with random data values. Any non-
139      * primitive fields (with the exception of <code>id</code>) will also be
140      * assigned <code>null</code> on a random basis.
141      */

142
143     public void fillRandom()
144     {
145         booleanField = r.nextBoolean();
146         booleanObjField = nextNull() ? null : new Boolean JavaDoc(r.nextBoolean());
147         byteField = nextByte();
148         byteObjField = nextNull() ? null : new Byte JavaDoc(nextByte());
149         charField = nextCharacter();
150         charObjField = nextNull() ? null : new Character JavaDoc(nextCharacter());
151         shortField = (short)(r.nextInt(Short.MAX_VALUE * 2) - Short.MAX_VALUE);
152         shortObjField = nextNull() ? null : new Short JavaDoc((short)(r.nextInt(Short.MAX_VALUE * 2) - Short.MAX_VALUE));
153         intField = r.nextInt();
154         intObjField = nextNull() ? null : new Integer JavaDoc(r.nextInt());
155         longField = r.nextLong();
156         longObjField = nextNull() ? null : new Long JavaDoc(r.nextLong());
157     }
158
159
160     /**
161      * Indicates whether some other object is "equal to" this one. By comparing
162      * against an original copy of the object, <code>compareTo()</code> can be
163      * used to verify that the object has been written to a database and read
164      * back correctly.
165      *
166      * @param obj the reference object with which to compare
167      *
168      * @return <code>true</code> if this object is equal to the obj argument;
169      * <code>false</code> otherwise.
170      */

171
172     public boolean compareTo(Object JavaDoc 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     /**
210      * Returns a string representation for this object. All of the field
211      * values are included in the string for debugging purposes.
212      *
213      * @return a string representation for this object.
214      */

215
216     public String JavaDoc toString()
217     {
218         StringBuffer JavaDoc s = new StringBuffer JavaDoc(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         /*
257          * This is here for the benefit of one particular test in
258          * BasicStorageTest.updateObjects(), which tests the updating of
259          * a default-fetch-group field when the default fetch group has not
260          * been loaded. All it needs to do is touch a couple of DFG fields.
261          */

262         if (booleanField && intField < 0)
263             nextCharacter();
264     }
265 }
266
Popular Tags