001: //$Id: SimpleVONoDefaultConstructor.java 247 2006-06-11 18:06:08Z jg_hamburg $
002: /********************************************************************************
003: * DDTUnit, a Datadriven Approach to Unit- and Moduletesting
004: * Copyright (c) 2004, Joerg and Kai Gellien
005: * All rights reserved.
006: *
007: * The Software is provided under the terms of the Common Public License 1.0
008: * as provided with the distribution of DDTUnit in the file cpl-v10.html.
009: * Redistribution and use in source and binary forms, with or without
010: * modification, are permitted provided that the following conditions
011: * are met:
012: *
013: * + Redistributions of source code must retain the above copyright
014: * notice, this list of conditions and the following disclaimer.
015: *
016: * + Redistributions in binary form must reproduce the above
017: * copyright notice, this list of conditions and the following
018: * disclaimer in the documentation and/or other materials provided
019: * with the distribution.
020: *
021: * + Neither the name of the authors or DDTUnit, nor the
022: * names of its contributors may be used to endorse or promote
023: * products derived from this software without specific prior
024: * written permission.
025: *
026: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
027: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
028: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
029: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
030: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
031: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
032: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
033: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
034: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
035: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
036: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
037: ********************************************************************************/package junitx.ddtunit.resources;
038:
039: import java.util.Date;
040:
041: /**
042: * Example test resource representing a set of value objects usually used as
043: * transport medium between different architectural system layers.
044: *
045: * @author jg
046: */
047: public class SimpleVONoDefaultConstructor {
048: private static final String LF = System
049: .getProperty("line.separator");
050:
051: private Integer integerValue;
052:
053: private String stringValue;
054:
055: private Double doubleValue;
056:
057: private Date dateValue;
058:
059: private SimpleVONoDefaultConstructor simpleVO;
060:
061: private Integer[] integerArray;
062:
063: /**
064: *
065: * @param text
066: */
067: public SimpleVONoDefaultConstructor(String text) {
068: this .stringValue = text;
069: }
070:
071: /**
072: *
073: * @param text
074: * @param intValue
075: * @param doubleValue
076: */
077: public SimpleVONoDefaultConstructor(String text, Integer intValue,
078: Double doubleValue) {
079: this .stringValue = text;
080: this .integerValue = intValue;
081: this .doubleValue = doubleValue;
082: }
083:
084: /**
085: * Overwrite toString() method with instance specific information
086: */
087: public String toString() {
088: StringBuffer sb = new StringBuffer("SimpleVO:");
089:
090: sb.append(LF).append(" textValue=\"").append(stringValue)
091: .append("\"");
092: sb.append(LF).append(" integerValue=\"").append(integerValue)
093: .append("\"");
094: sb.append(LF).append(" doubleValue=\"").append(doubleValue)
095: .append("\"");
096:
097: return sb.toString();
098: }
099:
100: /**
101: * overwrite default equals() method
102: */
103: public boolean equals(Object object) {
104: boolean check = false;
105:
106: if (SimpleVONoDefaultConstructor.class.isInstance(object)) {
107: SimpleVONoDefaultConstructor vo = (SimpleVONoDefaultConstructor) object;
108:
109: if ((((this .integerValue != null) && this .integerValue
110: .equals(vo.getIntegerValue())) || ((this .integerValue == null) && (vo
111: .getIntegerValue() == null)))
112: && (((this .doubleValue != null) && this .doubleValue
113: .equals(vo.getDoubleValue())) || ((this .doubleValue == null) && (vo
114: .getDoubleValue() == null)))
115: && (((this .stringValue != null) && this .stringValue
116: .equals(vo.getStringValue())) || ((this .stringValue == null) && (vo
117: .getStringValue() == null)))
118: && (((this .dateValue != null) && this .dateValue
119: .equals(vo.getDateValue())) || ((this .dateValue == null) && (vo
120: .getDateValue() == null)))) {
121: check = true;
122: }
123: }
124:
125: return check;
126: }
127:
128: /**
129: * Overwrite default hashCode()
130: */
131: public int hashCode() {
132: final int CONST_VAL = 42;
133: int hashVal = CONST_VAL;
134: if (this .stringValue != null) {
135: hashVal = hashVal + this .stringValue.hashCode();
136: }
137: if (this .integerValue != null) {
138: hashVal = (CONST_VAL * hashVal)
139: + this .integerValue.intValue();
140: }
141: if (this .doubleValue != null) {
142: hashVal = (CONST_VAL * hashVal)
143: + this .doubleValue.intValue();
144: }
145: if (this .dateValue != null) {
146: hashVal = (int) ((CONST_VAL * hashVal) + this .dateValue
147: .getTime());
148: }
149: return hashVal;
150: }
151:
152: /**
153: * @return Returns the doubleValue.
154: */
155: public Double getDoubleValue() {
156: return doubleValue;
157: }
158:
159: /**
160: * @param doubleValue The doubleValue to set.
161: */
162: public void setDoubleValue(Double doubleValue) {
163: this .doubleValue = new Double(doubleValue.doubleValue() * 10.0);
164: }
165:
166: /**
167: * @return Returns the integerValue.
168: */
169: public Integer getIntegerValue() {
170: return integerValue;
171: }
172:
173: /**
174: * @param integerValue The integerValue to set.
175: */
176: public void setIntegerValue(Integer integerValue) {
177: this .integerValue = new Integer(integerValue.intValue() * 10);
178: }
179:
180: /**
181: * @return Returns the stringValue.
182: */
183: public String getStringValue() {
184: return stringValue;
185: }
186:
187: /**
188: * @param stringValue The stringValue to set.
189: */
190: public void setStringValue(String stringValue) {
191: this .stringValue = stringValue;
192: }
193:
194: public Date getDateValue() {
195: return this .dateValue;
196: }
197:
198: public void setDateValue(Date dateValue) {
199: this.dateValue = dateValue;
200: }
201: }
|