1 22 package net.sf.anupam.csv.mapping; 23 24 import net.sf.anupam.csv.formatters.CSVFieldFormatter; 25 26 import org.apache.commons.lang.StringUtils; 27 import org.apache.commons.lang.builder.EqualsBuilder; 28 import org.apache.commons.lang.builder.ToStringBuilder; 29 import org.apache.commons.lang.builder.HashCodeBuilder; 30 import org.apache.commons.lang.builder.CompareToBuilder; 31 32 42 public class CSVFieldMapping implements Comparable <CSVFieldMapping> { 43 44 47 private String fieldName; 48 49 52 private String fieldType; 53 54 57 private int fieldPosition; 58 59 62 private String attributeName; 63 64 67 private CSVFieldFormatter formatter; 68 69 72 private String reformatterName; 73 74 78 private String beanReferenceName; 79 80 83 private CSVBeanMapping beanReference; 84 85 88 public CSVFieldMapping() { 89 super(); 90 } 91 92 99 @Override 100 public int hashCode() { 101 return new HashCodeBuilder().append(fieldName).append(fieldPosition) 102 .toHashCode(); 103 } 104 105 113 @Override 114 public boolean equals(final Object other) { 115 if (this == other) { 116 return true; 117 } 118 if (!(other instanceof CSVFieldMapping)) { 119 return false; 120 } 121 final CSVFieldMapping castOther = (CSVFieldMapping) other; 122 return new EqualsBuilder().append(fieldName, castOther.fieldName) 123 .append(fieldPosition, castOther.fieldPosition).isEquals(); 124 } 125 126 133 @Override 134 public String toString() { 135 final ToStringBuilder strBuilder = new ToStringBuilder(this); 136 strBuilder.append("fieldName", fieldName) 137 .append("fieldType", fieldType).append("fieldPosition", 138 fieldPosition).append("attributeName", attributeName) 139 .append("reformatterName", reformatterName); 140 141 strBuilder.append("FormatterClass", (formatter != null ? formatter 142 .getClass() : "None")); 143 strBuilder.append("beanReferenceName", beanReferenceName); 144 strBuilder 145 .append("Bean Reference Class", 146 (beanReference != null) ? beanReference.getBeanClass() 147 : "None"); 148 return strBuilder.toString(); 149 } 150 151 161 public int compareTo(final CSVFieldMapping other) { 162 if (this.equals(other)) { 163 return 0; 164 } else { 165 return new CompareToBuilder().append(this.getFieldName(), other.getFieldName()) 166 .append(this.getFieldPosition(), other.getFieldPosition()).toComparison(); 167 168 169 } 170 171 } 172 173 178 public String getAttributeName() { 179 return this.attributeName; 180 } 181 182 188 public void setAttributeName(final String attributeName) { 189 this.attributeName = StringUtils.trim(attributeName); 190 } 191 192 197 public String getFieldName() { 198 return this.fieldName; 199 } 200 201 207 public void setFieldName(final String fieldName) { 208 this.fieldName = StringUtils.trim(fieldName); 209 } 210 211 217 public int getFieldPosition() { 218 return this.fieldPosition; 219 } 220 221 227 public void setFieldPosition(final int fieldPosition) { 228 this.fieldPosition = fieldPosition; 229 } 230 231 236 public String getFieldType() { 237 return this.fieldType; 238 } 239 240 245 public void setFieldType(final String fieldType) { 246 this.fieldType = StringUtils.trim(fieldType); 247 } 248 249 254 public CSVFieldFormatter getFormatter() { 255 return this.formatter; 256 } 257 258 263 public void setFormatter(final CSVFieldFormatter formatter) { 264 this.formatter = formatter; 265 } 266 267 272 public String getReformatterName() { 273 return this.reformatterName; 274 } 275 276 281 public void setReformatterName(final String reformatterName) { 282 this.reformatterName = reformatterName; 283 } 284 285 291 public String getBeanReferenceName() { 292 return this.beanReferenceName; 293 } 294 295 301 public void setBeanReferenceName(final String beanReferenceName) { 302 this.beanReferenceName = beanReferenceName; 303 } 304 305 310 public void setBeanReference(final CSVBeanMapping beanReference) { 311 this.beanReference = beanReference; 312 } 313 314 320 public CSVBeanMapping getBeanReference() { 321 return this.beanReference; 322 } 323 324 } 325 | Popular Tags |