Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 95f3dd1

Browse files
committed
Add equals() method in Product class
1 parent cd8fdbe commit 95f3dd1

File tree

1 file changed

+19
-1
lines changed
  • src/main/java/br/com/zevolution/algorithms/sorting

1 file changed

+19
-1
lines changed

src/main/java/br/com/zevolution/algorithms/sorting/Product.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,22 @@ public String toString() {
1919
return this.description;
2020
}
2121

22-
}
22+
@Override
23+
public boolean equals(Object obj) {
24+
if (obj == null)
25+
return false;
26+
27+
if (this.getClass() != obj.getClass())
28+
return false;
29+
30+
Product other = Product.class.cast(obj);
31+
return other.toString().equals(this.toString()) &&
32+
other.getPrice() == this.getPrice();
33+
}
34+
35+
@Override
36+
public int hashCode() {
37+
return super.hashCode();
38+
}
39+
40+
}

0 commit comments

Comments
 (0)