KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > test > net > sf > anupam > csv > beans > Employee


1 /*
2  * Employee.java
3  *
4  * Copyright (C) 2005 Anupam Sengupta (anupamsg@users.sourceforge.net)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * Version $Revision: 1.2 $
21  */

22 package test.net.sf.anupam.csv.beans;
23
24 import org.apache.commons.lang.builder.CompareToBuilder;
25 import org.apache.commons.lang.builder.EqualsBuilder;
26 import org.apache.commons.lang.builder.HashCodeBuilder;
27 import org.apache.commons.lang.builder.ToStringBuilder;
28
29 /**
30  * Sample bean to represent an employee.
31  *
32  * @author Anupam Sengupta
33  * @version $Revision: 1.2 $
34  * @csv.bean-mapping bean-name="employeeBean" csv-header="true"
35  */

36 public class Employee
37         implements Comparable JavaDoc<Employee> {
38     // ~ Instance fields
39
// --------------------------------------------------------
40

41     /**
42      * Employee ID.
43      */

44     private String JavaDoc employeeID;
45
46     /**
47      * First name of the employee.
48      */

49     private String JavaDoc firstName;
50
51     /**
52      * Last name of the employee.
53      */

54     private String JavaDoc lastName;
55
56     /**
57      * The client supplied identifier.
58      */

59     private String JavaDoc clientSuppliedID;
60
61     /**
62      * An alternate client supplied identifier.
63      */

64     private String JavaDoc clientSuppliedSecondaryID;
65
66     /**
67      * the designation of this employee.
68      */

69     private Designation designation;
70
71     /**
72      * Default Constructor.
73      */

74     public Employee() {
75         super();
76     }
77
78     /**
79      * Returns value of the clientSuppliedID.
80      *
81      * @return Returns the clientSuppliedID.
82      * @csv.field-mapping field-name="MyTimeID" position="8"
83      */

84     public String JavaDoc getClientSuppliedID() {
85         return this.clientSuppliedID;
86     }
87
88     /**
89      * Sets value of the clientSuppliedID.
90      *
91      * @param clientSuppliedID The clientSuppliedID to set.
92      */

93     public void setClientSuppliedID(final String JavaDoc clientSuppliedID) {
94         this.clientSuppliedID = clientSuppliedID;
95     }
96
97     /**
98      * Returns value of the clientSuppliedSecondaryID.
99      *
100      * @return Returns the clientSuppliedSecondaryID.
101      * @csv.field-mapping field-name="contractorID" position="7"
102      */

103     public String JavaDoc getClientSuppliedSecondaryID() {
104         return this.clientSuppliedSecondaryID;
105     }
106
107     /**
108      * Sets value of the clientSuppliedSecondaryID.
109      *
110      * @param clientSuppliedSecondaryID The clientSuppliedSecondaryID to set.
111      */

112     public void setClientSuppliedSecondaryID(
113             final String JavaDoc clientSuppliedSecondaryID) {
114         this.clientSuppliedSecondaryID = clientSuppliedSecondaryID;
115     }
116
117     /**
118      * Sets the employee ID.
119      *
120      * @param employeeID The employeeID to set.
121      */

122     public void setEmployeeID(final String JavaDoc employeeID) {
123         this.employeeID = employeeID;
124     }
125
126     /**
127      * Return the employee ID.
128      *
129      * @return Returns the employeeID.
130      * @csv.field-mapping position="1"
131      */

132     public String JavaDoc getEmployeeID() {
133         return this.employeeID;
134     }
135
136     /**
137      * Set the first name.
138      *
139      * @param firstName The firstName to set.
140      */

141     public void setFirstName(final String JavaDoc firstName) {
142         this.firstName = firstName;
143     }
144
145     /**
146      * Returns the first name.
147      *
148      * @return Returns the firstName.
149      * @csv.field-mapping position="2" reformat="firstWord"
150      */

151     public String JavaDoc getFirstName() {
152         return this.firstName;
153     }
154
155     /**
156      * Sets the last name.
157      *
158      * @param lastName The lastName to set.
159      */

160     public void setLastName(final String JavaDoc lastName) {
161         this.lastName = lastName;
162     }
163
164     /**
165      * Returns the last name.
166      *
167      * @return Returns the lastName.
168      * @csv.field-mapping position="2" reformat="lastWord"
169      */

170     public String JavaDoc getLastName() {
171         return this.lastName;
172     }
173
174     /**
175      * Compares this employee against another employee for ordering purposes. The comparision
176      * is based on the employee ID.
177      *
178      * @param other the other employee to compare against
179      * @return <code>0</code> if the two employee are equal, <code>-1</code> if this employee ID
180      * is lower, <code>+1</code> if this employee ID is higher
181      * @see Comparable#compareTo(Object)
182      */

183     public int compareTo(final Employee other) {
184
185         return new CompareToBuilder().append(employeeID, other.employeeID)
186                 .toComparison();
187     }
188
189     /**
190      * Compares this employee against another for equality. The comparision is based on the
191      * employee ID.
192      *
193      * @param other the other employee to compare against
194      * @return <code>true</code> if equal, <code>false</code> otherwise
195      * @see Object#equals(Object)
196      */

197     @Override JavaDoc
198     public boolean equals(final Object JavaDoc other) {
199         if (this == other) {
200             return true;
201         }
202
203         if (!(other instanceof Employee)) {
204             return false;
205         }
206
207         final Employee castOther = (Employee) other;
208
209         return new EqualsBuilder().append(employeeID, castOther.employeeID)
210                 .isEquals();
211     }
212
213     /**
214      * Returns the hashcode for this employee. The hash code is based on the employee ID.
215      *
216      * @return the hash code
217      * @see Object#hashCode()
218      */

219     @Override JavaDoc
220     public int hashCode() {
221         return new HashCodeBuilder().append(employeeID).toHashCode();
222     }
223
224     /**
225      * Returns a string representation of this employee for <code>debugging</code> purposes
226      * only.
227      *
228      * @return the string representation
229      * @see Object#toString()
230      */

231     @Override JavaDoc
232     public String JavaDoc toString() {
233         return new ToStringBuilder(this).append("employeeID", employeeID)
234                 .append("firstName", firstName).append("lastName", lastName)
235                 .append("clientSuppliedID", clientSuppliedID).append(
236                 "clientSuppliedSecondayID", clientSuppliedSecondaryID)
237                 .append("designation", designation).toString();
238     }
239
240     /**
241      * Returns value of the designation.
242      *
243      * @return Returns the designation.
244      * @csv.field-mapping position="3" bean-ref="designationBean"
245      */

246     public Designation getDesignation() {
247         return this.designation;
248     }
249
250     /**
251      * Sets value of the designation.
252      *
253      * @param designation The designation to set.
254      */

255     public void setDesignation(final Designation designation) {
256         this.designation = designation;
257     }
258 }
259
Popular Tags