Kimes

Untitled

Mar 29th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. @Override
  2.     public int hashCode() {
  3.         final int prime = 31;
  4.         int result = 1;
  5.         result = prime * result + ((author == null) ? 0 : author.hashCode());
  6.         result = prime * result + ((title == null) ? 0 : title.hashCode());
  7.         result = prime * result + ((year == null) ? 0 : year.hashCode());
  8.         return result;
  9.     }
  10.  
  11.     @Override
  12.     public boolean equals(Object obj) {
  13.         if (this == obj)
  14.             return true;
  15.         if (obj == null)
  16.             return false;
  17.         if (getClass() != obj.getClass())
  18.             return false;
  19.         Book other = (Book) obj;
  20.         if (author == null) {
  21.             if (other.author != null)
  22.                 return false;
  23.         } else if (!author.equals(other.author))
  24.             return false;
  25.         if (title == null) {
  26.             if (other.title != null)
  27.                 return false;
  28.         } else if (!title.equals(other.title))
  29.             return false;
  30.         if (year == null) {
  31.             if (other.year != null)
  32.                 return false;
  33.         } else if (!year.equals(other.year))
  34.             return false;
  35.         return true;
  36.     }
Advertisement
Add Comment
Please, Sign In to add comment