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