001 /*
002 * Designation.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 designation.
031 *
032 * @author Anupam Sengupta
033 * @version $Revision: 1.2 $
034 * @csv.bean-mapping bean-name="designationBean" csv-header="true"
035 */
036 public class Designation
037 implements Comparable<Designation> {
038
039 /**
040 * The designation.
041 */
042 private String designation;
043
044 /**
045 * Constructor for Designation.
046 */
047 public Designation() {
048 super();
049 }
050
051 /**
052 * Compares this designation to another designation.
053 *
054 * @param other the other designation to compare against
055 * @return <code>0</code> if the two designations are equal, <code>-1</code> if this
056 * designation ranks lower, <code>+1</code> if this designation ranks higher
057 * @see Comparable#compareTo(Object)
058 */
059 public int compareTo(final Designation other) {
060
061 return new CompareToBuilder().append(designation, other.designation)
062 .toComparison();
063 }
064
065 /**
066 * Returns the string representation of this designation for <strong>debugging</strong>
067 * purposes only.
068 *
069 * @return the string representation
070 * @see Object#toString()
071 */
072 @Override
073 public String toString() {
074 return new ToStringBuilder(this).append("designation", designation)
075 .toString();
076 }
077
078 /**
079 * Returns the hash code for this designation. The hash code is based on the designation string.
080 *
081 * @return the hash code for this designation
082 * @see Object#hashCode()
083 */
084 @Override
085 public int hashCode() {
086 return new HashCodeBuilder().append(designation).toHashCode();
087 }
088
089 /**
090 * Compares this designation with another for equality. The equality is based on the
091 * designation string.
092 *
093 * @param other the other designation to compare against
094 * @return <code>true</code> if the designations are equal, <code>false</code> otherwise
095 * @see Object#equals(Object)
096 */
097 @Override
098 public boolean equals(final Object other) {
099 if (this == other) {
100 return true;
101 }
102
103 if (!(other instanceof Designation)) {
104 return false;
105 }
106 final Designation castOther = (Designation) other;
107 return new EqualsBuilder().append(designation, castOther.designation)
108 .isEquals();
109 }
110
111 /**
112 * Returns value of the designation.
113 *
114 * @return Returns the designation.
115 * @csv.field-mapping position="4"
116 */
117 public String getDesignation() {
118 return this.designation;
119 }
120
121 /**
122 * Sets value of the designation.
123 *
124 * @param designation The designation to set.
125 */
126 public void setDesignation(final String designation) {
127 this.designation = designation;
128 }
129
130 }