|
| 1 | +package ru.javawebinar.basejava.model; |
| 2 | + |
| 3 | +import java.time.LocalDate; |
| 4 | +import java.util.Objects; |
| 5 | + |
| 6 | +/** |
| 7 | + * gkislin |
| 8 | + * 19.07.2016 |
| 9 | + */ |
| 10 | +public class Organization { |
| 11 | + private final Link homePage; |
| 12 | + |
| 13 | + private final LocalDate startDate; |
| 14 | + private final LocalDate endDate; |
| 15 | + private final String title; |
| 16 | + private final String description; |
| 17 | + |
| 18 | + public Organization(String name, String url, LocalDate startDate, LocalDate endDate, String title, String description) { |
| 19 | + Objects.requireNonNull(startDate, "startDate must not be null"); |
| 20 | + Objects.requireNonNull(endDate, "endDate must not be null"); |
| 21 | + Objects.requireNonNull(title, "title must not be null"); |
| 22 | + this.homePage = new Link(name, url); |
| 23 | + this.startDate = startDate; |
| 24 | + this.endDate = endDate; |
| 25 | + this.title = title; |
| 26 | + this.description = description; |
| 27 | + } |
| 28 | + |
| 29 | + @Override |
| 30 | + public boolean equals(Object o) { |
| 31 | + if (this == o) return true; |
| 32 | + if (o == null || getClass() != o.getClass()) return false; |
| 33 | + |
| 34 | + Organization that = (Organization) o; |
| 35 | + |
| 36 | + if (!homePage.equals(that.homePage)) return false; |
| 37 | + if (!startDate.equals(that.startDate)) return false; |
| 38 | + if (!endDate.equals(that.endDate)) return false; |
| 39 | + if (!title.equals(that.title)) return false; |
| 40 | + return description != null ? description.equals(that.description) : that.description == null; |
| 41 | + |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + public int hashCode() { |
| 46 | + int result = homePage.hashCode(); |
| 47 | + result = 31 * result + startDate.hashCode(); |
| 48 | + result = 31 * result + endDate.hashCode(); |
| 49 | + result = 31 * result + title.hashCode(); |
| 50 | + result = 31 * result + (description != null ? description.hashCode() : 0); |
| 51 | + return result; |
| 52 | + } |
| 53 | + |
| 54 | + @Override |
| 55 | + public String toString() { |
| 56 | + return "Organization{" + |
| 57 | + "homePage=" + homePage + |
| 58 | + ", startDate=" + startDate + |
| 59 | + ", endDate=" + endDate + |
| 60 | + ", title='" + title + '\'' + |
| 61 | + ", description='" + description + '\'' + |
| 62 | + '}'; |
| 63 | + } |
| 64 | +} |
0 commit comments