View Javadoc

1   //$Id: SimpleVO.java 230 2006-04-05 20:12:50Z jg_hamburg $
2   /********************************************************************************
3    * DDTUnit, a Datadriven Approach to Unit- and Moduletesting
4    * Copyright (c) 2004, Joerg and Kai Gellien
5    * All rights reserved.
6    *
7    * The Software is provided under the terms of the Common Public License 1.0
8    * as provided with the distribution of DDTUnit in the file cpl-v10.html.
9    * Redistribution and use in source and binary forms, with or without
10   * modification, are permitted provided that the following conditions
11   * are met:
12   *
13   *     + Redistributions of source code must retain the above copyright
14   *       notice, this list of conditions and the following disclaimer.
15   *
16   *     + Redistributions in binary form must reproduce the above
17   *       copyright notice, this list of conditions and the following
18   *       disclaimer in the documentation and/or other materials provided
19   *       with the distribution.
20   *
21   *     + Neither the name of the authors or DDTUnit, nor the
22   *       names of its contributors may be used to endorse or promote
23   *       products derived from this software without specific prior
24   *       written permission.
25   *
26   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
30   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31   * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32   * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33   * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34   * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35   * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37   ********************************************************************************/
38  package junitx.ddtunit.resources;
39  
40  import java.util.Date;
41  
42  /**
43   * Example test resource representing a set of value objects usually used as
44   * transport medium between different architectural system layers.
45   * 
46   * @author jg
47   */
48  public class SimpleVO {
49      private static final String LF = System.getProperty("line.separator");
50  
51      private Integer integerValue;
52  
53      private String stringValue;
54  
55      private Double doubleValue;
56  
57      private Date dateValue;
58  
59      private SimpleVO simpleVO;
60  
61      private Integer[] integerArray;
62  
63      /**
64       * Default constructor.
65       */
66      public SimpleVO() {
67          // no special initialization neccessary
68      }
69  
70      /**
71       * 
72       * @param text
73       */
74      public SimpleVO(String text) {
75          this.stringValue = text;
76      }
77  
78      /**
79       * 
80       * @param text
81       * @param intValue
82       * @param doubleValue
83       */
84      public SimpleVO(String text, Integer intValue, Double doubleValue) {
85          this.stringValue = text;
86          this.integerValue = intValue;
87          this.doubleValue = doubleValue;
88      }
89  
90      /**
91       * Overwrite toString() method with instance specific information
92       */
93      public String toString() {
94          StringBuffer sb = new StringBuffer("SimpleVO:");
95  
96          sb.append(LF).append("  textValue=\"").append(stringValue).append("\"");
97          sb.append(LF).append("  integerValue=\"").append(integerValue).append(
98              "\"");
99          sb.append(LF).append("  doubleValue=\"").append(doubleValue).append(
100             "\"");
101 
102         return sb.toString();
103     }
104 
105     /**
106      * overwrite default equals() method
107      */
108     public boolean equals(Object object) {
109         boolean check = false;
110 
111         if (SimpleVO.class.isInstance(object)) {
112             SimpleVO vo = (SimpleVO) object;
113 
114             if ((((this.integerValue != null) && this.integerValue.equals(vo
115                 .getIntegerValue())) || ((this.integerValue == null) && (vo
116                 .getIntegerValue() == null)))
117                     && (((this.doubleValue != null) && this.doubleValue
118                         .equals(vo.getDoubleValue())) || ((this.doubleValue == null) && (vo
119                         .getDoubleValue() == null)))
120                     && (((this.stringValue != null) && this.stringValue
121                         .equals(vo.getStringValue())) || ((this.stringValue == null) && (vo
122                         .getStringValue() == null)))
123                     && (((this.dateValue != null) && this.dateValue.equals(vo
124                         .getDateValue())) || ((this.dateValue == null) && (vo
125                         .getDateValue() == null)))) {
126                 check = true;
127             }
128         }
129 
130         return check;
131     }
132 
133     /**
134      * Overwrite default hashCode()
135      */
136     public int hashCode() {
137         final int CONST_VAL = 42;
138         int hashVal = CONST_VAL;
139         if (this.stringValue != null) {
140             hashVal = hashVal + this.stringValue.hashCode();
141         }
142         if (this.integerValue != null) {
143             hashVal = (CONST_VAL * hashVal) + this.integerValue.intValue();
144         }
145         if (this.doubleValue != null) {
146             hashVal = (CONST_VAL * hashVal) + this.doubleValue.intValue();
147         }
148         if (this.dateValue != null) {
149             hashVal = (int) ((CONST_VAL * hashVal) + this.dateValue.getTime());
150         }
151         return hashVal;
152     }
153 
154     /**
155      * @return Returns the doubleValue.
156      */
157     public Double getDoubleValue() {
158         return doubleValue;
159     }
160 
161     /**
162      * @param doubleValue The doubleValue to set.
163      */
164     public void setDoubleValue(Double doubleValue) {
165         this.doubleValue = new Double(doubleValue.doubleValue() * 10.0);
166     }
167 
168     /**
169      * @return Returns the integerValue.
170      */
171     public Integer getIntegerValue() {
172         return integerValue;
173     }
174 
175     /**
176      * @param integerValue The integerValue to set.
177      */
178     public void setIntegerValue(Integer integerValue) {
179         this.integerValue = new Integer(integerValue.intValue() * 10);
180     }
181 
182     /**
183      * @return Returns the stringValue.
184      */
185     public String getStringValue() {
186         return stringValue;
187     }
188 
189     /**
190      * @param stringValue The stringValue to set.
191      */
192     public void setStringValue(String stringValue) {
193         this.stringValue = stringValue;
194     }
195 
196     public Date getDateValue() {
197         return this.dateValue;
198     }
199 
200     public void setDateValue(Date dateValue) {
201         this.dateValue = dateValue;
202     }
203 }