001: /*
002: * Employee.java
003: *
004: * Copyright (C) 2005 Anupam Sengupta (anupamsg@users.sourceforge.net)
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
019: *
020: * Version $Revision: 1.2 $
021: */
022: package test.net.sf.anupam.csv.beans;
023:
024: import org.apache.commons.lang.builder.CompareToBuilder;
025: import org.apache.commons.lang.builder.EqualsBuilder;
026: import org.apache.commons.lang.builder.HashCodeBuilder;
027: import org.apache.commons.lang.builder.ToStringBuilder;
028:
029: /**
030: * Sample bean to represent an employee.
031: *
032: * @author Anupam Sengupta
033: * @version $Revision: 1.2 $
034: * @csv.bean-mapping bean-name="employeeBean" csv-header="true"
035: */
036: public class Employee implements Comparable<Employee> {
037: // ~ Instance fields
038: // --------------------------------------------------------
039:
040: /**
041: * Employee ID.
042: */
043: private String employeeID;
044:
045: /**
046: * First name of the employee.
047: */
048: private String firstName;
049:
050: /**
051: * Last name of the employee.
052: */
053: private String lastName;
054:
055: /**
056: * The client supplied identifier.
057: */
058: private String clientSuppliedID;
059:
060: /**
061: * An alternate client supplied identifier.
062: */
063: private String clientSuppliedSecondaryID;
064:
065: /**
066: * the designation of this employee.
067: */
068: private Designation designation;
069:
070: /**
071: * Default Constructor.
072: */
073: public Employee() {
074: super ();
075: }
076:
077: /**
078: * Returns value of the clientSuppliedID.
079: *
080: * @return Returns the clientSuppliedID.
081: * @csv.field-mapping field-name="MyTimeID" position="8"
082: */
083: public String getClientSuppliedID() {
084: return this .clientSuppliedID;
085: }
086:
087: /**
088: * Sets value of the clientSuppliedID.
089: *
090: * @param clientSuppliedID The clientSuppliedID to set.
091: */
092: public void setClientSuppliedID(final String clientSuppliedID) {
093: this .clientSuppliedID = clientSuppliedID;
094: }
095:
096: /**
097: * Returns value of the clientSuppliedSecondaryID.
098: *
099: * @return Returns the clientSuppliedSecondaryID.
100: * @csv.field-mapping field-name="contractorID" position="7"
101: */
102: public String getClientSuppliedSecondaryID() {
103: return this .clientSuppliedSecondaryID;
104: }
105:
106: /**
107: * Sets value of the clientSuppliedSecondaryID.
108: *
109: * @param clientSuppliedSecondaryID The clientSuppliedSecondaryID to set.
110: */
111: public void setClientSuppliedSecondaryID(
112: final String clientSuppliedSecondaryID) {
113: this .clientSuppliedSecondaryID = clientSuppliedSecondaryID;
114: }
115:
116: /**
117: * Sets the employee ID.
118: *
119: * @param employeeID The employeeID to set.
120: */
121: public void setEmployeeID(final String employeeID) {
122: this .employeeID = employeeID;
123: }
124:
125: /**
126: * Return the employee ID.
127: *
128: * @return Returns the employeeID.
129: * @csv.field-mapping position="1"
130: */
131: public String getEmployeeID() {
132: return this .employeeID;
133: }
134:
135: /**
136: * Set the first name.
137: *
138: * @param firstName The firstName to set.
139: */
140: public void setFirstName(final String firstName) {
141: this .firstName = firstName;
142: }
143:
144: /**
145: * Returns the first name.
146: *
147: * @return Returns the firstName.
148: * @csv.field-mapping position="2" reformat="firstWord"
149: */
150: public String getFirstName() {
151: return this .firstName;
152: }
153:
154: /**
155: * Sets the last name.
156: *
157: * @param lastName The lastName to set.
158: */
159: public void setLastName(final String lastName) {
160: this .lastName = lastName;
161: }
162:
163: /**
164: * Returns the last name.
165: *
166: * @return Returns the lastName.
167: * @csv.field-mapping position="2" reformat="lastWord"
168: */
169: public String getLastName() {
170: return this .lastName;
171: }
172:
173: /**
174: * Compares this employee against another employee for ordering purposes. The comparision
175: * is based on the employee ID.
176: *
177: * @param other the other employee to compare against
178: * @return <code>0</code> if the two employee are equal, <code>-1</code> if this employee ID
179: * is lower, <code>+1</code> if this employee ID is higher
180: * @see Comparable#compareTo(Object)
181: */
182: public int compareTo(final Employee other) {
183:
184: return new CompareToBuilder().append(employeeID,
185: other.employeeID).toComparison();
186: }
187:
188: /**
189: * Compares this employee against another for equality. The comparision is based on the
190: * employee ID.
191: *
192: * @param other the other employee to compare against
193: * @return <code>true</code> if equal, <code>false</code> otherwise
194: * @see Object#equals(Object)
195: */
196: @Override
197: public boolean equals(final Object other) {
198: if (this == other) {
199: return true;
200: }
201:
202: if (!(other instanceof Employee)) {
203: return false;
204: }
205:
206: final Employee castOther = (Employee) other;
207:
208: return new EqualsBuilder().append(employeeID,
209: castOther.employeeID).isEquals();
210: }
211:
212: /**
213: * Returns the hashcode for this employee. The hash code is based on the employee ID.
214: *
215: * @return the hash code
216: * @see Object#hashCode()
217: */
218: @Override
219: public int hashCode() {
220: return new HashCodeBuilder().append(employeeID).toHashCode();
221: }
222:
223: /**
224: * Returns a string representation of this employee for <code>debugging</code> purposes
225: * only.
226: *
227: * @return the string representation
228: * @see Object#toString()
229: */
230: @Override
231: public String toString() {
232: return new ToStringBuilder(this ).append("employeeID",
233: employeeID).append("firstName", firstName).append(
234: "lastName", lastName).append("clientSuppliedID",
235: clientSuppliedID).append("clientSuppliedSecondayID",
236: clientSuppliedSecondaryID).append("designation",
237: 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: }
|