1 package org.oxerr.viagogo.model;
2
3 import java.io.Serializable;
4 import java.math.BigDecimal;
5
6 import javax.annotation.Nullable;
7
8 import org.apache.commons.lang3.builder.CompareToBuilder;
9 import org.apache.commons.lang3.builder.EqualsBuilder;
10 import org.apache.commons.lang3.builder.HashCodeBuilder;
11
12
13
14
15
16
17 public class Money implements Comparable<Money>, Serializable {
18
19 private static final long serialVersionUID = 2023021301L;
20
21
22
23
24 @Nullable
25 private BigDecimal amount;
26
27
28
29
30 private String currencyCode;
31
32
33
34
35 private String display;
36
37 public static Money of(String amount, String currencyCode) {
38 return new Money(new BigDecimal(amount), currencyCode, null);
39 }
40
41 public Money() {
42 }
43
44 public Money(BigDecimal amount, String currencyCode, String display) {
45 this.amount = amount;
46 this.currencyCode = currencyCode;
47 this.display = display;
48 }
49
50 public BigDecimal getAmount() {
51 return amount;
52 }
53
54 public void setAmount(BigDecimal amount) {
55 this.amount = amount;
56 }
57
58 public String getCurrencyCode() {
59 return currencyCode;
60 }
61
62 public void setCurrencyCode(String currencyCode) {
63 this.currencyCode = currencyCode;
64 }
65
66 public String getDisplay() {
67 return display;
68 }
69
70 public void setDisplay(String display) {
71 this.display = display;
72 }
73
74 @Override
75 public int compareTo(Money o) {
76 return new CompareToBuilder()
77 .append(this.currencyCode, o.currencyCode)
78 .append(this.amount, o.amount)
79 .toComparison();
80 }
81
82 @Override
83 public int hashCode() {
84 return HashCodeBuilder.reflectionHashCode(this);
85 }
86
87 @Override
88 public boolean equals(Object obj) {
89 if (this == obj) {
90 return true;
91 }
92 if (!(obj instanceof Money)) {
93 return false;
94 }
95 Money rhs = (Money) obj;
96 return EqualsBuilder.reflectionEquals(this, rhs);
97 }
98
99 @Override
100 public String toString() {
101 return this.display;
102 }
103
104 }