-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVoucher.java
More file actions
38 lines (27 loc) · 848 Bytes
/
Copy pathVoucher.java
File metadata and controls
38 lines (27 loc) · 848 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package hashCodeEquals;
/***
* Composition instead of Inheritance. Voucher class with a Money property
*
*/
public class Voucher {
// Object Composition
private Money2 money2;
private String store;
public Voucher(int amount, String currencyCode, String store) {
this.money2 = new Money2(amount, currencyCode);
this.store = store;
}
@Override
public boolean equals(Object obj) {
if (obj == null)
return true;
if (!(obj instanceof Voucher))
return false;
Voucher voucher = (Voucher) obj;
boolean isMoneyEqual = (this.money2 == null && voucher.money2 == null)
|| (this.money2 != null && this.money2.equals(voucher.money2));
boolean isStoreEquals = (this.store == null && voucher.money2 == null)
|| (this.store != null && this.store.equals(voucher.store));
return isMoneyEqual && isStoreEquals;
}
}