|
1 | 1 | package warranty; |
2 | 2 |
|
| 3 | +import java.util.Objects; |
| 4 | + |
3 | 5 | public class LineItem { |
| 6 | + public final String type; |
4 | 7 | public final double amount; |
5 | 8 | public final String description; |
6 | 9 |
|
7 | | - public LineItem(double amount, String description) { |
8 | | - this.amount = amount; |
| 10 | + public LineItem(String type, double amount, String description) { |
| 11 | + this.type = type; |
| 12 | + this.amount = amount; |
9 | 13 | this.description = description; |
10 | 14 | } |
11 | 15 |
|
12 | 16 | @Override |
13 | | - public int hashCode() { |
14 | | - final int prime = 31; |
15 | | - int result = 1; |
16 | | - long temp; |
17 | | - temp = Double.doubleToLongBits(amount); |
18 | | - result = prime * result + (int) (temp ^ (temp >>> 32)); |
19 | | - result = prime * result |
20 | | - + ((description == null) ? 0 : description.hashCode()); |
21 | | - return result; |
| 17 | + public boolean equals(Object o) { |
| 18 | + if (this == o) return true; |
| 19 | + if (o == null || getClass() != o.getClass()) return false; |
| 20 | + LineItem lineItem = (LineItem) o; |
| 21 | + return Double.compare(lineItem.amount, amount) == 0 && Objects.equals(type, lineItem.type) && Objects.equals(description, lineItem.description); |
22 | 22 | } |
| 23 | + |
23 | 24 | @Override |
24 | | - public boolean equals(Object obj) { |
25 | | - if (this == obj) |
26 | | - return true; |
27 | | - if (obj == null) |
28 | | - return false; |
29 | | - if (getClass() != obj.getClass()) |
30 | | - return false; |
31 | | - LineItem other = (LineItem) obj; |
32 | | - if (Double.doubleToLongBits(amount) != Double |
33 | | - .doubleToLongBits(other.amount)) |
34 | | - return false; |
35 | | - if (description == null) { |
36 | | - if (other.description != null) |
37 | | - return false; |
38 | | - } else if (!description.equals(other.description)) |
39 | | - return false; |
40 | | - return true; |
| 25 | + public int hashCode() { |
| 26 | + return Objects.hash(type, amount, description); |
41 | 27 | } |
42 | | - |
43 | 28 | } |
0 commit comments