001    /*
002     * Employee.java 
003     * 
004     * Copyright (C) 2005 Anupam Sengupta ([email protected]) 
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
037            implements Comparable<Employee> {
038        // ~ Instance fields
039        // --------------------------------------------------------
040    
041        /**
042         * Employee ID.
043         */
044        private String employeeID;
045    
046        /**
047         * First name of the employee.
048         */
049        private String firstName;
050    
051        /**
052         * Last name of the employee.
053         */
054        private String lastName;
055    
056        /**
057         * The client supplied identifier.
058         */
059        private String clientSuppliedID;
060    
061        /**
062         * An alternate client supplied identifier.
063         */
064        private String clientSuppliedSecondaryID;
065    
066        /**
067         * the designation of this employee.
068         */
069        private Designation designation;
070    
071        /**
072         * Default Constructor.
073         */
074        public Employee() {
075            super();
076        }
077    
078        /**
079         * Returns value of the clientSuppliedID.
080         *
081         * @return Returns the clientSuppliedID.
082         * @csv.field-mapping field-name="MyTimeID" position="8"
083         */
084        public String getClientSuppliedID() {
085            return this.clientSuppliedID;
086        }
087    
088        /**
089         * Sets value of the clientSuppliedID.
090         *
091         * @param clientSuppliedID The clientSuppliedID to set.
092         */
093        public void setClientSuppliedID(final String clientSuppliedID) {
094            this.clientSuppliedID = clientSuppliedID;
095        }
096    
097        /**
098         * Returns value of the clientSuppliedSecondaryID.
099         *
100         * @return Returns the clientSuppliedSecondaryID.
101         * @csv.field-mapping field-name="contractorID" position="7"
102         */
103        public String 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 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 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 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 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 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 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 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
198        public boolean equals(final Object 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
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
232        public String 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    }