001/* 002 * jDTAUS Banking RI CurrencyDirectory 003 * Copyright (C) 2005 Christian Schulte 004 * <cs@schulte.it> 005 * 006 * This library is free software; you can redistribute it and/or 007 * modify it under the terms of the GNU Lesser General Public 008 * License as published by the Free Software Foundation; either 009 * version 2.1 of the License, or any later version. 010 * 011 * This library 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 GNU 014 * Lesser General Public License for more details. 015 * 016 * You should have received a copy of the GNU Lesser General Public 017 * License along with this library; if not, write to the Free Software 018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 019 * 020 */ 021package org.jdtaus.banking.ri.currencydir; 022 023import java.io.Serializable; 024import java.util.Date; 025 026/** 027 * Currency. 028 * 029 * @author <a href="mailto:cs@schulte.it">Christian Schulte</a> 030 * @version $JDTAUS: JaxpCurrency.java 8661 2012-09-27 11:29:58Z schulte $ 031 */ 032public class JaxpCurrency implements Serializable, Cloneable 033{ 034 035 /** Serial version UID for backwards compatibility with 1.0.x classes. */ 036 private static final long serialVersionUID = 3499875740280116856L; 037 038 /** 039 * ISO currency code. 040 * @serial 041 */ 042 private String isoCode; 043 044 /** 045 * DTAUS currency code. 046 * @serial 047 */ 048 private Character dtausCode; 049 050 /** 051 * Start date. 052 * @serial 053 */ 054 private Date startDate; 055 056 /** 057 * End date. 058 * @serial 059 */ 060 private Date endDate; 061 062 /** Cached hash-code. */ 063 private transient int hashCode = NO_HASHCODE; 064 065 /** Constant for field {@code hashCode} forcing hash code computation. */ 066 private static final int NO_HASHCODE = Integer.MIN_VALUE; 067 068 /** Creates a new {@code JaxpCurrency} instance. */ 069 public JaxpCurrency() 070 { 071 super(); 072 } 073 074 /** 075 * Gets the ISO currency code. 076 * 077 * @return The ISO currency code. 078 */ 079 public String getIsoCode() 080 { 081 return this.isoCode; 082 } 083 084 /** 085 * Sets the ISO currency code. 086 * 087 * @param value The ISO currency code. 088 */ 089 public void setIsoCode( final String value ) 090 { 091 this.isoCode = value; 092 this.hashCode = NO_HASHCODE; 093 } 094 095 /** 096 * Gets the DTAUS currency code. 097 * 098 * @return The DTAUS currency code or {@code null}. 099 */ 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 this.startDate; 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 = value; 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 this.endDate; 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 = value; 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}; {@code false} if not. 164 * 165 * @throws NullPointerException if {@code date} is {@code null}. 166 */ 167 public boolean isValidAt( final Date date ) 168 { 169 if ( date == null ) 170 { 171 throw new NullPointerException( "date" ); 172 } 173 174 return ( date.equals( this.getStartDate() ) || date.after( this.getStartDate() ) ) && 175 ( this.getEndDate() == null || date.equals( this.getEndDate() ) || date.before( this.getEndDate() ) ); 176 177 } 178 179 /** 180 * Creates and returns a copy of this object. 181 * 182 * @return A clone of this instance. 183 */ 184 public Object clone() 185 { 186 try 187 { 188 final JaxpCurrency ret = (JaxpCurrency) super.clone(); 189 if ( this.startDate != null ) 190 { 191 ret.startDate = (Date) this.startDate.clone(); 192 } 193 if ( this.endDate != null ) 194 { 195 ret.endDate = (Date) this.endDate.clone(); 196 } 197 198 return ret; 199 } 200 catch ( final CloneNotSupportedException e ) 201 { 202 throw new AssertionError( e ); 203 } 204 } 205 206 /** 207 * Indicates whether some other object is equal to this one by comparing the values of all properties. 208 * 209 * @param o The reference object with which to compare. 210 * 211 * @return {@code true} if this object is the same as {@code o}; {@code false} otherwise. 212 */ 213 public boolean equals( final Object o ) 214 { 215 boolean ret = o == this; 216 217 if ( !ret && o instanceof JaxpCurrency ) 218 { 219 final JaxpCurrency that = (JaxpCurrency) o; 220 ret = ( this.getIsoCode() == null 221 ? that.getIsoCode() == null : this.getIsoCode().equals( that.getIsoCode() ) ) && 222 ( this.getDtausCode() == that.getDtausCode() ) && 223 ( this.getStartDate() == null 224 ? that.getStartDate() == null : this.getStartDate().equals( that.getStartDate() ) ) && 225 ( this.getEndDate() == null 226 ? that.getEndDate() == null : this.getEndDate().equals( that.getEndDate() ) ); 227 228 } 229 230 return ret; 231 } 232 233 /** 234 * Returns a hash code value for this object. 235 * 236 * @return A hash code value for this object. 237 */ 238 public int hashCode() 239 { 240 if ( this.hashCode == NO_HASHCODE ) 241 { 242 int hc = 23; 243 hc = 37 * hc + ( this.dtausCode == null ? 0 : (int) this.dtausCode.charValue() ); 244 hc = 37 * hc + ( this.isoCode == null ? 0 : this.isoCode.hashCode() ); 245 hc = 37 * hc + ( this.startDate == null ? 0 : this.startDate.hashCode() ); 246 hc = 37 * hc + ( this.endDate == null ? 0 : this.endDate.hashCode() ); 247 this.hashCode = hc; 248 } 249 250 return this.hashCode; 251 } 252 253 /** 254 * Returns a string representation of the object. 255 * 256 * @return A string representation of the object. 257 */ 258 public String toString() 259 { 260 return super.toString() + this.internalString(); 261 } 262 263 /** 264 * Creates a string representing the properties of the instance. 265 * 266 * @return A string representing the properties of the instance. 267 */ 268 private String internalString() 269 { 270 return new StringBuffer( 200 ).append( '{' ). 271 append( "isoCode=" ).append( this.isoCode ). 272 append( ", dtausCode=" ).append( this.dtausCode ). 273 append( ", startDate=" ).append( this.startDate ). 274 append( ", endDate=" ).append( this.endDate ). 275 append( '}' ).toString(); 276 277 } 278 279}