diff --git a/src/main/java/com/epam/izh/rd/online/entity/Author.java b/src/main/java/com/epam/izh/rd/online/entity/Author.java index 166be587..e9531feb 100644 --- a/src/main/java/com/epam/izh/rd/online/entity/Author.java +++ b/src/main/java/com/epam/izh/rd/online/entity/Author.java @@ -19,5 +19,73 @@ * 6) Переопределить метод toString с выводом всех полей (не забывайте alt+inset) */ public class Author { +private String name; +private String lastName; +private LocalDate birthdate; +private String country; + public Author() { + } + + public Author(String name, String lastName, LocalDate birthdate, String country) { + this.name = name; + this.lastName = lastName; + this.birthdate = birthdate; + this.country = country; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public void setLastName(String lastName) { + this.lastName = lastName; + } + + public String getLastName() { + return lastName; + } + + public void setBirthdate(LocalDate birthdate) { + this.birthdate = birthdate; + } + + public LocalDate getBirthdate() { + return birthdate; + } + + public void setCountry(String country) { + this.country = country; + } + + public String getCountry() { + return country; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Author)) return false; + Author author = (Author) o; + return Objects.equals(getName(), author.getName()) && Objects.equals(getLastName(), author.getLastName()) && Objects.equals(getBirthdate(), author.getBirthdate()) && Objects.equals(getCountry(), author.getCountry()); + } + + @Override + public int hashCode() { + return Objects.hash(getName(), getLastName(), getBirthdate(), getCountry()); + } + + @Override + public String toString() { + return "Author{" + + "name='" + name + '\'' + + ", lastName='" + lastName + '\'' + + ", birthDate=" + birthdate + + ", country='" + country + '\'' + + '}'; + } } diff --git a/src/main/java/com/epam/izh/rd/online/entity/Book.java b/src/main/java/com/epam/izh/rd/online/entity/Book.java index 08bdccb8..b03f6d13 100644 --- a/src/main/java/com/epam/izh/rd/online/entity/Book.java +++ b/src/main/java/com/epam/izh/rd/online/entity/Book.java @@ -17,4 +17,51 @@ */ public abstract class Book { + private int numberOfPages; + private String name; + + public Book() { + } + + public Book(int numberOfPages, String name) { + this.numberOfPages = numberOfPages; + this.name = name; + } + + public void setNumberOfPages(int numberOfPages) { + this.numberOfPages = numberOfPages; + } + + public int getNumberOfPages() { + return numberOfPages; + } + + public void setName(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof Book)) return false; + Book book = (Book) o; + return getNumberOfPages() == book.getNumberOfPages() && Objects.equals(getName(), book.getName()); + } + + @Override + public int hashCode() { + return Objects.hash(getNumberOfPages(), getName()); + } + + @Override + public String toString() { + return "Book{" + + "numberOfPages=" + numberOfPages + + ", name='" + name + '\'' + + '}'; + } } diff --git a/src/main/java/com/epam/izh/rd/online/entity/SchoolBook.java b/src/main/java/com/epam/izh/rd/online/entity/SchoolBook.java index a9834db4..fcf725c8 100644 --- a/src/main/java/com/epam/izh/rd/online/entity/SchoolBook.java +++ b/src/main/java/com/epam/izh/rd/online/entity/SchoolBook.java @@ -20,5 +20,64 @@ * 6) Переопределить метод toString с выводом всех полей (не забывайте alt+inset) */ public class SchoolBook extends Book { +private String authorName; +private String authorLastName; +private LocalDate publishDate; + public SchoolBook() { + } + + public SchoolBook(int numberOfPages, String name, String authorName, String authorLastName, LocalDate publishDate) { + super(numberOfPages, name); + this.authorName = authorName; + this.authorLastName = authorLastName; + this.publishDate = publishDate; + } + + public void setAuthorName(String authorName) { + this.authorName = authorName; + } + + public String getAuthorName() { + return authorName; + } + + public void setAuthorLastName(String authorLastName) { + this.authorLastName = authorLastName; + } + + public String getAuthorLastName() { + return authorLastName; + } + + public void setPublishDate(LocalDate publishDate) { + this.publishDate = publishDate; + } + + public LocalDate getPublishDate() { + return publishDate; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (!(o instanceof SchoolBook)) return false; + if (!super.equals(o)) return false; + SchoolBook that = (SchoolBook) o; + return getAuthorName().equals(that.getAuthorName()) && getAuthorLastName().equals(that.getAuthorLastName()) && getPublishDate().equals(that.getPublishDate()); + } + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), getAuthorName(), getAuthorLastName(), getPublishDate()); + } + + @Override + public String toString() { + return "SchoolBook{" + + "authorName='" + authorName + '\'' + + ", authorLastName='" + authorLastName + '\'' + + ", publishDate=" + publishDate + + '}'; + } } diff --git a/src/main/java/com/epam/izh/rd/online/repository/AuthorRepository.java b/src/main/java/com/epam/izh/rd/online/repository/AuthorRepository.java index c62bd4e9..d1c16332 100644 --- a/src/main/java/com/epam/izh/rd/online/repository/AuthorRepository.java +++ b/src/main/java/com/epam/izh/rd/online/repository/AuthorRepository.java @@ -57,3 +57,4 @@ public interface AuthorRepository { */ int count(); } +