forked from JavaOPs/basejava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrganization.java
More file actions
163 lines (132 loc) · 5.05 KB
/
Organization.java
File metadata and controls
163 lines (132 loc) · 5.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
package com.urise.webapp.model;
import com.urise.webapp.util.DateUtil;
import com.urise.webapp.util.LocalDateAdapter;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import java.io.Serializable;
import java.time.LocalDate;
import java.time.Month;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import static com.urise.webapp.util.DateUtil.NOW;
@XmlAccessorType(XmlAccessType.FIELD)
public class Organization implements Serializable {
private Link homePage;
private List<Position> positions = new ArrayList<>();
public Organization() {
}
public Organization(String name, String url, Position... positions) {
this(new Link(name, url), Arrays.asList(positions));
}
public Organization(String name, String url, List<Position> positions) {
this(new Link(name, url), positions);
}
public Organization(Link homePage, List<Position> positions) {
this.homePage = homePage;
this.positions = positions;
}
@Override
public String toString() {
return "Organization(" + homePage + positions + ')';
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Organization that = (Organization) o;
return Objects.equals(homePage, that.homePage) &&
Objects.equals(positions, that.positions);
}
@Override
public int hashCode() {
int result = homePage != null ? homePage.hashCode() : 0;
result = 31 * result + (positions != null ? positions.hashCode() : 0);
return result;
}
public Link getHomePage() {
return homePage;
}
public List<Position> getPositions() {
return positions;
}
@XmlAccessorType(XmlAccessType.FIELD)
public static class Position implements Serializable {
@XmlJavaTypeAdapter(LocalDateAdapter.class)
private LocalDate startDate;
@XmlJavaTypeAdapter(LocalDateAdapter.class)
private LocalDate endDate;
private String title;
private String description;
public Position(int startYear, Month startMonth, String title, String description) {
this(DateUtil.of(startYear, startMonth), NOW, title, description);
}
public Position(int startYear, Month startMonth, int endYear, Month endMonth, String title, String description) {
this(DateUtil.of(startYear, startMonth), DateUtil.of(endYear, endMonth), title, description);
}
public Position() {
}
public Position(LocalDate startDate, LocalDate endDate, String title, String description) {
Objects.requireNonNull(startDate, "startDate must not be null");
Objects.requireNonNull(endDate, "endDate must not be null");
Objects.requireNonNull(title, "title must not be null");
this.startDate = startDate;
this.endDate = endDate;
this.title = title;
this.description = description==null?"":description;
}
public void setStartDate(LocalDate startDate) {
this.startDate = startDate;
}
public void setEndDate(LocalDate endDate) {
this.endDate = endDate;
}
public void setTitle(String title) {
this.title = title;
}
public void setDescription(String description) {
this.description = description;
}
public LocalDate getStartDate() {
return startDate;
}
public LocalDate getEndDate() {
return endDate;
}
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Position position = (Position) o;
if (!startDate.equals(position.startDate)) return false;
if (!endDate.equals(position.endDate)) return false;
if (!title.equals(position.title)) return false;
return description != null ? description.equals(position.description) : position.description == null;
}
@Override
public int hashCode() {
int result = startDate.hashCode();
result = 31 * result + endDate.hashCode();
result = 31 * result + title.hashCode();
result = 31 * result + (description != null ? description.hashCode() : 0);
return result;
}
@Override
public String toString() {
return "Position{" +
"startDate=" + startDate +
", endDate=" + endDate +
", title='" + title + '\'' +
", description='" + description + '\'' +
'}';
}
}
}