1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sourceforge.jhunters.pool.data;
18
19 import java.io.File;
20 import java.time.LocalDate;
21 import java.util.Iterator;
22
23 import javafx.beans.property.ObjectProperty;
24 import javafx.beans.property.SimpleObjectProperty;
25 import net.sourceforge.jhunters.pool.PoolStatus;
26
27
28
29
30 public class DataSet {
31
32
33
34 protected static final String OBJECT_NAME = "HuntersPool";
35
36
37
38
39 protected static final int HASH_PRIME = 47;
40
41
42
43
44 private static final String FIELD_UPDATED = "Updated";
45
46
47
48
49 private static final String FIELD_CHANGED = "LastChange";
50
51
52
53
54 private static final String FIELD_FILENAME = "FileName";
55
56
57
58
59 private final ObjectProperty<Boolean> theUpdated;
60
61
62
63
64 private final ObjectProperty<LocalDate> theLastChange;
65
66
67
68
69 private final ObjectProperty<File> theFileName;
70
71
72
73
74 private final PlayerList thePlayers;
75
76
77
78
79 private final CompetitionList theCompetitions;
80
81
82
83
84 private PoolStatus theStatus;
85
86
87
88
89 public DataSet() {
90 theUpdated = new SimpleObjectProperty<Boolean>(this, FIELD_UPDATED, Boolean.FALSE);
91 theLastChange = new SimpleObjectProperty<LocalDate>(this, FIELD_CHANGED);
92 theFileName = new SimpleObjectProperty<File>(this, FIELD_FILENAME);
93 thePlayers = new PlayerList();
94 theCompetitions = new CompetitionList();
95 }
96
97
98
99
100
101 public ObjectProperty<Boolean> updatedProperty() {
102 return theUpdated;
103 }
104
105
106
107
108
109 public ObjectProperty<LocalDate> lastChangeProperty() {
110 return theLastChange;
111 }
112
113
114
115
116
117 public ObjectProperty<File> fileNameProperty() {
118 return theFileName;
119 }
120
121
122
123
124
125 public Boolean isUpdated() {
126 return theUpdated.getValue();
127 }
128
129
130
131
132
133 public LocalDate getLastChange() {
134 return theLastChange.getValue();
135 }
136
137
138
139
140
141 public File getFileName() {
142 return theFileName.getValue();
143 }
144
145
146
147
148
149 public void setUpdated(final Boolean pUpdated) {
150 theUpdated.setValue(pUpdated);
151 }
152
153
154
155
156
157 public void setLastChange(final LocalDate pDate) {
158 theLastChange.setValue(pDate);
159 }
160
161
162
163
164
165 public void setFileName(final File pFile) {
166 theFileName.setValue(pFile);
167 }
168
169
170
171
172
173 public PlayerList getPlayers() {
174 return thePlayers;
175 }
176
177
178
179
180
181 public CompetitionList getCompetitions() {
182 return theCompetitions;
183 }
184
185
186
187
188
189 public PoolStatus getStatus() {
190 return theStatus;
191 }
192
193
194
195
196
197 public Iterator<Player> playerIterator() {
198 return thePlayers.playerIterator();
199 }
200
201
202
203
204
205 public Iterator<Competition> competitionIterator() {
206 return theCompetitions.competitionIterator();
207 }
208
209
210
211
212
213 protected void setPlayers(final PlayerList pSource) {
214
215 thePlayers.setPlayers(pSource.playerIterator());
216 }
217
218
219
220
221
222 protected void setCompetitions(final CompetitionList pSource) {
223
224 theCompetitions.setCompetitions(pSource.competitionIterator());
225 }
226
227
228
229
230 public void adjustPlayers() {
231
232 theCompetitions.adjustPlayers();
233 }
234
235 @Override
236 public boolean equals(final Object pThat) {
237
238 if (this == pThat) {
239 return true;
240 }
241 if (pThat == null) {
242 return false;
243 }
244
245
246 if (!(pThat instanceof DataSet)) {
247 return false;
248 }
249
250
251 DataSet myThat = (DataSet) pThat;
252
253
254 if (!thePlayers.equals(myThat.getPlayers())) {
255 return false;
256 }
257
258
259 return theCompetitions.equals(myThat.getCompetitions());
260 }
261
262 @Override
263 public int hashCode() {
264 return (thePlayers.hashCode() * HASH_PRIME)
265 + theCompetitions.hashCode();
266 }
267
268
269
270
271
272 protected PoolStatus validate() {
273
274 theStatus = thePlayers.validate();
275
276
277 if (theStatus.isValid()) {
278
279 thePlayers.setActive(Boolean.FALSE);
280
281
282 theStatus = theCompetitions.validate();
283 }
284
285
286 return theStatus;
287 }
288
289
290
291
292
293
294
295
296 protected static <T> boolean isEqual(final T pFirst,
297 final T pSecond) {
298 if (pFirst == null) {
299 return pSecond == null;
300 }
301 return (pSecond == null)
302 ? false
303 : pFirst.equals(pSecond);
304 }
305 }