forked from JavaOPs/basejava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrganisation.java
More file actions
153 lines (124 loc) · 4.66 KB
/
Organisation.java
File metadata and controls
153 lines (124 loc) · 4.66 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
package ru.javaops.webapp.model;
import ru.javaops.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.Arrays;
import java.util.List;
import java.util.Objects;
import static ru.javaops.webapp.util.DateUtil.NOW;
import static ru.javaops.webapp.util.DateUtil.of;
@XmlAccessorType(XmlAccessType.FIELD)
public class Organisation implements Serializable {
private static final long serialVersionUID = 1L;
public static final Organisation EMPTY = new Organisation("", "", Position.EMPTY);
private String name;
private String url;
private List<Position> positions;
public Organisation() {
}
public Organisation(String name, String url, Position... positions){
this(name, url, Arrays.asList(positions));
}
public Organisation(String name, String url, List<Position> positions){
Objects.requireNonNull(name, "name can't be NULL");
this.name = name;
this.url = url == null ? "" : url;
this.positions = positions;
}
public String getName() {
return name;
}
public String getUrl() {
return url;
}
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;
Organisation that = (Organisation) o;
return Objects.equals(name, that.name) &&
Objects.equals(url, that.url) &&
Objects.equals(positions, that.positions);
}
@Override
public int hashCode() {
return Objects.hash(name, url, positions);
}
@Override
public String toString() {
return "Organisation: " + name + " (" + url + ", " + positions + ")";
// return "Organisation{" +
// "name='" + name + '\'' +
// ", url='" + url + '\'' +
// ", positions=" + positions +
// '}';
}
@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 head;
private String description;
public Position() {
}
public Position(int startYear, Month startMonth, String head, String description) {
this(of(startYear, startMonth), NOW, head, description);
}
public Position(int startYear, Month startMonth, int endYear, Month endMonth, String head, String description) {
this(of(startYear, startMonth), of(endYear, endMonth), head, description);
}
public Position(LocalDate startDate, LocalDate endDate, String head, String description) {
Objects.requireNonNull(startDate, "startDate can't be NULL");
Objects.requireNonNull(head, "head can't be NULL");
this.startDate = startDate;
this.endDate = endDate;
this.head = head;
this.description = description == null ? "" : description;
}
public LocalDate getStartDate() {
return startDate;
}
public LocalDate getEndDate() {
return endDate;
}
public String getHead() {
return head;
}
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;
return Objects.equals(startDate, position.startDate) &&
Objects.equals(endDate, position.endDate) &&
Objects.equals(head, position.head) &&
Objects.equals(description, position.description);
}
@Override
public int hashCode() {
return Objects.hash(startDate, endDate, head, description);
}
@Override
public String toString() {
return "Position: " +
"startDate=" + startDate +
", endDate=" + endDate +
", head='" + head + '\'' +
", description='" + description + '\'';
}
}
}