add hashCode and equals to Author and Book DTOs

This commit is contained in:
Sabiq Ihab 2017-06-24 00:31:04 +00:00
parent 3128d3fb40
commit a8f50297eb
2 changed files with 39 additions and 0 deletions

View File

@ -1,5 +1,7 @@
package com.iluwatar.cqrs.dto;
import java.util.Objects;
/**
*
* This is a DTO (Data Transfer Object) author, contains only useful information to be returned
@ -48,4 +50,22 @@ public class Author {
return "AuthorDTO [name=" + name + ", email=" + email + ", username=" + username + "]";
}
@Override
public int hashCode() {
return Objects.hash(username, name, email);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Author)) {
return false;
}
Author other = (Author) obj;
return username.equals(other.getUsername()) && email.equals(other.getEmail()) && name.equals(other.getName());
}
}

View File

@ -1,5 +1,7 @@
package com.iluwatar.cqrs.dto;
import java.util.Objects;
/**
*
* This is a DTO (Data Transfer Object) book, contains only useful information to be returned
@ -40,4 +42,21 @@ public class Book {
return "BookDTO [title=" + title + ", price=" + price + "]";
}
@Override
public int hashCode() {
return Objects.hash(title, price);
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof Book)) {
return false;
}
Book book = (Book) obj;
return title.equals(book.getTitle()) && price == book.getPrice();
}
}