View Javadoc
1   /*
2    * Copyright 2007 Kasper B. Graversen
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.supercsv.mock;
17  
18  import java.util.Date;
19  
20  /**
21   * Bean to use when testing bean reading/writing.
22   * 
23   * @author Kasper B. Graversen
24   * @author James Bassett
25   */
26  public class PersonBean {
27  	
28  	private String firstName;
29  	
30  	private String lastName;
31  	
32  	private Date birthDate;
33  	
34  	private Boolean married;
35  	
36  	private Integer numberOfKids;
37  	
38  	private String favouriteQuote;
39  	
40  	private String email;
41  	
42  	/**
43  	 * Default constructor.
44  	 */
45  	public PersonBean() {
46  	}
47  	
48  	/**
49  	 * Constructs a PersonBean.
50  	 * 
51  	 * @param firstName
52  	 * @param lastName
53  	 * @param birthDate
54  	 * @param married
55  	 * @param numberOfKids
56  	 * @param favouriteQuote
57  	 * @param email
58  	 */
59  	public PersonBean(final String firstName, final String lastName, final Date birthDate, final Boolean married,
60  		final Integer numberOfKids, final String favouriteQuote, final String email) {
61  		this.firstName = firstName;
62  		this.lastName = lastName;
63  		this.birthDate = birthDate;
64  		this.married = married;
65  		this.numberOfKids = numberOfKids;
66  		this.favouriteQuote = favouriteQuote;
67  		this.email = email;
68  	}
69  	
70  	/**
71  	 * @return the firstName
72  	 */
73  	public String getFirstName() {
74  		return firstName;
75  	}
76  	
77  	/**
78  	 * @param firstName
79  	 *            the firstName to set
80  	 */
81  	public void setFirstName(String firstName) {
82  		this.firstName = firstName;
83  	}
84  	
85  	/**
86  	 * @return the lastName
87  	 */
88  	public String getLastName() {
89  		return lastName;
90  	}
91  	
92  	/**
93  	 * @param lastName
94  	 *            the lastName to set
95  	 */
96  	public void setLastName(String lastName) {
97  		this.lastName = lastName;
98  	}
99  	
100 	/**
101 	 * @return the birthDate
102 	 */
103 	public Date getBirthDate() {
104 		return birthDate;
105 	}
106 	
107 	/**
108 	 * @param birthDate
109 	 *            the birthDate to set
110 	 */
111 	public void setBirthDate(Date birthDate) {
112 		this.birthDate = birthDate;
113 	}
114 	
115 	/**
116 	 * @return the married
117 	 */
118 	public Boolean getMarried() {
119 		return married;
120 	}
121 	
122 	/**
123 	 * @param married
124 	 *            the married to set
125 	 */
126 	public void setMarried(Boolean married) {
127 		this.married = married;
128 	}
129 	
130 	/**
131 	 * @return the numberOfKids
132 	 */
133 	public Integer getNumberOfKids() {
134 		return numberOfKids;
135 	}
136 	
137 	/**
138 	 * @param numberOfKids
139 	 *            the numberOfKids to set
140 	 */
141 	public void setNumberOfKids(Integer numberOfKids) {
142 		this.numberOfKids = numberOfKids;
143 	}
144 	
145 	/**
146 	 * @return the email
147 	 */
148 	public String getEmail() {
149 		return email;
150 	}
151 	
152 	/**
153 	 * @param email
154 	 *            the email to set
155 	 */
156 	public void setEmail(String email) {
157 		this.email = email;
158 	}
159 	
160 	/**
161 	 * @return the favouriteQuote
162 	 */
163 	public String getFavouriteQuote() {
164 		return favouriteQuote;
165 	}
166 	
167 	/**
168 	 * @param favouriteQuote
169 	 *            the favouriteQuote to set
170 	 */
171 	public void setFavouriteQuote(String favouriteQuote) {
172 		this.favouriteQuote = favouriteQuote;
173 	}
174 	
175 	@Override
176 	public int hashCode() {
177 		final int prime = 31;
178 		int result = 1;
179 		result = prime * result + ((birthDate == null) ? 0 : birthDate.hashCode());
180 		result = prime * result + ((email == null) ? 0 : email.hashCode());
181 		result = prime * result + ((favouriteQuote == null) ? 0 : favouriteQuote.hashCode());
182 		result = prime * result + ((firstName == null) ? 0 : firstName.hashCode());
183 		result = prime * result + ((lastName == null) ? 0 : lastName.hashCode());
184 		result = prime * result + ((married == null) ? 0 : married.hashCode());
185 		result = prime * result + ((numberOfKids == null) ? 0 : numberOfKids.hashCode());
186 		return result;
187 	}
188 	
189 	@Override
190 	public boolean equals(Object obj) {
191 		if( this == obj ) {
192 			return true;
193 		}
194 		if( obj == null ) {
195 			return false;
196 		}
197 		if( !(obj instanceof PersonBean) ) {
198 			return false;
199 		}
200 		PersonBean other = (PersonBean) obj;
201 		if( birthDate == null ) {
202 			if( other.birthDate != null ) {
203 				return false;
204 			}
205 		} else if( !birthDate.equals(other.birthDate) ) {
206 			return false;
207 		}
208 		if( email == null ) {
209 			if( other.email != null ) {
210 				return false;
211 			}
212 		} else if( !email.equals(other.email) ) {
213 			return false;
214 		}
215 		if( favouriteQuote == null ) {
216 			if( other.favouriteQuote != null ) {
217 				return false;
218 			}
219 		} else if( !favouriteQuote.equals(other.favouriteQuote) ) {
220 			return false;
221 		}
222 		if( firstName == null ) {
223 			if( other.firstName != null ) {
224 				return false;
225 			}
226 		} else if( !firstName.equals(other.firstName) ) {
227 			return false;
228 		}
229 		if( lastName == null ) {
230 			if( other.lastName != null ) {
231 				return false;
232 			}
233 		} else if( !lastName.equals(other.lastName) ) {
234 			return false;
235 		}
236 		if( married == null ) {
237 			if( other.married != null ) {
238 				return false;
239 			}
240 		} else if( !married.equals(other.married) ) {
241 			return false;
242 		}
243 		if( numberOfKids == null ) {
244 			if( other.numberOfKids != null ) {
245 				return false;
246 			}
247 		} else if( !numberOfKids.equals(other.numberOfKids) ) {
248 			return false;
249 		}
250 		return true;
251 	}
252 	
253 	@Override
254 	public String toString() {
255 		return String
256 			.format(
257 				"PersonBean [firstName=%s, lastName=%s, birthDate=%s, married=%s, numberOfKids=%s, favouriteQuote=%s, email=%s]",
258 				firstName, lastName, birthDate, married, numberOfKids, favouriteQuote, email);
259 	}
260 	
261 }