Repository navigation
Expand file tree
/
Copy pathOrganization.java
More file actions
208 lines (166 loc) · 5.97 KB
/
Copy pathOrganization.java
File metadata and controls
208 lines (166 loc) · 5.97 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package com.javaops.model;
import com.javaops.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.javaops.util.DateUtil.NOW;
import static com.javaops.util.DateUtil.of;
/**
* @author Vasichkin Pavel
*/
@XmlAccessorType(XmlAccessType.FIELD)
public class Organization implements Serializable {
private static final long serialVersionUID = 1L;
public static final Organization EMPTY = new Organization("", "", Position.EMPTY);
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(Link homePage, List<Position> positions) {
Objects.requireNonNull(positions, "positions must not be null");
this.homePage = homePage;
this.positions = positions;
}
public Link getHomePage() {
return homePage;
}
public List<Position> getPositions() {
return 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) && positions.equals(that.positions);
}
@Override
public int hashCode() {
return Objects.hash(homePage, positions);
}
@Override
public String toString() {
return "Organization{" + "homePage=" + homePage + ", positions=" + positions + '}';
}
/**
* @author Vasichkin Pavel
*/
@XmlAccessorType(XmlAccessType.FIELD)
public static class Position implements Serializable {
private static final long serialVersionUID = 1L;
public static final Position EMPTY = new Position();
@XmlJavaTypeAdapter(LocalDateAdapter.class)
private LocalDate startDate;
@XmlJavaTypeAdapter(LocalDateAdapter.class)
private LocalDate endDate;
private String title;
private String description;
public Position() {
}
public Position(int startYear, Month startMonth, String title, String description) {
this(of(startYear, startMonth), NOW, title, description);
}
public Position(int startYear, Month startMonth, int endYear, Month endMonth, String title, String description) {
this(of(startYear, startMonth), of(endYear, endMonth), title, description);
}
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 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 that = (Position) o;
return startDate.equals(that.startDate) && endDate.equals(that.endDate) && title.equals(that.title) && Objects.equals(description, that.description);
}
@Override
public int hashCode() {
return Objects.hash(startDate, endDate, title, description);
}
@Override
public String toString() {
return "Position{" + "startDate=" + startDate + ", endDate=" + endDate + ", title='" + title + '\'' + ", description='" + description + '\'' + '}';
}
}
/**
* @author Vasichkin Pavel
*/
@XmlAccessorType(XmlAccessType.FIELD)
public static class Link implements Serializable {
private static final long serialVersionUID = 1L;
private String name;
private String url;
public Link() {
}
public Link(String name, String url) {
Objects.requireNonNull(name, "name must not be null");
this.name = name;
this.url = url == null ? "" : url;
}
public String getName() {
return name;
}
public String getUrl() {
return url;
}
@Override
public String toString() {
return "Link(" + name + ',' + url + ')';
}
public String toHtml() {
return (url == null) ? toLink("", name) : toLink(url, name);
}
public String toLink(String href, String name) {
return "<a href='" + href + "'>" + name + "</a>";
}
@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
Link link = (Link) o;
if (!name.equals(link.name))
return false;
return url != null ? url.equals(link.url) : link.url == null;
}
@Override
public int hashCode() {
int result = name.hashCode();
result = 31 * result + (url != null ? url.hashCode() : 0);
return result;
}
}
}