001: /*
002: * Copyright 2002 (C) TJDO.
003: * All rights reserved.
004: *
005: * This software is distributed under the terms of the TJDO License version 1.0.
006: * See the terms of the TJDO License in the documentation provided with this software.
007: *
008: * $Id: StringWidget.java,v 1.2 2002/10/17 21:01:00 pierreg0 Exp $
009: */
010:
011: package com.triactive.jdo.test;
012:
013: public class StringWidget extends Widget {
014: private String fixedLengthString;
015: private String normalString;
016: private String hugeString;
017:
018: public StringWidget() {
019: super ();
020: }
021:
022: public String getFixedLengthString() {
023: return fixedLengthString;
024: }
025:
026: public String getNormalString() {
027: return normalString;
028: }
029:
030: public String getHugeString() {
031: return hugeString;
032: }
033:
034: public void setNormalString(String normalString) {
035: this .normalString = normalString;
036: }
037:
038: /**
039: * Fills all of the object's fields with random data values. Any non-
040: * primitive fields (with the exception of <code>id</code>) will also be
041: * assigned <code>null</code> on a random basis.
042: */
043:
044: public void fillRandom() {
045: super .fillRandom();
046:
047: fixedLengthString = nextNull() ? null : nextString(20);
048: normalString = nextNull() ? null : nextString(r.nextInt(21));
049: hugeString = nextNull() ? null : nextString(r.nextInt(101));
050: }
051:
052: /**
053: * Indicates whether some other object is "equal to" this one. By comparing
054: * against an original copy of the object, <code>compareTo()</code> can be
055: * used to verify that the object has been written to a database and read
056: * back correctly.
057: *
058: * @param obj the reference object with which to compare
059: *
060: * @return <code>true</code> if this object is equal to the obj argument;
061: * <code>false</code> otherwise.
062: */
063:
064: public boolean compareTo(Object obj) {
065: if (obj == this )
066: return true;
067:
068: if (!(obj instanceof StringWidget) || !super .compareTo(obj))
069: return false;
070:
071: StringWidget w = (StringWidget) obj;
072:
073: if (fixedLengthString == null) {
074: if (w.fixedLengthString != null)
075: return false;
076: } else if (!fixedLengthString.equals(w.fixedLengthString))
077: return false;
078:
079: if (normalString == null) {
080: if (w.normalString != null)
081: return false;
082: } else if (!normalString.equals(w.normalString))
083: return false;
084:
085: if (hugeString == null) {
086: if (w.hugeString != null)
087: return false;
088: } else if (!hugeString.equals(w.hugeString))
089: return false;
090:
091: return true;
092: }
093:
094: /**
095: * Returns a string representation for this object. All of the field
096: * values are included in the string for debugging purposes.
097: *
098: * @return a string representation for this object.
099: */
100:
101: public String toString() {
102: StringBuffer s = new StringBuffer(super .toString());
103:
104: s.append(" fixedLengthString = ").append(fixedLengthString);
105: s.append('\n');
106: s.append(" normalString = ").append(normalString);
107: s.append('\n');
108: s.append(" hugeString = ").append(hugeString);
109: s.append('\n');
110:
111: return s.toString();
112: }
113: }
|