-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrganization.java
More file actions
169 lines (134 loc) · 4.81 KB
/
Organization.java
File metadata and controls
169 lines (134 loc) · 4.81 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
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.time.format.DateTimeFormatter;
import java.util.ArrayList;
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 Organization implements Serializable {
private static final long serialVersionUID = 1L;
private Link homePage = new Link();
private List<Period> periods = new ArrayList<>();
public Organization() {
}
public Organization(String name, String url, Period... periods) {
this(new Link(name, url), Arrays.asList(periods));
}
public Organization(String name, String url, List<Period> periods) {
this(new Link(name, url), periods);
}
public Organization(Link homePage, List<Period> periods) {
this.homePage = homePage;
this.periods = periods;
}
public Link getHomePage() {
return homePage;
}
public List<Period> getPeriods() {
return periods;
}
public void addPeriod(Period period) {
this.periods.add(period);
}
public void addPeriod(LocalDate start, LocalDate end, String title, String description) {
Period period = new Period(start, end, title, description);
this.periods.add(period);
}
@Override
public String toString() {
return homePage + "\n" + periods;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Organization that = (Organization) o;
if (!homePage.equals(that.homePage)) return false;
return periods.equals(that.periods);
}
@Override
public int hashCode() {
int result = homePage.hashCode();
result = 31 * result + periods.hashCode();
return result;
}
@XmlAccessorType(XmlAccessType.FIELD)
public static class Period implements Serializable {
private transient final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM/yyyy");
@XmlJavaTypeAdapter(LocalDateAdapter.class)
private LocalDate start;
@XmlJavaTypeAdapter(LocalDateAdapter.class)
private LocalDate end;
private String title;
private String description;
public Period() {
}
public Period(int starYear, Month startMonth, String title, String description) {
this(of(starYear, startMonth), NOW, title, description);
}
public Period(int startYear, Month startMonth, int endYear, Month endMonth, String title, String description) {
this(of(startYear, startMonth), of(endYear, endMonth), title, description);
}
public Period(LocalDate start, LocalDate end, String title, String description) {
this.start = start;
this.end = end;
this.title = title;
this.description = description;
}
public LocalDate getStart() {
return start;
}
public LocalDate getEnd() {
return end;
}
public String getFormattedStart() {
if (end == null) {
return null;
}
return start.format(formatter);
}
public String getFormattedEnd() {
if (end == null) {
return null;
}
return end.format(formatter);
}
public String getTitle() {
return title;
}
public String getDescription() {
return description;
}
@Override
public String toString() {
return "\n" + start + " - " + end + "\t" + title + "\n" + description;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Period period = (Period) o;
if (!start.equals(period.start)) return false;
if (!end.equals(period.end)) return false;
if (!title.equals(period.title)) return false;
return Objects.equals(description, period.description);
}
@Override
public int hashCode() {
int result = start.hashCode();
result = 31 * result + end.hashCode();
result = 31 * result + title.hashCode();
result = 31 * result + (description != null ? description.hashCode() : 0);
return result;
}
}
}