001: /*
002: * FormatConfiguration.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 net.sf.anupam.csv.formatters;
023:
024: import org.apache.commons.lang.builder.EqualsBuilder;
025: import org.apache.commons.lang.builder.HashCodeBuilder;
026: import org.apache.commons.lang.builder.ToStringBuilder;
027: import org.apache.commons.lang.builder.CompareToBuilder;
028:
029: /**
030: * FormatConfiguration.
031: *
032: * @author Anupam Sengupta
033: * @version $Revision: 1.2 $
034: * @since 1.5
035: */
036: public class FormatterConfiguration implements
037: Comparable<FormatterConfiguration> {
038:
039: /**
040: * Name of this formatter.
041: */
042: private String formatterName;
043:
044: /**
045: * Fully qualified class name of the formatter.
046: */
047: private String formatterClass;
048:
049: /**
050: * Whether special formatter construction is to be performed by the factory
051: * methods.
052: */
053: private boolean constructionNeeded;
054:
055: /**
056: * Constructor for FormatConfiguration.
057: */
058: public FormatterConfiguration() {
059: super ();
060: }
061:
062: /**
063: * Compares this formatter configuration to another configuration for ordering purposes.
064: * The comparision is based on the formatter name.
065: *
066: * @param other the other configuration to compare against
067: * @return <code>0</code> if the two configurations are equal, <code>-1</code> if
068: * this configuration ranks "lower", <code>+1</code> if this configuration ranks "higher"
069: * @see Comparable#compareTo(Object)
070: */
071: public int compareTo(final FormatterConfiguration other) {
072:
073: return new CompareToBuilder().append(formatterName,
074: other.formatterName).append(formatterClass,
075: other.formatterClass).toComparison();
076: }
077:
078: /**
079: * Returns a string representation of this formatter configuration for
080: * <strong>debugging</strong> purposes only.
081: *
082: * @return a string representation of this formatter configuration
083: * @see Object#toString()
084: */
085: @Override
086: public String toString() {
087: return new ToStringBuilder(this ).append("formatterName",
088: formatterName).append("formatterClass", formatterClass)
089: .append("constructionNeeded", constructionNeeded)
090: .toString();
091: }
092:
093: /**
094: * Computes the hash code for this formatter configuration. The has code is based on the
095: * formatter configuration's name.
096: *
097: * @return the hash code
098: * @see Object#hashCode()
099: */
100: @Override
101: public int hashCode() {
102: return new HashCodeBuilder().append(formatterName).append(
103: formatterClass).toHashCode();
104: }
105:
106: /**
107: * Compares this formatter configuration to another configuration for equality. Equality
108: * test is based on the formatter configuration name.
109: *
110: * @param other the other configuration to compare to
111: * @return <code>true</code> if the configurations are equal, <code>false</code> other wise
112: * @see Object#equals(Object)
113: */
114: @Override
115: public boolean equals(final Object other) {
116: if (this == other) {
117: return true;
118: }
119: if (!(other instanceof FormatterConfiguration)) {
120: return false;
121: }
122:
123: final FormatterConfiguration castOther = (FormatterConfiguration) other;
124: return new EqualsBuilder().append(formatterName,
125: castOther.formatterName).append(formatterClass,
126: castOther.formatterClass).isEquals();
127: }
128:
129: /**
130: * Returns value of the formatName.
131: *
132: * @return Returns the formatName.
133: */
134: public String getFormatterName() {
135: return this .formatterName;
136: }
137:
138: /**
139: * Sets value of the formatName.
140: *
141: * @param formatName The formatName to set.
142: */
143: public void setFormatterName(final String formatName) {
144: this .formatterName = formatName;
145: }
146:
147: /**
148: * Returns value of the formatterClass.
149: *
150: * @return Returns the formatterClass.
151: */
152: public String getFormatterClass() {
153: return this .formatterClass;
154: }
155:
156: /**
157: * Sets value of the formatterClass.
158: *
159: * @param formatterClass The formatterClass to set.
160: */
161: public void setFormatterClass(final String formatterClass) {
162: this .formatterClass = formatterClass;
163: }
164:
165: /**
166: * Returns value of the constructionNeeded.
167: *
168: * @return Returns the constructionNeeded.
169: */
170: public boolean isConstructionNeeded() {
171: return this .constructionNeeded;
172: }
173:
174: /**
175: * Sets value of the constructionNeeded.
176: *
177: * @param constructionNeeded The constructionNeeded to set.
178: */
179: public void setConstructionNeeded(final boolean constructionNeeded) {
180: this.constructionNeeded = constructionNeeded;
181: }
182:
183: }
|