| 1 | /* |
| 2 | * jDTAUS Banking API |
| 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.dtaus; |
| 22 | |
| 23 | import java.io.Serializable; |
| 24 | import java.util.Calendar; |
| 25 | import java.util.Currency; |
| 26 | import java.util.Date; |
| 27 | import org.jdtaus.banking.AlphaNumericText27; |
| 28 | import org.jdtaus.banking.Bankleitzahl; |
| 29 | import org.jdtaus.banking.Kontonummer; |
| 30 | import org.jdtaus.banking.Referenznummer10; |
| 31 | |
| 32 | /** |
| 33 | * "A" record. |
| 34 | * |
| 35 | * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> |
| 36 | * @version $JDTAUS: Header.java 8661 2012-09-27 11:29:58Z schulte $ |
| 37 | */ |
| 38 | public class Header implements Cloneable, Serializable |
| 39 | { |
| 40 | |
| 41 | /** Constant for the name of property {@code customer}. */ |
| 42 | public static final String PROP_CUSTOMER = "org.jdtaus.banking.dtaus.Header.PROP_CUSTOMER"; |
| 43 | |
| 44 | /** Constant for the name of property {@code account}. */ |
| 45 | public static final String PROP_ACCOUNT = "org.jdtaus.banking.dtaus.Header.PROP_ACCOUNT"; |
| 46 | |
| 47 | /** Constant for the name of property {@code bank}. */ |
| 48 | public static final String PROP_BANK = "org.jdtaus.banking.dtaus.Header.PROP_BANK"; |
| 49 | |
| 50 | /** Constant for the name of property {@code type}. */ |
| 51 | public static final String PROP_TYPE = "org.jdtaus.banking.dtaus.Header.PROP_TYPE"; |
| 52 | |
| 53 | /** Constant for the name of property {@code currency}. */ |
| 54 | public static final String PROP_CURRENCY = "org.jdtaus.banking.dtaus.Header.PROP_CURRENCY"; |
| 55 | |
| 56 | /** Constant for the name of property {@code reference}. */ |
| 57 | public static final String PROP_REFERENCE = "org.jdtaus.banking.dtaus.Header.PROP_REFERENCE"; |
| 58 | |
| 59 | /** Constant for the name of property {@code bankData}. */ |
| 60 | public static final String PROP_BANKDATA = "org.jdtaus.banking.dtaus.Header.PROP_BANKDATA"; |
| 61 | |
| 62 | /** Constant for the name of property {@code createDate}. */ |
| 63 | public static final String PROP_CREATEDATE = "org.jdtaus.banking.dtaus.Header.PROP_CREATEDATE"; |
| 64 | |
| 65 | /** Constant for the name of property {@code executionDate}. */ |
| 66 | public static final String PROP_EXECUTIONDATE = "org.jdtaus.banking.dtaus.Header.PROP_EXECUTIONDATE"; |
| 67 | |
| 68 | /** Serial version UID for backwards compatibility with 1.0.x classes. */ |
| 69 | private static final long serialVersionUID = -5704199858711059732L; |
| 70 | |
| 71 | /** |
| 72 | * Name of the customer a logical file belongs to. |
| 73 | * @serial |
| 74 | */ |
| 75 | private AlphaNumericText27 customer; |
| 76 | |
| 77 | /** |
| 78 | * Code of the account a logical file belongs to. |
| 79 | * @serial |
| 80 | */ |
| 81 | private Kontonummer account; |
| 82 | |
| 83 | /** |
| 84 | * Code of the bank a logical file belongs to. |
| 85 | * @serial |
| 86 | */ |
| 87 | private Bankleitzahl bank; |
| 88 | |
| 89 | /** |
| 90 | * Type of a logical file. |
| 91 | * @serial |
| 92 | */ |
| 93 | private LogicalFileType type; |
| 94 | |
| 95 | /** |
| 96 | * Currency of a logical file. |
| 97 | * @serial |
| 98 | */ |
| 99 | private Currency currency; |
| 100 | |
| 101 | /** |
| 102 | * Reference code of a logical file. |
| 103 | * @serial |
| 104 | */ |
| 105 | private Referenznummer10 reference; |
| 106 | |
| 107 | /** |
| 108 | * Create date of a logical file. |
| 109 | * @serial |
| 110 | */ |
| 111 | private Date createDate; |
| 112 | |
| 113 | /** |
| 114 | * Execution date of a logical file. |
| 115 | * @serial |
| 116 | */ |
| 117 | private Date executionDate; |
| 118 | |
| 119 | /** |
| 120 | * Bank internal data. |
| 121 | * @serial |
| 122 | */ |
| 123 | private Bankleitzahl bankData; |
| 124 | |
| 125 | /** Cached hash code. */ |
| 126 | private transient int hashCode = NO_HASHCODE; |
| 127 | private static final int NO_HASHCODE = Integer.MIN_VALUE; |
| 128 | |
| 129 | /** Creates a new {@code Header} instance. */ |
| 130 | public Header() |
| 131 | { |
| 132 | super(); |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * Getter for property {@code customer}. |
| 137 | * |
| 138 | * @return Name of the customer a logical file belongs to. |
| 139 | */ |
| 140 | public AlphaNumericText27 getCustomer() |
| 141 | { |
| 142 | return this.customer; |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Setter for property {@code customer}. |
| 147 | * |
| 148 | * @param value Name of the customer a logical file belongs to. |
| 149 | */ |
| 150 | public void setCustomer( final AlphaNumericText27 value ) |
| 151 | { |
| 152 | this.customer = value; |
| 153 | this.hashCode = NO_HASHCODE; |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Getter for property {@code account}. |
| 158 | * |
| 159 | * @return Code of the account a logical file belongs to. |
| 160 | */ |
| 161 | public Kontonummer getAccount() |
| 162 | { |
| 163 | return this.account; |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Setter for property {@code account}. |
| 168 | * |
| 169 | * @param value Code of the account a logical file belongs to. |
| 170 | */ |
| 171 | public void setAccount( final Kontonummer value ) |
| 172 | { |
| 173 | this.account = value; |
| 174 | this.hashCode = NO_HASHCODE; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Getter for property {@code bank}. |
| 179 | * |
| 180 | * @return Code of the bank a logical file belongs to. |
| 181 | */ |
| 182 | public Bankleitzahl getBank() |
| 183 | { |
| 184 | return this.bank; |
| 185 | } |
| 186 | |
| 187 | /** |
| 188 | * Setter for property {@code bank}. |
| 189 | * |
| 190 | * @param value Code of the bank a logical file belongs to. |
| 191 | */ |
| 192 | public void setBank( final Bankleitzahl value ) |
| 193 | { |
| 194 | this.bank = value; |
| 195 | this.hashCode = NO_HASHCODE; |
| 196 | } |
| 197 | |
| 198 | /** |
| 199 | * Getter for property {@code type}. |
| 200 | * |
| 201 | * @return The type of a logical file. |
| 202 | */ |
| 203 | public LogicalFileType getType() |
| 204 | { |
| 205 | return this.type; |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Setter for property {@code type}. |
| 210 | * |
| 211 | * @param value The type of a logical file. |
| 212 | */ |
| 213 | public void setType( final LogicalFileType value ) |
| 214 | { |
| 215 | this.type = value; |
| 216 | this.hashCode = NO_HASHCODE; |
| 217 | } |
| 218 | |
| 219 | /** |
| 220 | * Getter for property {@code currency}. |
| 221 | * |
| 222 | * @return Currency of a logical file. |
| 223 | */ |
| 224 | public Currency getCurrency() |
| 225 | { |
| 226 | return this.currency; |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Setter for property {@code currency}. |
| 231 | * |
| 232 | * @param value Currency for a logical file. |
| 233 | */ |
| 234 | public void setCurrency( final Currency value ) |
| 235 | { |
| 236 | this.currency = value; |
| 237 | this.hashCode = NO_HASHCODE; |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * Getter for property {@code reference}. |
| 242 | * |
| 243 | * @return Reference code of a logical file or {@code null}. |
| 244 | */ |
| 245 | public Referenznummer10 getReference() |
| 246 | { |
| 247 | return this.reference; |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * Setter for property {@code reference}. |
| 252 | * |
| 253 | * @param value Reference code of a logical file or {@code null}. |
| 254 | */ |
| 255 | public void setReference( final Referenznummer10 value ) |
| 256 | { |
| 257 | this.reference = value; |
| 258 | this.hashCode = NO_HASHCODE; |
| 259 | } |
| 260 | |
| 261 | /** |
| 262 | * Getter for property {@code createDate}. |
| 263 | * |
| 264 | * @return Create date of a logical file. |
| 265 | */ |
| 266 | public Date getCreateDate() |
| 267 | { |
| 268 | return this.createDate != null ? (Date) this.createDate.clone() : null; |
| 269 | } |
| 270 | |
| 271 | /** |
| 272 | * Setter for property {@code createDate}. |
| 273 | * |
| 274 | * @param value Create date of a logical file. |
| 275 | */ |
| 276 | public void setCreateDate( final Date value ) |
| 277 | { |
| 278 | this.createDate = null; |
| 279 | this.hashCode = NO_HASHCODE; |
| 280 | |
| 281 | if ( value != null ) |
| 282 | { |
| 283 | final Calendar cal = Calendar.getInstance(); |
| 284 | cal.setTime( value ); |
| 285 | cal.clear( Calendar.HOUR_OF_DAY ); |
| 286 | cal.clear( Calendar.MINUTE ); |
| 287 | cal.clear( Calendar.SECOND ); |
| 288 | cal.clear( Calendar.MILLISECOND ); |
| 289 | this.createDate = cal.getTime(); |
| 290 | } |
| 291 | } |
| 292 | |
| 293 | /** |
| 294 | * Getter for property {@code executionDate}. |
| 295 | * |
| 296 | * @return Execution date of a logical file or {@code null}. |
| 297 | */ |
| 298 | public Date getExecutionDate() |
| 299 | { |
| 300 | return this.executionDate != null ? (Date) this.executionDate.clone() : null; |
| 301 | } |
| 302 | |
| 303 | /** |
| 304 | * Setter for property {@code executionDate}. |
| 305 | * |
| 306 | * @param value Execution date of a logical file or {@code null}. |
| 307 | */ |
| 308 | public void setExecutionDate( final Date value ) |
| 309 | { |
| 310 | this.executionDate = null; |
| 311 | this.hashCode = NO_HASHCODE; |
| 312 | |
| 313 | if ( value != null ) |
| 314 | { |
| 315 | final Calendar cal = Calendar.getInstance(); |
| 316 | cal.setTime( value ); |
| 317 | cal.clear( Calendar.HOUR_OF_DAY ); |
| 318 | cal.clear( Calendar.MINUTE ); |
| 319 | cal.clear( Calendar.SECOND ); |
| 320 | cal.clear( Calendar.MILLISECOND ); |
| 321 | this.executionDate = cal.getTime(); |
| 322 | } |
| 323 | } |
| 324 | |
| 325 | /** |
| 326 | * Getter for property {@code bankData}. |
| 327 | * |
| 328 | * @return Bank internal data. |
| 329 | */ |
| 330 | public Bankleitzahl getBankData() |
| 331 | { |
| 332 | return this.bankData; |
| 333 | } |
| 334 | |
| 335 | /** |
| 336 | * Setter for property {@code bankData}. |
| 337 | * |
| 338 | * @param value Bank internal data. |
| 339 | */ |
| 340 | public void setBankData( final Bankleitzahl value ) |
| 341 | { |
| 342 | this.bankData = value; |
| 343 | this.hashCode = NO_HASHCODE; |
| 344 | } |
| 345 | |
| 346 | /** |
| 347 | * Indicates whether some other object is equal to this one by comparing the values of all properties. |
| 348 | * |
| 349 | * @param o The reference object with which to compare. |
| 350 | * |
| 351 | * @return {@code true} if this object is the same as {@code o}; {@code false} otherwise. |
| 352 | */ |
| 353 | public boolean equals( final Object o ) |
| 354 | { |
| 355 | boolean ret = o == this; |
| 356 | |
| 357 | if ( !ret && o instanceof Header ) |
| 358 | { |
| 359 | final Header that = (Header) o; |
| 360 | ret = ( this.getAccount() == null |
| 361 | ? that.getAccount() == null : this.getAccount().equals( that.getAccount() ) ) && |
| 362 | ( this.getBank() == null |
| 363 | ? that.getBank() == null : this.getBank().equals( that.getBank() ) ) && |
| 364 | ( this.getBankData() == null |
| 365 | ? that.getBankData() == null : this.getBankData().equals( that.getBankData() ) ) && |
| 366 | ( this.getCurrency() == null |
| 367 | ? that.getCurrency() == null : this.getCurrency().equals( that.getCurrency() ) ) && |
| 368 | ( this.getCustomer() == null |
| 369 | ? that.getCustomer() == null : this.getCustomer().equals( that.getCustomer() ) ) && |
| 370 | ( this.getType() == null |
| 371 | ? that.getType() == null : this.getType().equals( that.getType() ) ) && |
| 372 | ( this.getReference() == null |
| 373 | ? that.getReference() == null : this.getReference().equals( that.getReference() ) ) && |
| 374 | ( this.getCreateDate() == null |
| 375 | ? that.getCreateDate() == null : this.getCreateDate().equals( that.getCreateDate() ) ) && |
| 376 | ( this.getExecutionDate() == null |
| 377 | ? that.getExecutionDate() == null : this.getExecutionDate().equals( that.getExecutionDate() ) ); |
| 378 | |
| 379 | } |
| 380 | |
| 381 | return ret; |
| 382 | } |
| 383 | |
| 384 | /** |
| 385 | * Returns a hash code value for this object. |
| 386 | * |
| 387 | * @return A hash code value for this object. |
| 388 | */ |
| 389 | public int hashCode() |
| 390 | { |
| 391 | if ( this.hashCode == NO_HASHCODE ) |
| 392 | { |
| 393 | int hc = 23; |
| 394 | hc = 37 * hc + ( this.account == null ? 0 : this.account.hashCode() ); |
| 395 | hc = 37 * hc + ( this.bank == null ? 0 : this.bank.hashCode() ); |
| 396 | hc = 37 * hc + ( this.bankData == null ? 0 : this.bankData.hashCode() ); |
| 397 | hc = 37 * hc + ( this.currency == null ? 0 : this.currency.hashCode() ); |
| 398 | hc = 37 * hc + ( this.customer == null ? 0 : this.customer.hashCode() ); |
| 399 | hc = 37 * hc + ( this.type == null ? 0 : this.type.hashCode() ); |
| 400 | hc = 37 * hc + ( this.reference == null ? 0 : this.reference.hashCode() ); |
| 401 | hc = 37 * hc + ( this.createDate == null ? 0 : this.createDate.hashCode() ); |
| 402 | hc = 37 * hc + ( this.executionDate == null ? 0 : this.executionDate.hashCode() ); |
| 403 | this.hashCode = hc; |
| 404 | } |
| 405 | |
| 406 | return this.hashCode; |
| 407 | } |
| 408 | |
| 409 | /** |
| 410 | * Creates and returns a copy of this object. |
| 411 | * |
| 412 | * @return A clone of this instance. |
| 413 | */ |
| 414 | public Object clone() |
| 415 | { |
| 416 | try |
| 417 | { |
| 418 | final Object o = super.clone(); |
| 419 | if ( this.createDate != null ) |
| 420 | { |
| 421 | ( (Header) o ).createDate = (Date) this.createDate.clone(); |
| 422 | } |
| 423 | if ( this.executionDate != null ) |
| 424 | { |
| 425 | ( (Header) o ).executionDate = (Date) this.executionDate.clone(); |
| 426 | } |
| 427 | |
| 428 | return o; |
| 429 | } |
| 430 | catch ( final CloneNotSupportedException e ) |
| 431 | { |
| 432 | throw new AssertionError( e ); |
| 433 | } |
| 434 | } |
| 435 | |
| 436 | /** |
| 437 | * Returns a string representation of the object. |
| 438 | * |
| 439 | * @return A string representation of the object. |
| 440 | */ |
| 441 | public String toString() |
| 442 | { |
| 443 | return super.toString() + this.internalString(); |
| 444 | } |
| 445 | |
| 446 | /** |
| 447 | * Creates a string representing the properties of the instance. |
| 448 | * |
| 449 | * @return A string representing the properties of the instance. |
| 450 | */ |
| 451 | private String internalString() |
| 452 | { |
| 453 | return new StringBuffer( 150 ).append( '{' ). |
| 454 | append( "account=" ).append( this.account ). |
| 455 | append( ", bank=" ).append( this.bank ). |
| 456 | append( ", bankData=" ).append( this.bankData ). |
| 457 | append( ", currency=" ).append( this.currency ). |
| 458 | append( ", customer=" ).append( (Object) this.customer ). |
| 459 | append( ", createDate=" ).append( this.createDate ). |
| 460 | append( ", executionDate=" ).append( this.executionDate ). |
| 461 | append( ", type=" ).append( this.type ). |
| 462 | append( ", reference=" ).append( this.reference ). |
| 463 | append( '}' ).toString(); |
| 464 | |
| 465 | } |
| 466 | |
| 467 | } |