1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.jdtaus.banking.dtaus;
22
23 import java.io.Serializable;
24
25
26
27
28
29
30
31 public class Checksum implements Cloneable, Serializable
32 {
33
34
35 private static final long serialVersionUID = -7639085407620663083L;
36
37
38
39
40
41 private int transactionCount;
42
43
44
45
46
47 private long sumTargetAccount;
48
49
50
51
52
53 private long sumTargetBank;
54
55
56
57
58
59 private long sumAmount;
60
61
62 private transient int hashCode = NO_HASHCODE;
63 private static final int NO_HASHCODE = Integer.MIN_VALUE;
64
65
66 public Checksum()
67 {
68 super();
69 }
70
71
72
73
74
75
76 public int getTransactionCount()
77 {
78 return this.transactionCount;
79 }
80
81
82
83
84
85
86 public void setTransactionCount( final int value )
87 {
88 this.transactionCount = value;
89 this.hashCode = NO_HASHCODE;
90 }
91
92
93
94
95
96
97 public long getSumTargetAccount()
98 {
99 return this.sumTargetAccount;
100 }
101
102
103
104
105
106
107 public void setSumTargetAccount( final long value )
108 {
109 this.sumTargetAccount = value;
110 this.hashCode = NO_HASHCODE;
111 }
112
113
114
115
116
117
118 public long getSumTargetBank()
119 {
120 return this.sumTargetBank;
121 }
122
123
124
125
126
127
128 public void setSumTargetBank( final long value )
129 {
130 this.sumTargetBank = value;
131 this.hashCode = NO_HASHCODE;
132 }
133
134
135
136
137
138
139 public long getSumAmount()
140 {
141 return this.sumAmount;
142 }
143
144
145
146
147
148
149 public void setSumAmount( final long value )
150 {
151 this.sumAmount = value;
152 this.hashCode = NO_HASHCODE;
153 }
154
155
156
157
158
159
160
161
162 public void add( final Transaction transaction )
163 {
164 if ( transaction == null )
165 {
166 throw new NullPointerException( "transaction" );
167 }
168
169 this.sumAmount += transaction.getAmount().longValue();
170 this.sumTargetAccount += transaction.getTargetAccount().longValue();
171 this.sumTargetBank += transaction.getTargetBank().longValue();
172 this.hashCode = NO_HASHCODE;
173 }
174
175
176
177
178
179
180
181
182
183 public final void substract( final Transaction transaction )
184 {
185 this.subtract( transaction );
186 }
187
188
189
190
191
192
193
194
195 public void subtract( final Transaction transaction )
196 {
197 if ( transaction == null )
198 {
199 throw new NullPointerException( "transaction" );
200 }
201
202 this.sumAmount -= transaction.getAmount().longValue();
203 this.sumTargetAccount -= transaction.getTargetAccount().longValue();
204 this.sumTargetBank -= transaction.getTargetBank().longValue();
205 this.hashCode = NO_HASHCODE;
206 }
207
208
209
210
211
212
213
214
215 public boolean equals( final Object o )
216 {
217 boolean equal = o == this;
218
219 if ( !equal && o instanceof Checksum )
220 {
221 final Checksum that = (Checksum) o;
222 equal = this.getSumAmount() == that.getSumAmount() &&
223 this.getSumTargetAccount() == that.getSumTargetAccount() &&
224 this.getSumTargetBank() == that.getSumTargetBank() &&
225 this.getTransactionCount() == that.getTransactionCount();
226
227 }
228
229 return equal;
230 }
231
232
233
234
235
236
237 public int hashCode()
238 {
239 if ( this.hashCode == NO_HASHCODE )
240 {
241 int hc = 23;
242 hc = 37 * hc + (int) ( this.sumAmount ^ ( this.sumAmount >>> 32 ) );
243 hc = 37 * hc + (int) ( this.sumTargetAccount ^ ( this.sumTargetAccount >>> 32 ) );
244 hc = 37 * hc + (int) ( this.sumTargetBank ^ ( this.sumTargetBank >>> 32 ) );
245 hc = 37 * hc + this.transactionCount;
246 this.hashCode = hc;
247 }
248
249 return this.hashCode;
250 }
251
252
253
254
255
256
257 public Object clone()
258 {
259 try
260 {
261 return super.clone();
262 }
263 catch ( final CloneNotSupportedException e )
264 {
265 throw new AssertionError( e );
266 }
267 }
268
269
270
271
272
273
274 public String toString()
275 {
276 return super.toString() + this.internalString();
277 }
278
279
280
281
282
283
284 private String internalString()
285 {
286 return new StringBuffer( 100 ).append( '{' ).
287 append( "sumAmount=" ).append( this.sumAmount ).
288 append( ", sumTargetAccount=" ).append( this.sumTargetAccount ).
289 append( ", sumTargetBank=" ).append( this.sumTargetBank ).
290 append( ", transactionCount=" ).append( this.transactionCount ).
291 append( '}' ).toString();
292
293 }
294
295 }