|
3 | 3 | import com.google.gson.annotations.Expose;
|
4 | 4 | import java.time.LocalDateTime;
|
5 | 5 | import java.time.ZoneOffset;
|
| 6 | +import java.util.Objects; |
6 | 7 |
|
7 | 8 | /**
|
8 | 9 | * @author GoodforGod
|
@@ -30,54 +31,34 @@ public double inBtc() {
|
30 | 31 | }
|
31 | 32 |
|
32 | 33 | public LocalDateTime usdTimestamp() {
|
33 |
| - if (_ethusd_timestamp == null) |
| 34 | + if (_ethusd_timestamp == null && ethusd_timestamp != null) { |
34 | 35 | _ethusd_timestamp = LocalDateTime.ofEpochSecond(Long.parseLong(ethusd_timestamp), 0, ZoneOffset.UTC);
|
| 36 | + } |
35 | 37 | return _ethusd_timestamp;
|
36 | 38 | }
|
37 | 39 |
|
38 | 40 | public LocalDateTime btcTimestamp() {
|
39 |
| - if (_ethbtc_timestamp == null) |
| 41 | + if (_ethbtc_timestamp == null && ethbtc_timestamp != null) { |
40 | 42 | _ethbtc_timestamp = LocalDateTime.ofEpochSecond(Long.parseLong(ethbtc_timestamp), 0, ZoneOffset.UTC);
|
| 43 | + } |
41 | 44 | return _ethbtc_timestamp;
|
42 | 45 | }
|
43 | 46 |
|
44 | 47 | @Override
|
45 | 48 | public boolean equals(Object o) {
|
46 | 49 | if (this == o)
|
47 | 50 | return true;
|
48 |
| - if (o == null || getClass() != o.getClass()) |
| 51 | + if (!(o instanceof Price)) |
49 | 52 | return false;
|
50 |
| - |
51 | 53 | Price price = (Price) o;
|
52 |
| - |
53 |
| - if (Double.compare(price.ethusd, ethusd) != 0) |
54 |
| - return false; |
55 |
| - if (Double.compare(price.ethbtc, ethbtc) != 0) |
56 |
| - return false; |
57 |
| - if (ethusd_timestamp != null |
58 |
| - ? !ethusd_timestamp.equals(price.ethusd_timestamp) |
59 |
| - : price.ethusd_timestamp != null) |
60 |
| - return false; |
61 |
| - return (ethbtc_timestamp != null |
62 |
| - ? !ethbtc_timestamp.equals(price.ethbtc_timestamp) |
63 |
| - : price.ethbtc_timestamp != null); |
| 54 | + return Double.compare(price.ethusd, ethusd) == 0 && Double.compare(price.ethbtc, ethbtc) == 0 |
| 55 | + && Objects.equals(ethusd_timestamp, price.ethusd_timestamp) |
| 56 | + && Objects.equals(ethbtc_timestamp, price.ethbtc_timestamp); |
64 | 57 | }
|
65 | 58 |
|
66 | 59 | @Override
|
67 | 60 | public int hashCode() {
|
68 |
| - int result; |
69 |
| - long temp; |
70 |
| - temp = Double.doubleToLongBits(ethusd); |
71 |
| - result = (int) (temp ^ (temp >>> 32)); |
72 |
| - temp = Double.doubleToLongBits(ethbtc); |
73 |
| - result = 31 * result + (int) (temp ^ (temp >>> 32)); |
74 |
| - result = 31 * result + (ethusd_timestamp != null |
75 |
| - ? ethusd_timestamp.hashCode() |
76 |
| - : 0); |
77 |
| - result = 31 * result + (ethbtc_timestamp != null |
78 |
| - ? ethbtc_timestamp.hashCode() |
79 |
| - : 0); |
80 |
| - return result; |
| 61 | + return Objects.hash(ethusd, ethbtc, ethusd_timestamp, ethbtc_timestamp); |
81 | 62 | }
|
82 | 63 |
|
83 | 64 | @Override
|
@@ -126,11 +107,15 @@ public PriceBuilder withEthBtcTimestamp(LocalDateTime ethbtcTimestamp) {
|
126 | 107 | public Price build() {
|
127 | 108 | Price price = new Price();
|
128 | 109 | price.ethbtc = this.ethbtc;
|
129 |
| - price.ethbtc_timestamp = String.valueOf(this.ethbtcTimestamp.toEpochSecond(ZoneOffset.UTC)); |
130 |
| - price._ethbtc_timestamp = this.ethbtcTimestamp; |
131 | 110 | price.ethusd = this.ethusd;
|
132 |
| - price.ethusd_timestamp = String.valueOf(this.ethusdTimestamp.toEpochSecond(ZoneOffset.UTC)); |
133 |
| - price._ethusd_timestamp = this.ethusdTimestamp; |
| 111 | + if (this.ethbtcTimestamp != null) { |
| 112 | + price.ethbtc_timestamp = String.valueOf(this.ethbtcTimestamp.toEpochSecond(ZoneOffset.UTC)); |
| 113 | + price._ethbtc_timestamp = this.ethbtcTimestamp; |
| 114 | + } |
| 115 | + if (this.ethusdTimestamp != null) { |
| 116 | + price.ethusd_timestamp = String.valueOf(this.ethusdTimestamp.toEpochSecond(ZoneOffset.UTC)); |
| 117 | + price._ethusd_timestamp = this.ethusdTimestamp; |
| 118 | + } |
134 | 119 | return price;
|
135 | 120 | }
|
136 | 121 | }
|
|
0 commit comments