Java Reference
In-Depth Information
private final String title;
private final String author;
private final Genre genre;
/**
* Constructor.
*
* @param title The title of the topic; may not be {@code null}.
* @param author The author of the topic; may not be {@code null}.
* @param genre The genre of the topic; may not be {@code null}.
*/
public Book(final String title, final String author, final Genre genre) {
Objects.requireNonNull(title, "title of the book");
this.title = title;
Objects.requireNonNull(author, "author of the book");
this.author = author;
Objects.requireNonNull(genre, "genre of the book");
this.genre = genre;
}
@Override
public String toString() {
return "\"" + title + "\" by " + author +
" (" + genre.toString().toLowerCase() + ")";
}
@Override
public int hashCode() {
int result = title.hashCode();
result = 17 * result + author.hashCode();
result = 31 * result + genre.hashCode();
return result;
}
@Override
public boolean equals(final Object o) {
if (o == null) return false;
if (this == o) return true;
if (!(o instanceof Book)) return false;
final Book book = (Book) o;
if (!author.equals(book.author)) return false;
if (genre != book.genre) return false;
if (!title.equals(book.title)) return false;
return true;
}
}
Search WWH ::




Custom Search