Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Book implements Comparable<Book>, Cloneable {
- private String title;
- private Date publishDate;
- private String comment;
- public String getTitle() { return this.title; }
- public Date getPublishDate() { return this.publishDate; }
- public String getComment() { return this.comment; }
- public void setTitle(String title) { this.title = title; }
- public void setPublishDate(Date publishDate) { this.publishDate = publishDate; }
- public void setComment(String comment) { this.comment = comment; }
- public boolean equals(Object obj) {
- if (obj == this) return true;
- if (obj == null) return false;
- if (!(obj instanceof Book)) return false;
- Book res = (Book) obj;
- if (!this.title.equals(res.title)) return false;
- if (!this.publishDate.equals(res.publishDate)) return false;
- return true;
- }
- public int hashCode() {
- int result = 37;
- result = result * 31 + this.title.hashCode();
- result = result * 31 + this.publishDate.hashCode();
- return result;
- }
- public int compareTo(Book obj) {
- return this.publishDate.compareTo(obj.publishDate);
- }
- public Book clone() {
- Book res = new Book();
- res.title = this.title;
- res.publishDate = this.publishDate;
- res.comment = this.comment;
- return res;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement