Advertisement
Guest User

Untitled

a guest
Nov 30th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class Book implements Comparable<Book>, Cloneable {
  4. private String title;
  5. private Date publishDate;
  6. private String comment;
  7.  
  8. public String getTitle() { return this.title; }
  9. public Date getPublishDate() { return this.publishDate; }
  10. public String getComment() { return this.comment; }
  11.  
  12. public void setTitle(String title) { this.title = title; }
  13. public void setPublishDate(Date publishDate) { this.publishDate = publishDate; }
  14. public void setComment(String comment) { this.comment = comment; }
  15.  
  16. public boolean equals(Object obj) {
  17. if (obj == this) return true;
  18. if (obj == null) return false;
  19. if (!(obj instanceof Book)) return false;
  20. Book res = (Book) obj;
  21. if (!this.title.equals(res.title)) return false;
  22. if (!this.publishDate.equals(res.publishDate)) return false;
  23. return true;
  24. }
  25.  
  26. public int hashCode() {
  27. int result = 37;
  28. result = result * 31 + this.title.hashCode();
  29. result = result * 31 + this.publishDate.hashCode();
  30. return result;
  31. }
  32.  
  33. public int compareTo(Book obj) {
  34. return this.publishDate.compareTo(obj.publishDate);
  35. }
  36.  
  37. public Book clone() {
  38. Book res = new Book();
  39. res.title = this.title;
  40. res.publishDate = this.publishDate;
  41. res.comment = this.comment;
  42. return res;
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement