KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > anupam > csv > formatters > FormatterConfiguration


1 /*
2  * FormatConfiguration.java
3  *
4  * Copyright (C) 2005 Anupam Sengupta (anupamsg@users.sourceforge.net)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  *
20  * Version: $Revision: 1.2 $
21  */

22 package net.sf.anupam.csv.formatters;
23
24 import org.apache.commons.lang.builder.EqualsBuilder;
25 import org.apache.commons.lang.builder.HashCodeBuilder;
26 import org.apache.commons.lang.builder.ToStringBuilder;
27 import org.apache.commons.lang.builder.CompareToBuilder;
28
29 /**
30  * FormatConfiguration.
31  *
32  * @author Anupam Sengupta
33  * @version $Revision: 1.2 $
34  * @since 1.5
35  */

36 public class FormatterConfiguration
37         implements Comparable JavaDoc<FormatterConfiguration> {
38
39     /**
40      * Name of this formatter.
41      */

42     private String JavaDoc formatterName;
43
44     /**
45      * Fully qualified class name of the formatter.
46      */

47     private String JavaDoc formatterClass;
48
49     /**
50      * Whether special formatter construction is to be performed by the factory
51      * methods.
52      */

53     private boolean constructionNeeded;
54
55     /**
56      * Constructor for FormatConfiguration.
57      */

58     public FormatterConfiguration() {
59         super();
60     }
61
62     /**
63      * Compares this formatter configuration to another configuration for ordering purposes.
64      * The comparision is based on the formatter name.
65      *
66      * @param other the other configuration to compare against
67      * @return <code>0</code> if the two configurations are equal, <code>-1</code> if
68      * this configuration ranks "lower", <code>+1</code> if this configuration ranks "higher"
69      * @see Comparable#compareTo(Object)
70      */

71     public int compareTo(final FormatterConfiguration other) {
72
73         return new CompareToBuilder()
74                 .append(formatterName, other.formatterName).append(
75                 formatterClass, other.formatterClass).toComparison();
76     }
77
78     /**
79      * Returns a string representation of this formatter configuration for
80      * <strong>debugging</strong> purposes only.
81      *
82      * @return a string representation of this formatter configuration
83      * @see Object#toString()
84      */

85     @Override JavaDoc
86     public String JavaDoc toString() {
87         return new ToStringBuilder(this).append("formatterName", formatterName)
88                 .append("formatterClass", formatterClass).append(
89                 "constructionNeeded", constructionNeeded).toString();
90     }
91
92     /**
93      * Computes the hash code for this formatter configuration. The has code is based on the
94      * formatter configuration's name.
95      *
96      * @return the hash code
97      * @see Object#hashCode()
98      */

99     @Override JavaDoc
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 JavaDoc
114     public boolean equals(final Object JavaDoc 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 JavaDoc 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 JavaDoc formatName) {
143         this.formatterName = formatName;
144     }
145
146     /**
147      * Returns value of the formatterClass.
148      *
149      * @return Returns the formatterClass.
150      */

151     public String JavaDoc 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 JavaDoc 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 }
183
Popular Tags