1 | /* |
2 | * jDTAUS Banking RI CurrencyDirectory |
3 | * Copyright (C) 2005 Christian Schulte |
4 | * <cs@schulte.it> |
5 | * |
6 | * This library is free software; you can redistribute it and/or |
7 | * modify it under the terms of the GNU Lesser General Public |
8 | * License as published by the Free Software Foundation; either |
9 | * version 2.1 of the License, or any later version. |
10 | * |
11 | * This library 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 GNU |
14 | * Lesser General Public License for more details. |
15 | * |
16 | * You should have received a copy of the GNU Lesser General Public |
17 | * License along with this library; if not, write to the Free Software |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
19 | * |
20 | */ |
21 | package org.jdtaus.banking.ri.currencydir; |
22 | |
23 | import java.io.Serializable; |
24 | import java.util.Date; |
25 | |
26 | /** |
27 | * Currency. |
28 | * |
29 | * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> |
30 | * @version $JDTAUS: JaxpCurrency.java 8865 2014-01-10 17:13:42Z schulte $ |
31 | */ |
32 | public class JaxpCurrency implements Serializable, Cloneable |
33 | { |
34 | |
35 | /** Serial version UID for backwards compatibility with 1.0.x classes. */ |
36 | private static final long serialVersionUID = 3499875740280116856L; |
37 | |
38 | /** |
39 | * ISO currency code. |
40 | * @serial |
41 | */ |
42 | private String isoCode; |
43 | |
44 | /** |
45 | * DTAUS currency code. |
46 | * @serial |
47 | */ |
48 | private Character dtausCode; |
49 | |
50 | /** |
51 | * Start date. |
52 | * @serial |
53 | */ |
54 | private Date startDate; |
55 | |
56 | /** |
57 | * End date. |
58 | * @serial |
59 | */ |
60 | private Date endDate; |
61 | |
62 | /** Cached hash-code. */ |
63 | private transient int hashCode = NO_HASHCODE; |
64 | |
65 | /** Constant for field {@code hashCode} forcing hash code computation. */ |
66 | private static final int NO_HASHCODE = Integer.MIN_VALUE; |
67 | |
68 | /** Creates a new {@code JaxpCurrency} instance. */ |
69 | public JaxpCurrency() |
70 | { |
71 | super(); |
72 | } |
73 | |
74 | /** |
75 | * Gets the ISO currency code. |
76 | * |
77 | * @return The ISO currency code. |
78 | */ |
79 | public String getIsoCode() |
80 | { |
81 | return this.isoCode; |
82 | } |
83 | |
84 | /** |
85 | * Sets the ISO currency code. |
86 | * |
87 | * @param value The ISO currency code. |
88 | */ |
89 | public void setIsoCode( final String value ) |
90 | { |
91 | this.isoCode = value; |
92 | this.hashCode = NO_HASHCODE; |
93 | } |
94 | |
95 | /** |
96 | * Gets the DTAUS currency code. |
97 | * |
98 | * @return The DTAUS currency code or {@code null}. |
99 | */ |
100 | public Character getDtausCode() |
101 | { |
102 | return this.dtausCode; |
103 | } |
104 | |
105 | /** |
106 | * Sets the DTAUS currency code. |
107 | * |
108 | * @param value The DTAUS currency code or {@code null}. |
109 | */ |
110 | public void setDtausCode( final Character value ) |
111 | { |
112 | this.dtausCode = value; |
113 | this.hashCode = NO_HASHCODE; |
114 | } |
115 | |
116 | /** |
117 | * Gets the start date. |
118 | * |
119 | * @return The start date.. |
120 | */ |
121 | public Date getStartDate() |
122 | { |
123 | return (Date) ( this.startDate == null ? null : this.startDate.clone() ); |
124 | } |
125 | |
126 | /** |
127 | * Sets the start date. |
128 | * |
129 | * @param value The start date. |
130 | */ |
131 | public void setStartDate( final Date value ) |
132 | { |
133 | this.startDate = (Date) ( value == null ? null : value.clone() ); |
134 | this.hashCode = NO_HASHCODE; |
135 | } |
136 | |
137 | /** |
138 | * Gets the end date. |
139 | * |
140 | * @return The end date. |
141 | */ |
142 | public Date getEndDate() |
143 | { |
144 | return (Date) ( this.endDate == null ? null : this.endDate.clone() ); |
145 | } |
146 | |
147 | /** |
148 | * Sets the end date. |
149 | * |
150 | * @param value The end date. |
151 | */ |
152 | public void setEndDate( final Date value ) |
153 | { |
154 | this.endDate = (Date) ( value == null ? null : value.clone() ); |
155 | this.hashCode = NO_HASHCODE; |
156 | } |
157 | |
158 | /** |
159 | * Checks that the currency is valid at a given date. |
160 | * |
161 | * @param date The date with which to check. |
162 | * |
163 | * @return {@code true}, if the currency is valid at {@code date}; |
164 | * {@code false} if not. |
165 | * |
166 | * @throws NullPointerException if {@code date} is {@code null}. |
167 | */ |
168 | public boolean isValidAt( final Date date ) |
169 | { |
170 | if ( date == null ) |
171 | { |
172 | throw new NullPointerException( "date" ); |
173 | } |
174 | |
175 | return ( date.equals( this.startDate ) |
176 | || date.after( this.startDate ) ) |
177 | && ( this.endDate == null |
178 | || date.equals( this.endDate ) |
179 | || date.before( this.endDate ) ); |
180 | |
181 | } |
182 | |
183 | /** |
184 | * Creates and returns a copy of this object. |
185 | * |
186 | * @return A clone of this instance. |
187 | */ |
188 | public Object clone() |
189 | { |
190 | try |
191 | { |
192 | final JaxpCurrency ret = (JaxpCurrency) super.clone(); |
193 | if ( this.startDate != null ) |
194 | { |
195 | ret.startDate = (Date) this.startDate.clone(); |
196 | } |
197 | if ( this.endDate != null ) |
198 | { |
199 | ret.endDate = (Date) this.endDate.clone(); |
200 | } |
201 | |
202 | return ret; |
203 | } |
204 | catch ( final CloneNotSupportedException e ) |
205 | { |
206 | throw new AssertionError( e ); |
207 | } |
208 | } |
209 | |
210 | /** |
211 | * Indicates whether some other object is equal to this one by comparing the values of all properties. |
212 | * |
213 | * @param o The reference object with which to compare. |
214 | * |
215 | * @return {@code true} if this object is the same as {@code o}; {@code false} otherwise. |
216 | */ |
217 | public boolean equals( final Object o ) |
218 | { |
219 | boolean ret = o == this; |
220 | |
221 | if ( !ret && o instanceof JaxpCurrency ) |
222 | { |
223 | final JaxpCurrency that = (JaxpCurrency) o; |
224 | |
225 | ret = ( this.isoCode == null |
226 | ? that.isoCode == null |
227 | : this.isoCode.equals( that.isoCode ) ) |
228 | && ( this.dtausCode == null |
229 | ? that.dtausCode == null |
230 | : this.dtausCode.equals( that.dtausCode ) ) |
231 | && ( this.startDate == null |
232 | ? that.startDate == null |
233 | : this.startDate.equals( that.startDate ) ) |
234 | && ( this.endDate == null |
235 | ? that.endDate == null |
236 | : this.endDate.equals( that.endDate ) ); |
237 | |
238 | } |
239 | |
240 | return ret; |
241 | } |
242 | |
243 | /** |
244 | * Returns a hash code value for this object. |
245 | * |
246 | * @return A hash code value for this object. |
247 | */ |
248 | public int hashCode() |
249 | { |
250 | if ( this.hashCode == NO_HASHCODE ) |
251 | { |
252 | int hc = 23; |
253 | hc = 37 * hc + ( this.dtausCode == null |
254 | ? 0 |
255 | : (int) this.dtausCode.charValue() ); |
256 | hc = 37 * hc + ( this.isoCode == null |
257 | ? 0 |
258 | : this.isoCode.hashCode() ); |
259 | hc = 37 * hc + ( this.startDate == null |
260 | ? 0 |
261 | : this.startDate.hashCode() ); |
262 | hc = 37 * hc + ( this.endDate == null |
263 | ? 0 |
264 | : this.endDate.hashCode() ); |
265 | |
266 | this.hashCode = hc; |
267 | } |
268 | |
269 | return this.hashCode; |
270 | } |
271 | |
272 | /** |
273 | * Returns a string representation of the object. |
274 | * |
275 | * @return A string representation of the object. |
276 | */ |
277 | public String toString() |
278 | { |
279 | return super.toString() + this.internalString(); |
280 | } |
281 | |
282 | /** |
283 | * Creates a string representing the properties of the instance. |
284 | * |
285 | * @return A string representing the properties of the instance. |
286 | */ |
287 | private String internalString() |
288 | { |
289 | return new StringBuffer( 200 ).append( '{' ). |
290 | append( "isoCode=" ).append( this.isoCode ). |
291 | append( ", dtausCode=" ).append( this.dtausCode ). |
292 | append( ", startDate=" ).append( this.startDate ). |
293 | append( ", endDate=" ).append( this.endDate ). |
294 | append( '}' ).toString(); |
295 | |
296 | } |
297 | |
298 | } |