| 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.ArrayList; |
| 25 | import java.util.Collection; |
| 26 | import java.util.Locale; |
| 27 | import org.jdtaus.core.container.ContainerFactory; |
| 28 | |
| 29 | /** |
| 30 | * Type of a logical file. |
| 31 | * |
| 32 | * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> |
| 33 | * @version $JDTAUS: LogicalFileType.java 8661 2012-09-27 11:29:58Z schulte $ |
| 34 | */ |
| 35 | public final class LogicalFileType implements Serializable |
| 36 | { |
| 37 | |
| 38 | /** Constant for a logical file holding debit orders sent by a customer. Kundendatei Lastschriften. */ |
| 39 | public static final LogicalFileType LK = new LogicalFileType( "LK", true, false, true, false ); |
| 40 | |
| 41 | /** Constant for a logical file holding remittance orders sent by a customer. Kundendatei Gutschriften. */ |
| 42 | public static final LogicalFileType GK = new LogicalFileType( "GK", false, true, true, false ); |
| 43 | |
| 44 | /** Constant for a logical file holding debit orders sent by a bank. Bankdatei Lastschriften. */ |
| 45 | public static final LogicalFileType LB = new LogicalFileType( "LB", true, false, false, true ); |
| 46 | |
| 47 | /** Constant for a logical file holding remittance orders sent by a bank. Bankdatei Gutschriften. */ |
| 48 | public static final LogicalFileType GB = new LogicalFileType( "GB", false, true, false, true ); |
| 49 | |
| 50 | /** Supported DTAUS codes. */ |
| 51 | private static final LogicalFileType[] SUPPORTED = |
| 52 | { |
| 53 | GB, GK, LB, LK |
| 54 | }; |
| 55 | |
| 56 | /** Serial version UID for backwards compatibility with 1.0.x classes. */ |
| 57 | private static final long serialVersionUID = 5932863701674153762L; |
| 58 | |
| 59 | /** |
| 60 | * DTAUS code. |
| 61 | * @serial |
| 62 | */ |
| 63 | private String code; |
| 64 | |
| 65 | /** |
| 66 | * Flag indicating if a logical file may hold debit orders. |
| 67 | * @serial |
| 68 | */ |
| 69 | private boolean debitAllowed; |
| 70 | |
| 71 | /** |
| 72 | * Flag indicating if a logical file may hold remittance orders. |
| 73 | * @serial |
| 74 | */ |
| 75 | private boolean remittanceAllowed; |
| 76 | |
| 77 | /** |
| 78 | * Flag indicating if a logical file is allowed to be created by a customer. |
| 79 | * @serial |
| 80 | */ |
| 81 | private boolean sendByCustomer; |
| 82 | |
| 83 | /** |
| 84 | * Flag indicating if a logical file is allowed to be created by a bank. |
| 85 | * @serial |
| 86 | */ |
| 87 | private boolean sendByBank; |
| 88 | |
| 89 | /** |
| 90 | * Creates a new {@code LogicalFileType} instance initializing all properties. |
| 91 | * |
| 92 | * @param code DTAUS code of the type. |
| 93 | * @param debitAllowed {@code true} if a logical file may hold debit orders; {@code false} if not. |
| 94 | * @param remittanceAllowed {@code true} if a logical file may hold remittance orders; {@code false} if not. |
| 95 | * @param sendByBank {@code true} if a logical file is allowed to be created by a bank; {@code false} if not. |
| 96 | * @param sendByCustomer {@code true} if a logical file is allowed to be created by a customer; {@code false} if |
| 97 | * not. |
| 98 | * |
| 99 | * @throws NullPointerException if {@code code} is {@code null}. |
| 100 | */ |
| 101 | private LogicalFileType( final String code, final boolean debitAllowed, final boolean remittanceAllowed, |
| 102 | final boolean sendByCustomer, final boolean sendByBank ) |
| 103 | { |
| 104 | if ( code == null ) |
| 105 | { |
| 106 | throw new NullPointerException( "code" ); |
| 107 | } |
| 108 | |
| 109 | this.code = code; |
| 110 | this.debitAllowed = debitAllowed; |
| 111 | this.remittanceAllowed = remittanceAllowed; |
| 112 | this.sendByBank = sendByBank; |
| 113 | this.sendByCustomer = sendByCustomer; |
| 114 | } |
| 115 | |
| 116 | /** |
| 117 | * Returns an instance for the type identified by a DTAUS code. |
| 118 | * |
| 119 | * @param code A DTAUS code identifying a type of a logical file. |
| 120 | * |
| 121 | * @return An instance for {@code code} or {@code null} if {@code code} is no known logical file type. |
| 122 | * |
| 123 | * @throws NullPointerException if {@code code} is {@code null}. |
| 124 | */ |
| 125 | public static LogicalFileType valueOf( final String code ) |
| 126 | { |
| 127 | if ( code == null ) |
| 128 | { |
| 129 | throw new NullPointerException( "code" ); |
| 130 | } |
| 131 | |
| 132 | for ( int i = SUPPORTED.length - 1; i >= 0; i-- ) |
| 133 | { |
| 134 | if ( SUPPORTED[i].getCode().equals( code ) ) |
| 135 | { |
| 136 | return SUPPORTED[i]; |
| 137 | } |
| 138 | } |
| 139 | |
| 140 | return null; |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Getter for property {@code code}. |
| 145 | * |
| 146 | * @return DTAUS code of the logical file type. |
| 147 | */ |
| 148 | public String getCode() |
| 149 | { |
| 150 | return this.code; |
| 151 | } |
| 152 | |
| 153 | /** |
| 154 | * Flag indicating if a logical file may hold debit orders. |
| 155 | * |
| 156 | * @return {@code true} if a logical file may hold debit orders; {@code false} if not. |
| 157 | */ |
| 158 | public boolean isDebitAllowed() |
| 159 | { |
| 160 | return this.debitAllowed; |
| 161 | } |
| 162 | |
| 163 | /** |
| 164 | * Flag indicating if a logical file may hold remittance orders. |
| 165 | * |
| 166 | * @return {@code true} if a logical file may hold remittance orders; {@code false} if not. |
| 167 | */ |
| 168 | public boolean isRemittanceAllowed() |
| 169 | { |
| 170 | return this.remittanceAllowed; |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * Flag indicating if a logical file is allowed to be created by a customer. |
| 175 | * |
| 176 | * @return {@code true} if a logical file is allowed to be created by a customer; {@code false} if not. |
| 177 | */ |
| 178 | public boolean isSendByCustomer() |
| 179 | { |
| 180 | return this.sendByCustomer; |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * Flag indicating if a logical file is allowed to be created by a bank. |
| 185 | * |
| 186 | * @return {@code true} if a logical file is allowed to be created by a bank; {@code false} if not. |
| 187 | */ |
| 188 | public boolean isSendByBank() |
| 189 | { |
| 190 | return this.sendByBank; |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Gets the short description of the file type for a given locale. |
| 195 | * |
| 196 | * @param locale The locale of the short description to return or {@code null} for {@code Locale.getDefault()}. |
| 197 | * |
| 198 | * @return The short description of the instance. |
| 199 | */ |
| 200 | public String getShortDescription( final Locale locale ) |
| 201 | { |
| 202 | String shortDescription = ""; |
| 203 | |
| 204 | final Locale l = locale == null ? Locale.getDefault() : locale; |
| 205 | |
| 206 | if ( "LK".equals( this.getCode() ) ) |
| 207 | { |
| 208 | shortDescription = this.getLogicalFileType_LKMessage( l ); |
| 209 | } |
| 210 | else if ( "GK".equals( this.getCode() ) ) |
| 211 | { |
| 212 | shortDescription = this.getLogicalFileType_GKMessage( l ); |
| 213 | } |
| 214 | else if ( "LB".equals( this.getCode() ) ) |
| 215 | { |
| 216 | shortDescription = this.getLogicalFileType_LBMessage( l ); |
| 217 | } |
| 218 | else if ( "GB".equals( this.getCode() ) ) |
| 219 | { |
| 220 | shortDescription = this.getLogicalFileType_GBMessage( l ); |
| 221 | } |
| 222 | |
| 223 | return shortDescription; |
| 224 | } |
| 225 | |
| 226 | /** |
| 227 | * Searches the implementation for {@code LogicalFileType} instances according to the given arguments. |
| 228 | * |
| 229 | * @param debitAllowed Value to compare property {@code debitAllowed} with. |
| 230 | * @param remittanceAllowed Value to compare property {@code remittanceAllowed} with. |
| 231 | * @param sendByBank Value to compare property {@code sendByBank} with. |
| 232 | * @param sendByCustomer Value to compare property {@code sendByCustomer} with. |
| 233 | * |
| 234 | * @return All {@code LogicalFileType} instances with property {@code debitAllowed} equal to the |
| 235 | * {@code debitAllowed} argument, property {@code remittanceAllowed} equal to the {@code remittanceAllowed} |
| 236 | * argument, property {@code sendByBank} equal to the {@code sendByBank} argument and property |
| 237 | * {@code sendByCustomer} equal to the {@code sendByCustomer} argument. |
| 238 | * |
| 239 | * @deprecated Replaced by {@link #searchLogicalFileTypes(java.lang.Boolean, java.lang.Boolean, java.lang.Boolean, java.lang.Boolean) }. |
| 240 | */ |
| 241 | public static LogicalFileType[] search( final boolean debitAllowed, final boolean remittanceAllowed, |
| 242 | final boolean sendByBank, final boolean sendByCustomer ) |
| 243 | { |
| 244 | return searchLogicalFileTypes( Boolean.valueOf( debitAllowed ), Boolean.valueOf( remittanceAllowed ), |
| 245 | Boolean.valueOf( sendByBank ), Boolean.valueOf( sendByCustomer ) ); |
| 246 | |
| 247 | } |
| 248 | |
| 249 | /** |
| 250 | * Searches the implementation for {@code LogicalFileType} instances |
| 251 | * according to the given arguments. |
| 252 | * |
| 253 | * @param debitAllowed Value to compare property {@code debitAllowed} with |
| 254 | * or {@code null} to ignore that property during searching. |
| 255 | * @param remittanceAllowed Value to compare property |
| 256 | * {@code remittanceAllowed} with or {@code null} to ignore that property |
| 257 | * during searching. |
| 258 | * @param sendByBank Value to compare property {@code sendByBank} with or |
| 259 | * {@code null} to ignore that property during searching. |
| 260 | * @param sendByCustomer Value to compare property {@code sendByCustomer} |
| 261 | * with or {@code null} to ignore that property during searching. |
| 262 | * |
| 263 | * @return All {@code LogicalFileType} instances with property |
| 264 | * {@code debitAllowed} equal to the {@code debitAllowed} argument when |
| 265 | * given, property {@code remittanceAllowed} equal to the |
| 266 | * {@code remittanceAllowed} argument when given, property |
| 267 | * {@code sendByBank} equal to the {@code sendByBank} argument when given, |
| 268 | * and property {@code sendByCustomer} equal to the {@code sendByCustomer} |
| 269 | * argument when given. |
| 270 | */ |
| 271 | public static LogicalFileType[] searchLogicalFileTypes( final Boolean debitAllowed, final Boolean remittanceAllowed, |
| 272 | final Boolean sendByBank, final Boolean sendByCustomer ) |
| 273 | { |
| 274 | final Collection c = new ArrayList( SUPPORTED.length ); |
| 275 | |
| 276 | for ( int i = SUPPORTED.length - 1; i >= 0; i-- ) |
| 277 | { |
| 278 | if ( ( debitAllowed == null ? true : SUPPORTED[i].isDebitAllowed() == debitAllowed.booleanValue() ) && |
| 279 | ( remittanceAllowed == null |
| 280 | ? true : SUPPORTED[i].isRemittanceAllowed() == remittanceAllowed.booleanValue() ) && |
| 281 | ( sendByBank == null ? true : SUPPORTED[i].isSendByBank() == sendByBank.booleanValue() ) && |
| 282 | ( sendByCustomer == null ? true : SUPPORTED[i].isSendByCustomer() == sendByCustomer.booleanValue() ) ) |
| 283 | { |
| 284 | c.add( SUPPORTED[i] ); |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | return (LogicalFileType[]) c.toArray( new LogicalFileType[ c.size() ] ); |
| 289 | } |
| 290 | |
| 291 | /** |
| 292 | * Creates a string representing the properties of the instance. |
| 293 | * |
| 294 | * @return A string representing the properties of the instance. |
| 295 | */ |
| 296 | private String internalString() |
| 297 | { |
| 298 | return new StringBuffer( 200 ).append( '{' ). |
| 299 | append( "code=" ).append( this.code ). |
| 300 | append( ", debitAllowed=" ).append( this.debitAllowed ). |
| 301 | append( ", remittanceAllowed=" ).append( this.remittanceAllowed ). |
| 302 | append( ", sendByCustomer=" ).append( this.sendByCustomer ). |
| 303 | append( ", sendByBank=" ).append( this.sendByBank ). |
| 304 | append( '}' ).toString(); |
| 305 | |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * Indicates whether some other object is equal to this one by comparing the values of all properties. |
| 310 | * |
| 311 | * @param o The reference object with which to compare. |
| 312 | * |
| 313 | * @return {@code true} if this object is the same as {@code o}; {@code false} otherwise. |
| 314 | */ |
| 315 | public boolean equals( final Object o ) |
| 316 | { |
| 317 | boolean ret = o == this; |
| 318 | |
| 319 | if ( !ret && o instanceof LogicalFileType ) |
| 320 | { |
| 321 | final LogicalFileType that = (LogicalFileType) o; |
| 322 | |
| 323 | ret = this.isDebitAllowed() == that.isDebitAllowed() && |
| 324 | this.isRemittanceAllowed() == that.isRemittanceAllowed() && |
| 325 | this.isSendByBank() == that.isSendByBank() && |
| 326 | this.isSendByCustomer() == that.isSendByCustomer() && |
| 327 | ( this.getCode() == null ? that.getCode() == null : this.getCode().equals( that.getCode() ) ); |
| 328 | |
| 329 | } |
| 330 | |
| 331 | return ret; |
| 332 | } |
| 333 | |
| 334 | /** |
| 335 | * Returns a hash code value for this object. |
| 336 | * |
| 337 | * @return A hash code value for this object. |
| 338 | */ |
| 339 | public int hashCode() |
| 340 | { |
| 341 | return this.internalString().hashCode(); |
| 342 | } |
| 343 | |
| 344 | /** |
| 345 | * Returns a string representation of the object. |
| 346 | * |
| 347 | * @return A string representation of the object. |
| 348 | */ |
| 349 | public String toString() |
| 350 | { |
| 351 | return super.toString() + this.internalString(); |
| 352 | } |
| 353 | |
| 354 | //--Messages---------------------------------------------------------------- |
| 355 | |
| 356 | // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:jdtausMessages |
| 357 | // This section is managed by jdtaus-container-mojo. |
| 358 | |
| 359 | /** |
| 360 | * Gets the text of message <code>logicalFileType_GB</code>. |
| 361 | * <blockquote><pre>Bankdatei - Gutschriften</pre></blockquote> |
| 362 | * <blockquote><pre>Bank file - remittances</pre></blockquote> |
| 363 | * |
| 364 | * @param locale The locale of the message instance to return. |
| 365 | * |
| 366 | * @return the text of message <code>logicalFileType_GB</code>. |
| 367 | */ |
| 368 | private String getLogicalFileType_GBMessage( final Locale locale ) |
| 369 | { |
| 370 | return ContainerFactory.getContainer(). |
| 371 | getMessage( this, "logicalFileType_GB", locale, null ); |
| 372 | |
| 373 | } |
| 374 | |
| 375 | /** |
| 376 | * Gets the text of message <code>logicalFileType_LB</code>. |
| 377 | * <blockquote><pre>Bankdatei - Lastschriften</pre></blockquote> |
| 378 | * <blockquote><pre>Bank file - debits</pre></blockquote> |
| 379 | * |
| 380 | * @param locale The locale of the message instance to return. |
| 381 | * |
| 382 | * @return the text of message <code>logicalFileType_LB</code>. |
| 383 | */ |
| 384 | private String getLogicalFileType_LBMessage( final Locale locale ) |
| 385 | { |
| 386 | return ContainerFactory.getContainer(). |
| 387 | getMessage( this, "logicalFileType_LB", locale, null ); |
| 388 | |
| 389 | } |
| 390 | |
| 391 | /** |
| 392 | * Gets the text of message <code>logicalFileType_GK</code>. |
| 393 | * <blockquote><pre>Kundendatei - Gutschriften</pre></blockquote> |
| 394 | * <blockquote><pre>Customer file - remittances</pre></blockquote> |
| 395 | * |
| 396 | * @param locale The locale of the message instance to return. |
| 397 | * |
| 398 | * @return the text of message <code>logicalFileType_GK</code>. |
| 399 | */ |
| 400 | private String getLogicalFileType_GKMessage( final Locale locale ) |
| 401 | { |
| 402 | return ContainerFactory.getContainer(). |
| 403 | getMessage( this, "logicalFileType_GK", locale, null ); |
| 404 | |
| 405 | } |
| 406 | |
| 407 | /** |
| 408 | * Gets the text of message <code>logicalFileType_LK</code>. |
| 409 | * <blockquote><pre>Kundendatei - Lastschriften</pre></blockquote> |
| 410 | * <blockquote><pre>Customer file - debits</pre></blockquote> |
| 411 | * |
| 412 | * @param locale The locale of the message instance to return. |
| 413 | * |
| 414 | * @return the text of message <code>logicalFileType_LK</code>. |
| 415 | */ |
| 416 | private String getLogicalFileType_LKMessage( final Locale locale ) |
| 417 | { |
| 418 | return ContainerFactory.getContainer(). |
| 419 | getMessage( this, "logicalFileType_LK", locale, null ); |
| 420 | |
| 421 | } |
| 422 | |
| 423 | // </editor-fold>//GEN-END:jdtausMessages |
| 424 | |
| 425 | //----------------------------------------------------------------Messages-- |
| 426 | } |