Skip to content

Commit f5f75c5

Browse files
adding equals, hash, and toString
1 parent 587d5eb commit f5f75c5

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/main/java/guru/springframework/spring5webapp/model/Publisher.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,28 @@ public String getAddress() {
4040
public void setAddress(String address) {
4141
this.address = address;
4242
}
43+
44+
@Override
45+
public boolean equals(Object o) {
46+
if (this == o) return true;
47+
if (o == null || getClass() != o.getClass()) return false;
48+
49+
Publisher publisher = (Publisher) o;
50+
51+
return id != null ? id.equals(publisher.id) : publisher.id == null;
52+
}
53+
54+
@Override
55+
public int hashCode() {
56+
return id != null ? id.hashCode() : 0;
57+
}
58+
59+
@Override
60+
public String toString() {
61+
return "Publisher{" +
62+
"id=" + id +
63+
", name='" + name + '\'' +
64+
", address='" + address + '\'' +
65+
'}';
66+
}
4367
}

0 commit comments

Comments
 (0)