|
| 1 | +package org.gluecoders.library.models; |
| 2 | + |
| 3 | +import java.io.Serializable; |
| 4 | +import java.util.Arrays; |
| 5 | +import java.util.List; |
| 6 | + |
| 7 | +/** |
| 8 | + * Created by Anand_Rajneesh on 6/10/2017. |
| 9 | + */ |
| 10 | +public class Book implements Serializable { |
| 11 | + |
| 12 | + private String title; |
| 13 | + private String author; |
| 14 | + private int publishedYear; |
| 15 | + private List<String> categories; |
| 16 | + private String publisher; |
| 17 | + private long isbnCode; |
| 18 | + |
| 19 | + public Book() { |
| 20 | + } |
| 21 | + |
| 22 | + public String getTitle() { |
| 23 | + return title; |
| 24 | + } |
| 25 | + |
| 26 | + public void setTitle(String title) { |
| 27 | + this.title = title; |
| 28 | + } |
| 29 | + |
| 30 | + public String getAuthor() { |
| 31 | + return author; |
| 32 | + } |
| 33 | + |
| 34 | + public void setAuthor(String author) { |
| 35 | + this.author = author; |
| 36 | + } |
| 37 | + |
| 38 | + public List<String> getCategories() { |
| 39 | + return categories; |
| 40 | + } |
| 41 | + |
| 42 | + public void setCategories(List<String> categories) { |
| 43 | + this.categories = categories; |
| 44 | + } |
| 45 | + |
| 46 | + public String getPublisher() { |
| 47 | + return publisher; |
| 48 | + } |
| 49 | + |
| 50 | + public void setPublisher(String publisher) { |
| 51 | + this.publisher = publisher; |
| 52 | + } |
| 53 | + |
| 54 | + public long getIsbnCode() { |
| 55 | + return isbnCode; |
| 56 | + } |
| 57 | + |
| 58 | + public void setIsbnCode(long isbnCode) { |
| 59 | + this.isbnCode = isbnCode; |
| 60 | + } |
| 61 | + |
| 62 | + public int getPublishedYear() { |
| 63 | + return publishedYear; |
| 64 | + } |
| 65 | + |
| 66 | + public void setPublishedYear(int publishedYear) { |
| 67 | + this.publishedYear = publishedYear; |
| 68 | + } |
| 69 | + |
| 70 | + @Override |
| 71 | + public boolean equals(Object obj) { |
| 72 | + return obj != null && obj instanceof Book && Long.compare(isbnCode, ((Book) obj).getIsbnCode()) == 0; |
| 73 | + } |
| 74 | + |
| 75 | + @Override |
| 76 | + public int hashCode() { |
| 77 | + return Long.hashCode(isbnCode); |
| 78 | + } |
| 79 | + |
| 80 | + public static Builder builder(){ |
| 81 | + return new Builder(); |
| 82 | + } |
| 83 | + |
| 84 | + public static class Builder{ |
| 85 | + |
| 86 | + private Book book = new Book(); |
| 87 | + |
| 88 | + public Builder title(String title){ |
| 89 | + book.setTitle(title); |
| 90 | + return this; |
| 91 | + } |
| 92 | + |
| 93 | + public Builder author(String author){ |
| 94 | + book.setAuthor(author); |
| 95 | + return this; |
| 96 | + } |
| 97 | + |
| 98 | + public Builder isbn(long isbnCode){ |
| 99 | + book.setIsbnCode(isbnCode); |
| 100 | + return this; |
| 101 | + } |
| 102 | + |
| 103 | + public Builder yearOfPublishing(int year){ |
| 104 | + book.setPublishedYear(year); |
| 105 | + return this; |
| 106 | + } |
| 107 | + |
| 108 | + public Builder categories(String ... category){ |
| 109 | + book.setCategories(Arrays.asList(category)); |
| 110 | + return this; |
| 111 | + } |
| 112 | + |
| 113 | + public Builder publisher(String publisher){ |
| 114 | + book.setPublisher(publisher); |
| 115 | + return this; |
| 116 | + } |
| 117 | + |
| 118 | + public Book build(){ |
| 119 | + return this.book; |
| 120 | + } |
| 121 | + } |
| 122 | +} |
0 commit comments