KickJava   Java API By Example, From Geeks To Geeks.

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


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: StringWidget.java,v 1.2 2002/10/17 21:01:00 pierreg0 Exp $
9  */

10
11 package com.triactive.jdo.test;
12
13
14 public class StringWidget extends Widget
15 {
16     private String JavaDoc fixedLengthString;
17     private String JavaDoc normalString;
18     private String JavaDoc hugeString;
19
20
21     public StringWidget()
22     {
23         super();
24     }
25
26
27     public String JavaDoc getFixedLengthString()
28     {
29         return fixedLengthString;
30     }
31
32
33     public String JavaDoc getNormalString()
34     {
35         return normalString;
36     }
37
38
39     public String JavaDoc getHugeString()
40     {
41         return hugeString;
42     }
43
44
45     public void setNormalString(String JavaDoc normalString)
46     {
47         this.normalString = normalString;
48     }
49
50
51     /**
52      * Fills all of the object's fields with random data values. Any non-
53      * primitive fields (with the exception of <code>id</code>) will also be
54      * assigned <code>null</code> on a random basis.
55      */

56
57     public void fillRandom()
58     {
59         super.fillRandom();
60
61         fixedLengthString = nextNull() ? null : nextString(20);
62         normalString = nextNull() ? null : nextString(r.nextInt(21));
63         hugeString = nextNull() ? null : nextString(r.nextInt(101));
64     }
65
66
67     /**
68      * Indicates whether some other object is "equal to" this one. By comparing
69      * against an original copy of the object, <code>compareTo()</code> can be
70      * used to verify that the object has been written to a database and read
71      * back correctly.
72      *
73      * @param obj the reference object with which to compare
74      *
75      * @return <code>true</code> if this object is equal to the obj argument;
76      * <code>false</code> otherwise.
77      */

78
79     public boolean compareTo(Object JavaDoc obj)
80     {
81         if (obj == this)
82             return true;
83
84         if (!(obj instanceof StringWidget) || !super.compareTo(obj))
85             return false;
86
87         StringWidget w = (StringWidget)obj;
88
89         if (fixedLengthString == null) { if (w.fixedLengthString != null) return false; }
90         else if (!fixedLengthString.equals(w.fixedLengthString)) return false;
91
92         if (normalString == null) { if (w.normalString != null) return false; }
93         else if (!normalString.equals(w.normalString)) return false;
94
95         if (hugeString == null) { if (w.hugeString != null) return false; }
96         else if (!hugeString.equals(w.hugeString)) return false;
97
98         return true;
99     }
100
101
102     /**
103      * Returns a string representation for this object. All of the field
104      * values are included in the string for debugging purposes.
105      *
106      * @return a string representation for this object.
107      */

108
109     public String JavaDoc toString()
110     {
111         StringBuffer JavaDoc s = new StringBuffer JavaDoc(super.toString());
112
113         s.append(" fixedLengthString = ").append(fixedLengthString);
114         s.append('\n');
115         s.append(" normalString = ").append(normalString);
116         s.append('\n');
117         s.append(" hugeString = ").append(hugeString);
118         s.append('\n');
119
120         return s.toString();
121     }
122 }
123
Popular Tags