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
037            implements 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()
074                    .append(formatterName, other.formatterName).append(
075                    formatterClass, 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", formatterName)
088                    .append("formatterClass", formatterClass).append(
089                    "constructionNeeded", constructionNeeded).toString();
090        }
091    
092        /**
093         * Computes the hash code for this formatter configuration. The has code is based on the
094         * formatter configuration's name.
095         *
096         * @return the hash code
097         * @see Object#hashCode()
098         */
099        @Override
100        public int hashCode() {
101            return new HashCodeBuilder().append(formatterName).append(
102                    formatterClass).toHashCode();
103        }
104    
105        /**
106         * Compares this formatter configuration to another configuration for equality. Equality
107         * test is based on the formatter configuration name.
108         *
109         * @param other the other configuration to compare to
110         * @return <code>true</code> if the configurations are equal, <code>false</code> other wise
111         * @see Object#equals(Object)
112         */
113        @Override
114        public boolean equals(final Object other) {
115            if (this == other) {
116                return true;
117            }
118            if (!(other instanceof FormatterConfiguration)) {
119                return false;
120            }
121    
122            final FormatterConfiguration castOther = (FormatterConfiguration) other;
123            return new EqualsBuilder().append(formatterName,
124                    castOther.formatterName).append(formatterClass,
125                    castOther.formatterClass).isEquals();
126        }
127    
128        /**
129         * Returns value of the formatName.
130         *
131         * @return Returns the formatName.
132         */
133        public String getFormatterName() {
134            return this.formatterName;
135        }
136    
137        /**
138         * Sets value of the formatName.
139         *
140         * @param formatName The formatName to set.
141         */
142        public void setFormatterName(final String formatName) {
143            this.formatterName = formatName;
144        }
145    
146        /**
147         * Returns value of the formatterClass.
148         *
149         * @return Returns the formatterClass.
150         */
151        public String getFormatterClass() {
152            return this.formatterClass;
153        }
154    
155        /**
156         * Sets value of the formatterClass.
157         *
158         * @param formatterClass The formatterClass to set.
159         */
160        public void setFormatterClass(final String formatterClass) {
161            this.formatterClass = formatterClass;
162        }
163    
164        /**
165         * Returns value of the constructionNeeded.
166         *
167         * @return Returns the constructionNeeded.
168         */
169        public boolean isConstructionNeeded() {
170            return this.constructionNeeded;
171        }
172    
173        /**
174         * Sets value of the constructionNeeded.
175         *
176         * @param constructionNeeded The constructionNeeded to set.
177         */
178        public void setConstructionNeeded(final boolean constructionNeeded) {
179            this.constructionNeeded = constructionNeeded;
180        }
181    
182    }