1 |
cbd6adb3
|
Daniel Stuš
|
package data;
|
2 |
|
|
|
3 |
17168608
|
Daniel Stuš
|
import java.time.DayOfWeek;
|
4 |
cbd6adb3
|
Daniel Stuš
|
import java.time.LocalDate;
|
5 |
17168608
|
Daniel Stuš
|
import java.time.Month;
|
6 |
cbd6adb3
|
Daniel Stuš
|
import java.time.temporal.ChronoUnit;
|
7 |
17168608
|
Daniel Stuš
|
import java.time.temporal.WeekFields;
|
8 |
cbd6adb3
|
Daniel Stuš
|
import java.util.Arrays;
|
9 |
17168608
|
Daniel Stuš
|
import java.util.Locale;
|
10 |
27ba3ec6
|
Daniel Stuš
|
import java.util.Objects;
|
11 |
cbd6adb3
|
Daniel Stuš
|
|
12 |
|
|
/**
|
13 |
|
|
*
|
14 |
|
|
* Trida uchovavajici informace a umoznujici praci s bitmapou
|
15 |
|
|
*
|
16 |
|
|
* @author Daniel Stus, Marek Sobota, Lukas Scurko, Jan Jirman
|
17 |
17168608
|
Daniel Stuš
|
* @version 1.0
|
18 |
cbd6adb3
|
Daniel Stuš
|
*
|
19 |
|
|
*/
|
20 |
27ba3ec6
|
Daniel Stuš
|
public class Bitmap implements Comparable<Bitmap>{
|
21 |
cbd6adb3
|
Daniel Stuš
|
|
22 |
|
|
//-------------- Atributy --------------/
|
23 |
|
|
|
24 |
|
|
/** Atribut - Datum zacatku obdobi */
|
25 |
17168608
|
Daniel Stuš
|
private LocalDate dateFrom;
|
26 |
cbd6adb3
|
Daniel Stuš
|
|
27 |
|
|
/** Atribut - Datum konce obdobi */
|
28 |
17168608
|
Daniel Stuš
|
private LocalDate dateTo;
|
29 |
cbd6adb3
|
Daniel Stuš
|
|
30 |
|
|
/** Atribut s cislem linky pro kterou je generovana bitmapa */
|
31 |
|
|
private String lineNumber;
|
32 |
|
|
|
33 |
17168608
|
Daniel Stuš
|
/** Atribut s cislem spoje pro kterou je generovana bitmapa */
|
34 |
|
|
private String joinNumber;
|
35 |
|
|
|
36 |
|
|
/** Atribut s verzi linky */
|
37 |
|
|
private String lineVersion;
|
38 |
|
|
|
39 |
|
|
/** Atribut s casovym kodem */
|
40 |
|
|
private String timeCode;
|
41 |
|
|
|
42 |
|
|
/** List uchovavajici seznam pevnych kodu pro spoj */
|
43 |
|
|
private String hardCodes;
|
44 |
|
|
|
45 |
cbd6adb3
|
Daniel Stuš
|
/** Pole uchovavajici bitmapu */
|
46 |
|
|
private int[] bitmap;
|
47 |
|
|
|
48 |
17168608
|
Daniel Stuš
|
/** Aktualni dny velikonocnich svatku */
|
49 |
|
|
private LocalDate goodFriday, easterMonday;
|
50 |
7cafefe1
|
Daniel Stuš
|
|
51 |
cbd6adb3
|
Daniel Stuš
|
|
52 |
|
|
|
53 |
|
|
//-------------- Konstruktor -------------/
|
54 |
|
|
|
55 |
|
|
/**
|
56 |
|
|
* Konstruktor incializuje a nastavuje důležité parametry tridy (@code Bitmap)
|
57 |
|
|
*
|
58 |
|
|
* @param dateFrom Datum zacatku obdobi
|
59 |
|
|
* @param dateTo Datum konce obdobi
|
60 |
|
|
* @param lineNumber Cislo linky
|
61 |
17168608
|
Daniel Stuš
|
* @param joinNumber Cislo spoje
|
62 |
|
|
* @param timeCode Casovy kod bitmapy
|
63 |
|
|
* @param hardCodes Retezec s pevnymi kody bitmapy
|
64 |
|
|
* @param lineVersion Verze linky
|
65 |
cbd6adb3
|
Daniel Stuš
|
*/
|
66 |
17168608
|
Daniel Stuš
|
public Bitmap(LocalDate dateFrom, LocalDate dateTo, String lineNumber, String joinNumber, String timeCode, String hardCodes, String lineVersion) {
|
67 |
cbd6adb3
|
Daniel Stuš
|
this.dateFrom = dateFrom;
|
68 |
|
|
this.dateTo = dateTo;
|
69 |
|
|
this.lineNumber = lineNumber;
|
70 |
17168608
|
Daniel Stuš
|
this.joinNumber = joinNumber;
|
71 |
|
|
this.timeCode = timeCode;
|
72 |
|
|
this.hardCodes = hardCodes;
|
73 |
|
|
this.lineVersion = lineVersion;
|
74 |
cbd6adb3
|
Daniel Stuš
|
this.bitmap = new int[(int) getDateRange()];
|
75 |
17168608
|
Daniel Stuš
|
getEasterHolidays(dateFrom.getYear());
|
76 |
cbd6adb3
|
Daniel Stuš
|
}
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
//----------------- Metody ----------------/
|
80 |
|
|
|
81 |
|
|
/**
|
82 |
17168608
|
Daniel Stuš
|
* Metoda vraci pocet dni uzivatelem zvoleneho obdobi
|
83 |
cbd6adb3
|
Daniel Stuš
|
*
|
84 |
17168608
|
Daniel Stuš
|
* @return Pocet dni v uzivatelem zvolenem obdobi (rozmezi)
|
85 |
cbd6adb3
|
Daniel Stuš
|
*/
|
86 |
|
|
public long getDateRange() {
|
87 |
17168608
|
Daniel Stuš
|
LocalDate from = this.dateFrom;
|
88 |
|
|
LocalDate to = this.dateTo;
|
89 |
cbd6adb3
|
Daniel Stuš
|
|
90 |
|
|
long noOfDaysBetween = ChronoUnit.DAYS.between(from, to);
|
91 |
|
|
return noOfDaysBetween+1;
|
92 |
|
|
}
|
93 |
|
|
|
94 |
17168608
|
Daniel Stuš
|
/**
|
95 |
|
|
* Metoda vraci pozici dne v bitmape
|
96 |
|
|
*
|
97 |
|
|
* @param date Den pro ktery pozadujeme vratit pozici
|
98 |
|
|
* @return Pozice zadaneho dne v bitmape
|
99 |
|
|
*/
|
100 |
|
|
public long getDatePosition(LocalDate date) {
|
101 |
|
|
LocalDate from = this.dateFrom;
|
102 |
cbd6adb3
|
Daniel Stuš
|
|
103 |
de8ed2a2
|
Jan Jirman
|
//Re #7443
|
104 |
17168608
|
Daniel Stuš
|
return ChronoUnit.DAYS.between(from, date);
|
105 |
cbd6adb3
|
Daniel Stuš
|
}
|
106 |
|
|
|
107 |
|
|
|
108 |
17168608
|
Daniel Stuš
|
/**
|
109 |
|
|
* Metoda nastavy pracovni dny bitmapy na hodnotu parametru {@code value}
|
110 |
|
|
*
|
111 |
|
|
* @param value hodnota na kterou se maji dny v bitmape nastavit
|
112 |
|
|
*/
|
113 |
cbd6adb3
|
Daniel Stuš
|
public void setWorkdays(int value) {
|
114 |
|
|
value = validateValue(value);
|
115 |
17168608
|
Daniel Stuš
|
LocalDate currentDay = this.dateFrom;
|
116 |
cbd6adb3
|
Daniel Stuš
|
|
117 |
|
|
for (int i = 0; i < this.bitmap.length; i++) {
|
118 |
17168608
|
Daniel Stuš
|
if (currentDay.getDayOfWeek() != DayOfWeek.SATURDAY && currentDay.getDayOfWeek() != DayOfWeek.SUNDAY && !isBankHoliday(currentDay)) {
|
119 |
cbd6adb3
|
Daniel Stuš
|
this.bitmap[i] = value;
|
120 |
|
|
}
|
121 |
|
|
|
122 |
17168608
|
Daniel Stuš
|
currentDay = currentDay.plusDays(1);
|
123 |
cbd6adb3
|
Daniel Stuš
|
}
|
124 |
|
|
}
|
125 |
|
|
|
126 |
17168608
|
Daniel Stuš
|
|
127 |
|
|
/**
|
128 |
|
|
* Metoda nastavy pracovni dny bitmapy v zvolenem obdobi na hodnotu parametru {@code value}
|
129 |
|
|
*
|
130 |
|
|
* @param from Pocatecni den obdobi
|
131 |
|
|
* @param to Konecny den obdobi
|
132 |
|
|
* @param value hodnota na kterou se maji dny v bitmape nastavit
|
133 |
|
|
*/
|
134 |
|
|
public void setWorkdaysInRange(LocalDate from, LocalDate to, int value) {
|
135 |
|
|
value = validateValue(value);
|
136 |
|
|
LocalDate currentDay = this.dateFrom;
|
137 |
|
|
|
138 |
|
|
for (int i = 0; i < this.bitmap.length; i++) {
|
139 |
|
|
if (!currentDay.isBefore(from) && !currentDay.isAfter(to) && !isBankHoliday(currentDay)) {
|
140 |
|
|
if (currentDay.getDayOfWeek() != DayOfWeek.SATURDAY && currentDay.getDayOfWeek() != DayOfWeek.SUNDAY) {
|
141 |
|
|
this.bitmap[i] = value;
|
142 |
|
|
}
|
143 |
|
|
}
|
144 |
|
|
|
145 |
|
|
currentDay = currentDay.plusDays(1);
|
146 |
|
|
}
|
147 |
|
|
|
148 |
|
|
}
|
149 |
|
|
|
150 |
|
|
/**
|
151 |
|
|
* Metoda nastavy vsechny dny (krome soboty) bitmapy na hodnotu parametru {@code value}
|
152 |
|
|
*
|
153 |
|
|
* @param value hodnota na kterou se maji dny v bitmape nastavit
|
154 |
|
|
*/
|
155 |
cbd6adb3
|
Daniel Stuš
|
public void setSundaysAndHolidays(int value) {
|
156 |
|
|
value = validateValue(value);
|
157 |
17168608
|
Daniel Stuš
|
LocalDate currentDay = this.dateFrom;
|
158 |
cbd6adb3
|
Daniel Stuš
|
|
159 |
|
|
for (int i = 0; i < this.bitmap.length; i++) {
|
160 |
17168608
|
Daniel Stuš
|
if (currentDay.getDayOfWeek() != DayOfWeek.SATURDAY) {
|
161 |
cbd6adb3
|
Daniel Stuš
|
this.bitmap[i] = value;
|
162 |
|
|
}
|
163 |
|
|
|
164 |
17168608
|
Daniel Stuš
|
currentDay = currentDay.plusDays(1);
|
165 |
cbd6adb3
|
Daniel Stuš
|
}
|
166 |
|
|
}
|
167 |
|
|
|
168 |
17168608
|
Daniel Stuš
|
/**
|
169 |
|
|
* Metoda nastavi vsechny dny (krome soboty) bitmapy ve zvolenem obdobi na hodnotu parametru {@code value}
|
170 |
|
|
*
|
171 |
|
|
* @param from Pocatecni den obdobi
|
172 |
|
|
* @param to Konecny den obdobi
|
173 |
|
|
* @param value hodnota na kterou se maji dny v bitmape nastavit
|
174 |
|
|
*/
|
175 |
|
|
public void setSundaysAndHolidays(LocalDate from, LocalDate to, int value) {
|
176 |
|
|
value = validateValue(value);
|
177 |
|
|
LocalDate currentDay = this.dateFrom;
|
178 |
|
|
|
179 |
|
|
for (int i = 0; i < this.bitmap.length; i++) {
|
180 |
|
|
if (!currentDay.isBefore(from) && !currentDay.isAfter(to) && !isBankHoliday(currentDay)) {
|
181 |
|
|
if (currentDay.getDayOfWeek() != DayOfWeek.SATURDAY) {
|
182 |
|
|
this.bitmap[i] = value;
|
183 |
|
|
}
|
184 |
|
|
}
|
185 |
|
|
|
186 |
|
|
currentDay = currentDay.plusDays(1);
|
187 |
|
|
}
|
188 |
|
|
}
|
189 |
|
|
|
190 |
|
|
/**
|
191 |
|
|
* Nastavi den v bitmape na prislusnou hodnotu predanou parametrem {@code value}
|
192 |
|
|
*
|
193 |
|
|
* @param day Den, pro ktery se ma hodnota v bitmape nastavit
|
194 |
|
|
* @param value Hodnota na kterou se ma bitmapa nastavit
|
195 |
|
|
*/
|
196 |
|
|
public void setDay(LocalDate day, int value) {
|
197 |
cbd6adb3
|
Daniel Stuš
|
value = validateValue(value);
|
198 |
|
|
int dayPosition = (int) getDatePosition(day);
|
199 |
|
|
|
200 |
|
|
bitmap[dayPosition] = value;
|
201 |
|
|
}
|
202 |
|
|
|
203 |
|
|
|
204 |
17168608
|
Daniel Stuš
|
/**
|
205 |
|
|
* Nastavi pouze jeden den v bitmapě na hodnotu 1 - jede
|
206 |
|
|
* vsechny ostatni dny nastavi na 0
|
207 |
|
|
*
|
208 |
|
|
* @param day Den, pro který se má hodnota v bitmapě nastavit
|
209 |
|
|
*/
|
210 |
|
|
public void setOneDayOnly(LocalDate day) {
|
211 |
cbd6adb3
|
Daniel Stuš
|
fillWithZeros();
|
212 |
|
|
int dayPosition = (int) getDatePosition(day);
|
213 |
|
|
|
214 |
|
|
bitmap[dayPosition] = 1;
|
215 |
|
|
}
|
216 |
|
|
|
217 |
17168608
|
Daniel Stuš
|
|
218 |
|
|
/**
|
219 |
|
|
* Nastavi dny (vsechny krome svatku) ve zvolenem obdobi na hodnotu {@code value}
|
220 |
|
|
*
|
221 |
|
|
* @param from Pocatecni den obdobi
|
222 |
|
|
* @param to Konecny den obdobi
|
223 |
|
|
* @param value hodnota na kterou se maji dny v bitmape nastavit
|
224 |
|
|
*/
|
225 |
|
|
public void setDaysInRange(LocalDate from, LocalDate to, int value) {
|
226 |
cbd6adb3
|
Daniel Stuš
|
value = validateValue(value);
|
227 |
17168608
|
Daniel Stuš
|
LocalDate currentDay = this.dateFrom;
|
228 |
7cafefe1
|
Daniel Stuš
|
|
229 |
|
|
for (int i = 0; i < this.bitmap.length; i++) {
|
230 |
17168608
|
Daniel Stuš
|
if (!currentDay.isBefore(from) && !currentDay.isAfter(to) && !isBankHoliday(currentDay)) {
|
231 |
7cafefe1
|
Daniel Stuš
|
this.bitmap[i] = value;
|
232 |
|
|
}
|
233 |
cbd6adb3
|
Daniel Stuš
|
|
234 |
17168608
|
Daniel Stuš
|
currentDay = currentDay.plusDays(1);
|
235 |
cbd6adb3
|
Daniel Stuš
|
}
|
236 |
|
|
|
237 |
|
|
}
|
238 |
|
|
|
239 |
17168608
|
Daniel Stuš
|
|
240 |
|
|
/**
|
241 |
|
|
* Nastavi vsechny dny ve zvolenem obdobi na hodnotu 0
|
242 |
|
|
*
|
243 |
|
|
* @param from Pocatecni den obdobi
|
244 |
|
|
* @param to Konecny den obdobi
|
245 |
|
|
*/
|
246 |
|
|
public void unsetDaysInRange(LocalDate from, LocalDate to) {
|
247 |
|
|
LocalDate currentDay = this.dateFrom;
|
248 |
cbd6adb3
|
Daniel Stuš
|
|
249 |
|
|
for (int i = 0; i < this.bitmap.length; i++) {
|
250 |
17168608
|
Daniel Stuš
|
if (!currentDay.isBefore(from) && !currentDay.isAfter(to)) {
|
251 |
|
|
this.bitmap[i] = 0;
|
252 |
cbd6adb3
|
Daniel Stuš
|
}
|
253 |
|
|
|
254 |
17168608
|
Daniel Stuš
|
currentDay = currentDay.plusDays(1);
|
255 |
cbd6adb3
|
Daniel Stuš
|
}
|
256 |
17168608
|
Daniel Stuš
|
|
257 |
cbd6adb3
|
Daniel Stuš
|
}
|
258 |
|
|
|
259 |
17168608
|
Daniel Stuš
|
|
260 |
|
|
/**
|
261 |
|
|
* Nastavi vsechny zvolene dny v tydny parametrem {@code dayOfWeek} na hodnotu {@code value}
|
262 |
|
|
*
|
263 |
|
|
* @param dayOfWeek Den v tydnu (po - ne) pro ktery se maji hodnoty nastavit
|
264 |
|
|
* @param value hodnota na kterou se maji dny v bitmape nastavit
|
265 |
|
|
*/
|
266 |
|
|
public void setDaysInWeek(DayOfWeek dayOfWeek, int value) {
|
267 |
cbd6adb3
|
Daniel Stuš
|
value = validateValue(value);
|
268 |
17168608
|
Daniel Stuš
|
LocalDate currentDay = this.dateFrom;
|
269 |
cbd6adb3
|
Daniel Stuš
|
|
270 |
|
|
for (int i = 0; i < this.bitmap.length; i++) {
|
271 |
17168608
|
Daniel Stuš
|
if (currentDay.getDayOfWeek() == dayOfWeek) {
|
272 |
cbd6adb3
|
Daniel Stuš
|
this.bitmap[i] = value;
|
273 |
|
|
}
|
274 |
|
|
|
275 |
17168608
|
Daniel Stuš
|
currentDay = currentDay.plusDays(1);
|
276 |
cbd6adb3
|
Daniel Stuš
|
}
|
277 |
|
|
}
|
278 |
|
|
|
279 |
17168608
|
Daniel Stuš
|
/**
|
280 |
|
|
* Nastavi vsechny zvolene dny v tydny parametrem {@code dayOfWeek} ve zvolenem obdobi na hodnotu {@code value}
|
281 |
|
|
*
|
282 |
|
|
* @param from Pocatecni den obdobi
|
283 |
|
|
* @param to Konecny den obdobi
|
284 |
|
|
* @param dayOfWeek Den v tydnu (po - ne) pro ktery se maji hodnoty nastavit
|
285 |
|
|
* @param value hodnota na kterou se maji dny v bitmape nastavit
|
286 |
|
|
*/
|
287 |
|
|
public void setDaysInWeek(LocalDate from, LocalDate to, DayOfWeek dayOfWeek, int value) {
|
288 |
82a06985
|
Daniel Stuš
|
value = validateValue(value);
|
289 |
17168608
|
Daniel Stuš
|
LocalDate currentDay = this.dateFrom;
|
290 |
82a06985
|
Daniel Stuš
|
|
291 |
|
|
for (int i = 0; i < this.bitmap.length; i++) {
|
292 |
17168608
|
Daniel Stuš
|
if (!currentDay.isBefore(from) && !currentDay.isAfter(to) && !isBankHoliday(currentDay))
|
293 |
|
|
if (currentDay.getDayOfWeek() == dayOfWeek) {
|
294 |
|
|
this.bitmap[i] = value;
|
295 |
|
|
}
|
296 |
|
|
currentDay = currentDay.plusDays(1);
|
297 |
|
|
}
|
298 |
|
|
}
|
299 |
|
|
|
300 |
|
|
|
301 |
|
|
/**
|
302 |
|
|
* Nastavi vsechny sude/liche tydny v bitmape na hodnotu {@code value}
|
303 |
|
|
*
|
304 |
|
|
* @param value hodnota na kterou se maji dny v bitmape nastavit
|
305 |
|
|
* @param remainder urcuje sude/liche tydny (zbytek po deleni 2); 1 -> liche tydny; 0 -> sude tydny
|
306 |
|
|
*/
|
307 |
|
|
public void setWeeks(int value, int remainder) {
|
308 |
|
|
value = validateValue(value);
|
309 |
|
|
LocalDate currentDay = this.dateFrom;
|
310 |
|
|
WeekFields weekFields = WeekFields.of(Locale.getDefault());
|
311 |
|
|
|
312 |
|
|
for (int i = 0; i < this.bitmap.length; i++) {
|
313 |
|
|
if ((currentDay.get(weekFields.weekOfWeekBasedYear())%2)==remainder) {
|
314 |
82a06985
|
Daniel Stuš
|
this.bitmap[i] = value;
|
315 |
|
|
}
|
316 |
|
|
|
317 |
17168608
|
Daniel Stuš
|
currentDay = currentDay.plusDays(1);
|
318 |
82a06985
|
Daniel Stuš
|
|
319 |
|
|
}
|
320 |
|
|
}
|
321 |
|
|
|
322 |
cbd6adb3
|
Daniel Stuš
|
|
323 |
17168608
|
Daniel Stuš
|
/**
|
324 |
|
|
* Nastavi vsechny sude/liche tydny v bitmape ve zvolenem obdobi na hodnotu {@code value}
|
325 |
|
|
*
|
326 |
|
|
* @param from Pocatecni den obdobi
|
327 |
|
|
* @param to Konecny den obdobi
|
328 |
|
|
* @param value hodnota na kterou se maji dny v bitmape nastavit
|
329 |
|
|
* @param remainder urcuje sude/liche tydny (zbytek po deleni 2); 1 -> liche tydny; 0 -> sude tydny
|
330 |
|
|
*/
|
331 |
|
|
public void setWeeksInRange(LocalDate from, LocalDate to, int value, int remainder) {
|
332 |
7cafefe1
|
Daniel Stuš
|
|
333 |
cbd6adb3
|
Daniel Stuš
|
value = validateValue(value);
|
334 |
17168608
|
Daniel Stuš
|
LocalDate currentDay = this.dateFrom;
|
335 |
|
|
WeekFields weekFields = WeekFields.of(Locale.getDefault());
|
336 |
cbd6adb3
|
Daniel Stuš
|
|
337 |
7cafefe1
|
Daniel Stuš
|
for (int i = 0; i < this.bitmap.length; i++) {
|
338 |
17168608
|
Daniel Stuš
|
if (!currentDay.isBefore(from) && !currentDay.isAfter(to)) {
|
339 |
|
|
if ((currentDay.get(weekFields.weekOfWeekBasedYear())%2)==remainder) {
|
340 |
7cafefe1
|
Daniel Stuš
|
this.bitmap[i] = value;
|
341 |
|
|
}
|
342 |
cbd6adb3
|
Daniel Stuš
|
}
|
343 |
|
|
|
344 |
17168608
|
Daniel Stuš
|
currentDay = currentDay.plusDays(1);
|
345 |
cbd6adb3
|
Daniel Stuš
|
}
|
346 |
|
|
|
347 |
|
|
}
|
348 |
|
|
|
349 |
82a06985
|
Daniel Stuš
|
|
350 |
17168608
|
Daniel Stuš
|
/**
|
351 |
|
|
* Nastavi vsechny dny svatku v bitmape na hodnotu {@code value}
|
352 |
|
|
*
|
353 |
|
|
* @param value hodnota na kterou se maji dny v bitmape nastavit
|
354 |
|
|
*/
|
355 |
|
|
public void setHolidays(int value) {
|
356 |
82a06985
|
Daniel Stuš
|
value = validateValue(value);
|
357 |
17168608
|
Daniel Stuš
|
LocalDate currentDay = this.dateFrom;
|
358 |
82a06985
|
Daniel Stuš
|
|
359 |
|
|
for (int i = 0; i < this.bitmap.length; i++) {
|
360 |
17168608
|
Daniel Stuš
|
if (isBankHoliday(currentDay)) {
|
361 |
|
|
this.bitmap[i] = value;
|
362 |
82a06985
|
Daniel Stuš
|
}
|
363 |
|
|
|
364 |
17168608
|
Daniel Stuš
|
currentDay = currentDay.plusDays(1);
|
365 |
|
|
}
|
366 |
|
|
}
|
367 |
|
|
|
368 |
|
|
|
369 |
|
|
/**
|
370 |
|
|
* Nastavy vsechny dny odpovidajici pevnym kodum ve zvolenem obdobi na hodnotu {@code value}
|
371 |
|
|
*
|
372 |
|
|
* @param from Pocatecni den obdobi
|
373 |
|
|
* @param to Konecny den obdobi
|
374 |
|
|
* @param value hodnota na kterou se maji dny v bitmape nastavit
|
375 |
|
|
*/
|
376 |
|
|
public void setHardCodeDays(LocalDate from, LocalDate to, int value) {
|
377 |
|
|
|
378 |
|
|
value = validateValue(value);
|
379 |
|
|
char[] hardCodesChar = hardCodes.toCharArray();
|
380 |
|
|
|
381 |
|
|
for (int i = 0; i < hardCodesChar.length; i++) {
|
382 |
|
|
LocalDate currentDay = this.dateFrom;
|
383 |
|
|
for (int j = 0; j < this.bitmap.length; j++) {
|
384 |
|
|
if (isHardCodeDay(currentDay, hardCodesChar[i]) && !currentDay.isBefore(from) && !currentDay.isAfter(to)) {
|
385 |
|
|
this.bitmap[j] = value;
|
386 |
|
|
}
|
387 |
|
|
|
388 |
|
|
currentDay = currentDay.plusDays(1);
|
389 |
|
|
}
|
390 |
82a06985
|
Daniel Stuš
|
}
|
391 |
|
|
|
392 |
|
|
}
|
393 |
|
|
|
394 |
17168608
|
Daniel Stuš
|
/**
|
395 |
|
|
* Nastavy vsechny dny odpovidajici pevnym kodum v sudych/lichych tydnech na hodnotu {@code value}
|
396 |
|
|
*
|
397 |
|
|
* @param value hodnota na kterou se maji dny v bitmape nastavit
|
398 |
|
|
* @param remainder urcuje sude/liche tydny (zbytek po deleni 2); 1 -> liche tydny; 0 -> sude tydny
|
399 |
|
|
*/
|
400 |
|
|
public void setHardCodeWeeks(int value, int remainder) {
|
401 |
7cafefe1
|
Daniel Stuš
|
|
402 |
17168608
|
Daniel Stuš
|
value = validateValue(value);
|
403 |
|
|
WeekFields weekFields = WeekFields.of(Locale.getDefault());
|
404 |
|
|
char[] hardCodesChar = hardCodes.toCharArray();
|
405 |
|
|
|
406 |
|
|
for (int i = 0; i < hardCodesChar.length; i++) {
|
407 |
|
|
LocalDate currentDay = this.dateFrom;
|
408 |
|
|
for (int j = 0; j < this.bitmap.length; j++) {
|
409 |
|
|
if ((currentDay.get(weekFields.weekOfWeekBasedYear()) % 2) == remainder && isHardCodeDay(currentDay, hardCodesChar[i])) {
|
410 |
|
|
this.bitmap[j] = value;
|
411 |
|
|
}
|
412 |
|
|
|
413 |
|
|
currentDay = currentDay.plusDays(1);
|
414 |
7cafefe1
|
Daniel Stuš
|
}
|
415 |
17168608
|
Daniel Stuš
|
}
|
416 |
7cafefe1
|
Daniel Stuš
|
|
417 |
17168608
|
Daniel Stuš
|
}
|
418 |
|
|
|
419 |
|
|
/**
|
420 |
|
|
* Nastavy vsechny dny odpovidajici pevnym kodum v sudych/lichych tydnech ve zvolenem obdobi na hodnotu {@code value}
|
421 |
|
|
*
|
422 |
|
|
* @param from Pocatecni den obdobi
|
423 |
|
|
* @param to Konecny den obdobi
|
424 |
|
|
* @param value hodnota na kterou se maji dny v bitmape nastavit
|
425 |
|
|
* @param remainder urcuje sude/liche tydny (zbytek po deleni 2); 1 -> liche tydny; 0 -> sude tydny
|
426 |
|
|
*/
|
427 |
|
|
public void setHardCodeWeeksInRange(LocalDate from, LocalDate to, int value, int remainder) {
|
428 |
|
|
|
429 |
|
|
value = validateValue(value);
|
430 |
|
|
WeekFields weekFields = WeekFields.of(Locale.getDefault());
|
431 |
|
|
char[] hardCodesChar = hardCodes.toCharArray();
|
432 |
|
|
|
433 |
|
|
for (int i = 0; i < hardCodesChar.length; i++) {
|
434 |
|
|
LocalDate currentDay = this.dateFrom;
|
435 |
|
|
for (int j = 0; j < this.bitmap.length; j++) {
|
436 |
|
|
if (!currentDay.isBefore(from) && !currentDay.isAfter(to)) {
|
437 |
|
|
if ((currentDay.get(weekFields.weekOfWeekBasedYear()) % 2) == remainder && isHardCodeDay(currentDay, hardCodesChar[i])) {
|
438 |
|
|
this.bitmap[j] = value;
|
439 |
|
|
}
|
440 |
|
|
}
|
441 |
|
|
|
442 |
|
|
currentDay = currentDay.plusDays(1);
|
443 |
|
|
}
|
444 |
7cafefe1
|
Daniel Stuš
|
}
|
445 |
17168608
|
Daniel Stuš
|
|
446 |
|
|
}
|
447 |
|
|
|
448 |
|
|
/**
|
449 |
|
|
* Metoda overi jestli predany den je soucasti jednoho z pevnych kodu
|
450 |
|
|
*
|
451 |
|
|
* @param day den pro overeni pevnych kodu
|
452 |
|
|
* @param hardCode pevny kod pro overeni
|
453 |
|
|
* @return Vrati {@code true} pokud den spada do nektereho z pevnych kodu, v opacnem pripade vraci {@code false}
|
454 |
|
|
*/
|
455 |
|
|
public boolean isHardCodeDay(LocalDate day, char hardCode) {
|
456 |
|
|
|
457 |
|
|
switch (hardCode) {
|
458 |
|
|
case 'X': if(day.getDayOfWeek() != DayOfWeek.SATURDAY && day.getDayOfWeek() != DayOfWeek.SUNDAY && !isBankHoliday(day)) return true ; break;
|
459 |
|
|
case '+': if (day.getDayOfWeek() != DayOfWeek.SATURDAY) return true; break;
|
460 |
27ba3ec6
|
Daniel Stuš
|
case '1': if (day.getDayOfWeek() == DayOfWeek.MONDAY) return true; break;
|
461 |
17168608
|
Daniel Stuš
|
case '2': if (day.getDayOfWeek() == DayOfWeek.TUESDAY) return true; break;
|
462 |
|
|
case '3': if (day.getDayOfWeek() == DayOfWeek.WEDNESDAY) return true; break;
|
463 |
|
|
case '4': if (day.getDayOfWeek() == DayOfWeek.THURSDAY) return true; break;
|
464 |
|
|
case '5': if (day.getDayOfWeek() == DayOfWeek.FRIDAY) return true; break;
|
465 |
|
|
case '6': if (day.getDayOfWeek() == DayOfWeek.SATURDAY) return true; break;
|
466 |
|
|
case '7': if (day.getDayOfWeek() == DayOfWeek.SUNDAY) return true; break;
|
467 |
|
|
default: return false;
|
468 |
|
|
}
|
469 |
|
|
|
470 |
|
|
return false;
|
471 |
7cafefe1
|
Daniel Stuš
|
}
|
472 |
|
|
|
473 |
cbd6adb3
|
Daniel Stuš
|
|
474 |
|
|
/**
|
475 |
|
|
* Metoda naplní (přemaže) bitmapu nulami
|
476 |
|
|
*/
|
477 |
|
|
public void fillWithZeros() {
|
478 |
|
|
Arrays.fill(this.bitmap, 0);
|
479 |
|
|
}
|
480 |
|
|
|
481 |
9ebc6f0f
|
Daniel Stuš
|
/**
|
482 |
|
|
* Metoda naplní bitmapu (všechny dny) jedničkami
|
483 |
|
|
*/
|
484 |
|
|
public void fillWithOnes() {
|
485 |
|
|
Arrays.fill(this.bitmap, 1);
|
486 |
|
|
}
|
487 |
|
|
|
488 |
|
|
|
489 |
cbd6adb3
|
Daniel Stuš
|
/**
|
490 |
|
|
* Metoda overuje spravnost zadane hodnoty
|
491 |
|
|
* - do bitmapy lze zadat pouze 1 nebo 0
|
492 |
|
|
* - v pripade ze uzivatel zada cislo vetsi nez jedna metoda vrati jednotku
|
493 |
|
|
* - v pripade ze uzivatel zada cislo mensi nez nula metoda vrati nulu
|
494 |
|
|
*
|
495 |
|
|
* @param value Uzivatelem zadana hodnota
|
496 |
|
|
* @return Nova (spravna hodnota) ukladajici se do bitmapy
|
497 |
|
|
*/
|
498 |
|
|
public static int validateValue(int value) {
|
499 |
|
|
if (value < 0) value = 0;
|
500 |
|
|
else if (value > 0) value = 1;
|
501 |
|
|
else return value;
|
502 |
|
|
return value;
|
503 |
|
|
}
|
504 |
|
|
|
505 |
17168608
|
Daniel Stuš
|
/**
|
506 |
|
|
* Metoda overi zda je zadany den statnim svatkem
|
507 |
|
|
*
|
508 |
|
|
* @param date den pro overeni statniho svatku
|
509 |
|
|
* @return {@code true} pokud je v zadany den statni svatek, {@code false} pokud neni v zadany den statni svatek
|
510 |
|
|
*/
|
511 |
|
|
public boolean isBankHoliday(LocalDate date) {
|
512 |
7cafefe1
|
Daniel Stuš
|
|
513 |
17168608
|
Daniel Stuš
|
Month month = date.getMonth();
|
514 |
|
|
int dayOfMonth = date.getDayOfMonth();
|
515 |
7cafefe1
|
Daniel Stuš
|
|
516 |
17168608
|
Daniel Stuš
|
if (date.getDayOfYear() == 1) getEasterHolidays(date.getYear());
|
517 |
7cafefe1
|
Daniel Stuš
|
|
518 |
|
|
// 1. ledna - Den obnovy samostatného českého státu | Nový rok
|
519 |
17168608
|
Daniel Stuš
|
if(month == Month.JANUARY && dayOfMonth == 1) {
|
520 |
7cafefe1
|
Daniel Stuš
|
return true;
|
521 |
|
|
}
|
522 |
|
|
|
523 |
|
|
// Velikonoční pondělí
|
524 |
17168608
|
Daniel Stuš
|
if(month == easterMonday.getMonth() && dayOfMonth == easterMonday.getDayOfMonth()){
|
525 |
7cafefe1
|
Daniel Stuš
|
return true;
|
526 |
|
|
}
|
527 |
|
|
|
528 |
|
|
// Velký pátek
|
529 |
17168608
|
Daniel Stuš
|
if(month == goodFriday.getMonth() && dayOfMonth == goodFriday.getDayOfMonth()){
|
530 |
7cafefe1
|
Daniel Stuš
|
return true;
|
531 |
|
|
}
|
532 |
|
|
|
533 |
|
|
// 1. května - Svátek práce
|
534 |
17168608
|
Daniel Stuš
|
if(month == Month.MAY && dayOfMonth == 1) {
|
535 |
7cafefe1
|
Daniel Stuš
|
return true;
|
536 |
|
|
}
|
537 |
|
|
|
538 |
|
|
// 8. května - Den vítězství
|
539 |
17168608
|
Daniel Stuš
|
if(month == Month.MAY && dayOfMonth == 8) {
|
540 |
7cafefe1
|
Daniel Stuš
|
return true;
|
541 |
|
|
}
|
542 |
|
|
|
543 |
|
|
// 5. července - Den slovanských věrozvěstů Cyrila a Metoděje
|
544 |
17168608
|
Daniel Stuš
|
if(month == Month.JULY && dayOfMonth == 5) {
|
545 |
7cafefe1
|
Daniel Stuš
|
return true;
|
546 |
|
|
}
|
547 |
|
|
|
548 |
|
|
// 6. července - Den upálení mistra Jana Husa
|
549 |
17168608
|
Daniel Stuš
|
if(month == Month.JULY && dayOfMonth == 6) {
|
550 |
7cafefe1
|
Daniel Stuš
|
return true;
|
551 |
|
|
}
|
552 |
|
|
|
553 |
|
|
// 28. září – Den české státnosti
|
554 |
17168608
|
Daniel Stuš
|
if(month == Month.SEPTEMBER && dayOfMonth == 28) {
|
555 |
7cafefe1
|
Daniel Stuš
|
return true;
|
556 |
|
|
}
|
557 |
|
|
|
558 |
|
|
// 28. října – Den vzniku samostatného československého státu
|
559 |
17168608
|
Daniel Stuš
|
if(month == Month.OCTOBER && dayOfMonth == 28) {
|
560 |
7cafefe1
|
Daniel Stuš
|
return true;
|
561 |
|
|
}
|
562 |
|
|
|
563 |
|
|
// 17. listopadu – Den boje za svobodu a demokracii
|
564 |
17168608
|
Daniel Stuš
|
if(month == Month.NOVEMBER && dayOfMonth == 17) {
|
565 |
7cafefe1
|
Daniel Stuš
|
return true;
|
566 |
|
|
}
|
567 |
|
|
|
568 |
|
|
// 24. prosince – Štědrý den
|
569 |
17168608
|
Daniel Stuš
|
if(month == Month.DECEMBER && dayOfMonth == 24) {
|
570 |
7cafefe1
|
Daniel Stuš
|
return true;
|
571 |
|
|
}
|
572 |
|
|
|
573 |
|
|
// 25. prosince – 1. svátek vánoční
|
574 |
17168608
|
Daniel Stuš
|
if(month == Month.DECEMBER && dayOfMonth == 25) {
|
575 |
7cafefe1
|
Daniel Stuš
|
return true;
|
576 |
|
|
}
|
577 |
|
|
|
578 |
|
|
// 26. prosince – 2. svátek vánoční
|
579 |
17168608
|
Daniel Stuš
|
if(month == Month.DECEMBER && dayOfMonth == 26) {
|
580 |
7cafefe1
|
Daniel Stuš
|
return true;
|
581 |
|
|
}
|
582 |
|
|
|
583 |
|
|
// Není svátek
|
584 |
|
|
return false;
|
585 |
|
|
|
586 |
|
|
}
|
587 |
|
|
|
588 |
17168608
|
Daniel Stuš
|
/**
|
589 |
|
|
* Metoda vypocita a nastavi bitmape na zaklade roku aktualni dny velikonocnich svatku
|
590 |
|
|
*
|
591 |
|
|
* @param year Rok pro vypocet velikonocnich svatku
|
592 |
|
|
*/
|
593 |
7cafefe1
|
Daniel Stuš
|
public void getEasterHolidays(int year) {
|
594 |
27ba3ec6
|
Daniel Stuš
|
int a = year % 19;
|
595 |
|
|
int b = year / 100;
|
596 |
|
|
int c = year % 100;
|
597 |
7cafefe1
|
Daniel Stuš
|
int d = b / 4;
|
598 |
|
|
int e = b % 4;
|
599 |
|
|
int f = (b + 8) / 25;
|
600 |
|
|
int g = (b - f + 1) / 3;
|
601 |
|
|
int h = (19 * a + b - d - g + 15) % 30;
|
602 |
|
|
int i = c / 4;
|
603 |
|
|
int k = c % 4;
|
604 |
|
|
int L = (32 + 2 * e + 2 * i - h - k) % 7;
|
605 |
|
|
int m = (a + 11 * h + 22 * L) / 451;
|
606 |
|
|
int n = h + L - 7 * m + 114;
|
607 |
|
|
int month = n / 31;
|
608 |
|
|
int day = (n % 31) + 1;
|
609 |
|
|
|
610 |
|
|
//Velikonoční pondělí --> Velikonoční neděle + 1
|
611 |
17168608
|
Daniel Stuš
|
LocalDate easterMonday = LocalDate.of(year, month, day);
|
612 |
|
|
easterMonday = easterMonday.plusDays(1);
|
613 |
7cafefe1
|
Daniel Stuš
|
//Velký pátek --> Velikonoční neděle - 2
|
614 |
17168608
|
Daniel Stuš
|
LocalDate goodFriday = LocalDate.of(year, month, day);
|
615 |
|
|
goodFriday = goodFriday.minusDays(2);
|
616 |
7cafefe1
|
Daniel Stuš
|
|
617 |
|
|
this.easterMonday = easterMonday;
|
618 |
|
|
this.goodFriday = goodFriday;
|
619 |
|
|
}
|
620 |
|
|
|
621 |
17168608
|
Daniel Stuš
|
/**
|
622 |
|
|
* Vrati bitmapu ve formatu retezce
|
623 |
|
|
*
|
624 |
|
|
* @return bitmapa ve formatu retezce
|
625 |
|
|
*/
|
626 |
7cafefe1
|
Daniel Stuš
|
public String getBitmapString() {
|
627 |
|
|
return Arrays.toString(this.bitmap).replaceAll("\\[|\\]|,|\\s", "");
|
628 |
|
|
}
|
629 |
|
|
|
630 |
17168608
|
Daniel Stuš
|
/**
|
631 |
|
|
* Vrati pocatecni den obdobi bitmapy
|
632 |
|
|
*
|
633 |
|
|
* @return pocatecni den obdobi bitmapy
|
634 |
|
|
*/
|
635 |
|
|
public LocalDate getDateFrom() {
|
636 |
cbd6adb3
|
Daniel Stuš
|
return dateFrom;
|
637 |
|
|
}
|
638 |
|
|
|
639 |
17168608
|
Daniel Stuš
|
/**
|
640 |
|
|
* Nastavi pocatecni den obdobi na hodnotu {@code dateFrom}
|
641 |
|
|
*
|
642 |
|
|
* @param dateFrom pocatecni den obdobi bitmapy
|
643 |
|
|
*/
|
644 |
|
|
public void setDateFrom(LocalDate dateFrom) {
|
645 |
cbd6adb3
|
Daniel Stuš
|
this.dateFrom = dateFrom;
|
646 |
|
|
}
|
647 |
|
|
|
648 |
17168608
|
Daniel Stuš
|
|
649 |
|
|
/**
|
650 |
|
|
* Vrati koncovy den obdobi bitmapy
|
651 |
|
|
*
|
652 |
|
|
* @return koncovy den obdobi bitmapy
|
653 |
|
|
*/
|
654 |
|
|
public LocalDate getDateTo() {
|
655 |
cbd6adb3
|
Daniel Stuš
|
return dateTo;
|
656 |
|
|
}
|
657 |
|
|
|
658 |
17168608
|
Daniel Stuš
|
|
659 |
|
|
/**
|
660 |
|
|
* Nastavi koncovy den obdobi na hodnotu {@code dateFrom}
|
661 |
|
|
*
|
662 |
|
|
* @param dateTo koncovy den obdobi bitmapy
|
663 |
|
|
*/
|
664 |
|
|
public void setDateTo(LocalDate dateTo) {
|
665 |
cbd6adb3
|
Daniel Stuš
|
this.dateTo = dateTo;
|
666 |
|
|
}
|
667 |
|
|
|
668 |
17168608
|
Daniel Stuš
|
/**
|
669 |
|
|
* Vrati retezec s cislem linky generovane bitmapy
|
670 |
|
|
*
|
671 |
|
|
* @return retezec s cislem linky generovane bitmapy
|
672 |
|
|
*/
|
673 |
cbd6adb3
|
Daniel Stuš
|
public String getLineNumber() {
|
674 |
|
|
return lineNumber;
|
675 |
|
|
}
|
676 |
|
|
|
677 |
17168608
|
Daniel Stuš
|
/**
|
678 |
|
|
* Nastavi hodnotu atributu retezece s cislem linky generovane bitmapy na {@code lineNumber}
|
679 |
|
|
*
|
680 |
|
|
* @param lineNumber retezece s cislem linky pro nastaveni bitmapy
|
681 |
|
|
*/
|
682 |
cbd6adb3
|
Daniel Stuš
|
public void setLineNumber(String lineNumber) {
|
683 |
|
|
this.lineNumber = lineNumber;
|
684 |
|
|
}
|
685 |
|
|
|
686 |
17168608
|
Daniel Stuš
|
/**
|
687 |
|
|
* Vrati pole bitovych map
|
688 |
|
|
*
|
689 |
|
|
* @return pole bitovych map
|
690 |
|
|
*/
|
691 |
cbd6adb3
|
Daniel Stuš
|
public int[] getBitmap() {
|
692 |
|
|
return bitmap;
|
693 |
|
|
}
|
694 |
|
|
|
695 |
17168608
|
Daniel Stuš
|
/**
|
696 |
|
|
* Nastavi pole bitovych map na hodnotu {@code bitmap}
|
697 |
|
|
*
|
698 |
|
|
* @param bitmap pole bitovych map pro nastaveni bitmapy
|
699 |
|
|
*/
|
700 |
cbd6adb3
|
Daniel Stuš
|
public void setBitmap(int[] bitmap) {
|
701 |
|
|
this.bitmap = bitmap;
|
702 |
|
|
}
|
703 |
|
|
|
704 |
17168608
|
Daniel Stuš
|
/**
|
705 |
|
|
* Vrati retezec s cislem spoje generovane bitmapy
|
706 |
|
|
*
|
707 |
|
|
* @return retezec s cislem spoje generovane bitmapy
|
708 |
|
|
*/
|
709 |
|
|
public String getJoinNumber() {
|
710 |
|
|
return joinNumber;
|
711 |
|
|
}
|
712 |
|
|
|
713 |
|
|
/**
|
714 |
|
|
* Nastavi hodnotu atributu retezece s cislem spoje generovane bitmapy na {@code joinNumber}
|
715 |
|
|
*
|
716 |
|
|
* @param joinNumber retezece s cislem spoje pro nastaveni bitmapy
|
717 |
|
|
*/
|
718 |
|
|
public void setJoinNumber(String joinNumber) {
|
719 |
|
|
this.joinNumber = joinNumber;
|
720 |
|
|
}
|
721 |
|
|
|
722 |
|
|
/**
|
723 |
|
|
* Vrati retezec s cislem verze linky generovane bitmapy
|
724 |
|
|
*
|
725 |
|
|
* @return retezec s cislem verze linky generovane bitmapy
|
726 |
|
|
*/
|
727 |
|
|
public String getLineVersion() {
|
728 |
|
|
return lineVersion;
|
729 |
|
|
}
|
730 |
|
|
|
731 |
|
|
/**
|
732 |
|
|
* Nastavi hodnotu atributu retezece s verzi linky kodu generovane bitmapy na {@code lineVersion}
|
733 |
|
|
*
|
734 |
|
|
* @param lineVersion retezece s cislem verze linky pro nastaveni bitmapy
|
735 |
|
|
*/
|
736 |
|
|
public void setLineVersion(String lineVersion) {
|
737 |
|
|
this.lineVersion = lineVersion;
|
738 |
|
|
}
|
739 |
|
|
|
740 |
|
|
/**
|
741 |
|
|
* Vrati retezec s cislem ceasoveho kodu generovane bitmapy
|
742 |
|
|
*
|
743 |
|
|
* @return etezece s cislem casoveho kodu generovane bitmapy
|
744 |
|
|
*/
|
745 |
|
|
public String getTimeCode() {
|
746 |
|
|
return timeCode;
|
747 |
|
|
}
|
748 |
|
|
|
749 |
|
|
/**
|
750 |
|
|
* Nastavi hodnotu atributu retezece s cislem casoveho kodu generovane bitmapy na {@code timeCode}
|
751 |
|
|
*
|
752 |
|
|
* @param timeCode retezece s cislem casoveho kodu pro nastaveni bitmapy
|
753 |
|
|
*/
|
754 |
|
|
public void setTimeCode(String timeCode) {
|
755 |
|
|
this.timeCode = timeCode;
|
756 |
|
|
}
|
757 |
|
|
|
758 |
|
|
/**
|
759 |
|
|
* Nastavi hodnotu atributu tridy s pevnymi kody
|
760 |
|
|
*
|
761 |
|
|
* @return retezec s pevnymi kody
|
762 |
|
|
*/
|
763 |
|
|
public String getHardCodes() {
|
764 |
|
|
return hardCodes;
|
765 |
|
|
}
|
766 |
|
|
|
767 |
|
|
/**
|
768 |
|
|
* Nastavi hodnotu atributu tridy s pevnymi kody na {@code hardCodes}
|
769 |
|
|
*
|
770 |
|
|
* @param hardCodes retezec s pevnymi kody bitmapy
|
771 |
|
|
*/
|
772 |
|
|
public void setHardCodes(String hardCodes) {
|
773 |
|
|
this.hardCodes = hardCodes;
|
774 |
|
|
}
|
775 |
|
|
|
776 |
|
|
/**
|
777 |
|
|
* Vrati retezec bitmapy ve formatu [XXXXXXXXXXX]
|
778 |
|
|
*
|
779 |
|
|
* @return bitmapa jako retezec ve formatu [XXXXXXXXXXX]
|
780 |
|
|
*/
|
781 |
|
|
public String bitmapToString() { return Arrays.toString(this.bitmap); }
|
782 |
|
|
|
783 |
|
|
|
784 |
|
|
/**
|
785 |
|
|
* Vrati retezec s udajemi atributu tridy ve format pro vypis
|
786 |
|
|
* format: cisloLinkyVerzeLinky-CasovyKod-PevneKody;;Bitovamapa
|
787 |
|
|
*
|
788 |
|
|
* @return retezec s udajemi atributu tridy
|
789 |
|
|
*/
|
790 |
cbd6adb3
|
Daniel Stuš
|
@Override
|
791 |
|
|
public String toString() {
|
792 |
17168608
|
Daniel Stuš
|
return lineNumber+lineVersion+"-"+timeCode+"-"+hardCodes+";;"+getBitmapString();
|
793 |
cbd6adb3
|
Daniel Stuš
|
}
|
794 |
|
|
|
795 |
|
|
|
796 |
|
|
/**
|
797 |
|
|
*
|
798 |
|
|
* hlavni metoda pro ozkouseni funkcnosti {@code Bitmap}
|
799 |
|
|
*-issue #7374
|
800 |
|
|
*
|
801 |
|
|
* @param args parametry programu
|
802 |
|
|
*/
|
803 |
|
|
public static void main(String[] args) {
|
804 |
|
|
|
805 |
17168608
|
Daniel Stuš
|
LocalDate dateFrom = LocalDate.of(2019, 5, 1);
|
806 |
|
|
LocalDate dateTo = LocalDate.of(2019, 5, 31);
|
807 |
cbd6adb3
|
Daniel Stuš
|
|
808 |
|
|
|
809 |
17168608
|
Daniel Stuš
|
|
810 |
|
|
Bitmap bitmap = new Bitmap(dateFrom, dateTo, "143440","1","34", "5", "1");
|
811 |
cbd6adb3
|
Daniel Stuš
|
|
812 |
|
|
|
813 |
|
|
// ------------- KONTROLNÍ VÝPISY -----------------
|
814 |
|
|
System.out.println("------------- KONTROLNÍ VÝPISY -----------------");
|
815 |
7cafefe1
|
Daniel Stuš
|
System.out.println("Linka: "+ bitmap.getLineNumber());
|
816 |
17168608
|
Daniel Stuš
|
System.out.println("Datum: od: " + bitmap.getDateFrom() + " | do: " + bitmap.getDateTo());
|
817 |
|
|
System.out.println("První den je: "+bitmap.getDateFrom().getDayOfWeek());
|
818 |
cbd6adb3
|
Daniel Stuš
|
System.out.println("Počet dní v rozmezí: " + bitmap.getDateRange());
|
819 |
17168608
|
Daniel Stuš
|
System.out.println(bitmap.bitmapToString());
|
820 |
cbd6adb3
|
Daniel Stuš
|
|
821 |
|
|
//Jede pouze v pracovní dny
|
822 |
|
|
bitmap.setWorkdays(1);
|
823 |
|
|
System.out.println("\nJede v pracovní dny:");
|
824 |
17168608
|
Daniel Stuš
|
System.out.println(bitmap.bitmapToString());
|
825 |
de8ed2a2
|
Jan Jirman
|
|
826 |
|
|
bitmap.fillWithZeros();
|
827 |
|
|
|
828 |
|
|
bitmap.setSundaysAndHolidays(1);
|
829 |
17168608
|
Daniel Stuš
|
System.out.println(bitmap.bitmapToString());
|
830 |
cbd6adb3
|
Daniel Stuš
|
|
831 |
|
|
// Kontrola přemazání
|
832 |
|
|
System.out.println("\nKontrola přemazání:");
|
833 |
|
|
bitmap.fillWithZeros();
|
834 |
17168608
|
Daniel Stuš
|
System.out.println(bitmap.bitmapToString());
|
835 |
cbd6adb3
|
Daniel Stuš
|
|
836 |
|
|
//Nastavit pouze Pondělky - atribut 2
|
837 |
|
|
System.out.println("\nJede každé pondělí:");
|
838 |
17168608
|
Daniel Stuš
|
bitmap.setDaysInWeek(DayOfWeek.MONDAY, 1);
|
839 |
|
|
System.out.println(bitmap.bitmapToString());
|
840 |
cbd6adb3
|
Daniel Stuš
|
|
841 |
|
|
//přemazání
|
842 |
|
|
bitmap.fillWithZeros();
|
843 |
17168608
|
Daniel Stuš
|
|
844 |
|
|
System.out.println("\nJede liché týdny od 1. 5. - 13. 5. :");
|
845 |
|
|
LocalDate dateTo2 = LocalDate.of(2019, 5, 13);
|
846 |
|
|
bitmap.setWeeksInRange(dateFrom, dateTo2, 1, 1);
|
847 |
|
|
System.out.println(bitmap.bitmapToString());
|
848 |
cbd6adb3
|
Daniel Stuš
|
|
849 |
|
|
//Nastavit liché týdny (zbytek(remainder) 1 - liché)
|
850 |
|
|
System.out.println("\nLiché týdny:");
|
851 |
|
|
bitmap.setWeeks(1, 1);
|
852 |
17168608
|
Daniel Stuš
|
System.out.println(bitmap.bitmapToString());
|
853 |
|
|
|
854 |
|
|
//přemazání
|
855 |
|
|
bitmap.fillWithZeros();
|
856 |
|
|
|
857 |
|
|
//Nastavit podle časového kódu
|
858 |
|
|
System.out.println("\nNastavení podle pevných kódů:");
|
859 |
|
|
bitmap.setHardCodeDays(dateFrom, dateTo2, 1);
|
860 |
|
|
System.out.println(bitmap.bitmapToString());
|
861 |
cbd6adb3
|
Daniel Stuš
|
|
862 |
7cafefe1
|
Daniel Stuš
|
//Velikonoce pro svátky
|
863 |
17168608
|
Daniel Stuš
|
System.out.println("\nVelikonoční pondělí: " + bitmap.easterMonday);
|
864 |
|
|
System.out.println("Velký pátek: " + bitmap.goodFriday);
|
865 |
|
|
|
866 |
|
|
|
867 |
|
|
|
868 |
cbd6adb3
|
Daniel Stuš
|
|
869 |
|
|
|
870 |
|
|
}
|
871 |
|
|
|
872 |
|
|
|
873 |
27ba3ec6
|
Daniel Stuš
|
/**
|
874 |
|
|
* Porovnava bitmapy podle jejich atributu pro serazeni podle hodnot
|
875 |
|
|
* @param o bitmapa k porovnani se stavajici
|
876 |
|
|
* @return 0 - kdyz jsou bitmapy stejne
|
877 |
|
|
* 1 - kdyz je bitmapa "vetsi"
|
878 |
|
|
* -1 - kdyz je bitmapa "mensi"
|
879 |
|
|
*/
|
880 |
|
|
@Override
|
881 |
|
|
public int compareTo(Bitmap o) {
|
882 |
|
|
|
883 |
|
|
if (this.lineNumber.equals(o.lineNumber)) {
|
884 |
|
|
if(this.lineVersion.equals(o.lineVersion)) {
|
885 |
|
|
if (this.timeCode.equals(o.timeCode)) {
|
886 |
|
|
if (this.hardCodes.equals(o.hardCodes)) {
|
887 |
|
|
if(Arrays.equals(this.bitmap, o.bitmap)) return 0;
|
888 |
|
|
else return -1;
|
889 |
|
|
}
|
890 |
|
|
else if (this.hardCodes.equals("") && !o.hardCodes.equals(""))
|
891 |
|
|
return -Integer.parseInt(o.hardCodes);
|
892 |
a353614c
|
Daniel Stuš
|
else if (!this.hardCodes.equals("") && o.hardCodes.equals(""))
|
893 |
27ba3ec6
|
Daniel Stuš
|
return Integer.parseInt(this.hardCodes);
|
894 |
|
|
else return Integer.parseInt(this.hardCodes) - Integer.parseInt(o.hardCodes);
|
895 |
|
|
}
|
896 |
|
|
else if (this.timeCode.equals("") && !o.timeCode.equals(""))
|
897 |
|
|
return -Integer.parseInt(o.timeCode);
|
898 |
|
|
else if (!this.timeCode.equals("") && o.timeCode.equals(""))
|
899 |
|
|
return Integer.parseInt(this.timeCode);
|
900 |
|
|
else return Integer.parseInt(this.timeCode) - Integer.parseInt(o.timeCode);
|
901 |
|
|
}
|
902 |
|
|
else return Integer.parseInt(this.lineVersion) - Integer.parseInt(o.lineVersion);
|
903 |
|
|
}
|
904 |
|
|
else return Integer.parseInt(this.lineNumber) - Integer.parseInt(o.lineNumber);
|
905 |
|
|
}
|
906 |
|
|
|
907 |
|
|
/**
|
908 |
|
|
* Porovna objekt s bitmapou a rozhodne zda se jedna o stejnou ci ne
|
909 |
|
|
* @param obj objekt k porovnani s bitmapou
|
910 |
|
|
* @return true - kdyz je cela bitmapa stejna
|
911 |
|
|
* false - v opacnem pripade
|
912 |
|
|
*/
|
913 |
|
|
@Override
|
914 |
|
|
public boolean equals(Object obj) {
|
915 |
|
|
if (this == obj) return true;
|
916 |
|
|
if (obj == null) return false;
|
917 |
|
|
if(getClass() != obj.getClass()) return false;
|
918 |
|
|
Bitmap o = (Bitmap) obj;
|
919 |
|
|
return Objects.equals(lineNumber, o.lineNumber) && Objects.equals(lineVersion, o.lineVersion) &&
|
920 |
|
|
Objects.equals(timeCode, o.timeCode) && Objects.equals(hardCodes, o.hardCodes) &&
|
921 |
|
|
Objects.equals(bitmap, o.bitmap);
|
922 |
|
|
}
|
923 |
|
|
|
924 |
|
|
|
925 |
cbd6adb3
|
Daniel Stuš
|
}
|
926 |
27ba3ec6
|
Daniel Stuš
|
|