Revize 7cafefe1
Přidáno uživatelem Daniel Stuš před téměř 6 roky(ů)
src/data/Bitmap.java | ||
---|---|---|
15 | 15 |
* Trida uchovavajici informace a umoznujici praci s bitmapou |
16 | 16 |
* |
17 | 17 |
* @author Daniel Stus, Marek Sobota, Lukas Scurko, Jan Jirman |
18 |
* @version 0.5
|
|
18 |
* @version 0.8
|
|
19 | 19 |
* |
20 | 20 |
*/ |
21 | 21 |
public class Bitmap { |
... | ... | |
31 | 31 |
/** Atribut s cislem linky pro kterou je generovana bitmapa */ |
32 | 32 |
private String lineNumber; |
33 | 33 |
|
34 |
/** Atribut s cislem spoje linky pro kterou je generovana bitmapa */ |
|
35 |
private String connectionNumber; |
|
36 |
|
|
37 | 34 |
/** Pole uchovavajici bitmapu */ |
38 | 35 |
private int[] bitmap; |
39 | 36 |
|
40 |
/** Atribut uchovavajici hodnotu dne (ktery den v tydnu odpovida) pocatku obdobi */
|
|
41 |
private int firstDayOfWeek; |
|
37 |
private Calendar goodFriday, easterMonday;
|
|
38 |
|
|
42 | 39 |
|
43 | 40 |
|
44 | 41 |
//-------------- Konstruktor -------------/ |
... | ... | |
49 | 46 |
* @param dateFrom Datum zacatku obdobi |
50 | 47 |
* @param dateTo Datum konce obdobi |
51 | 48 |
* @param lineNumber Cislo linky |
52 |
* @param connectionNumber Cislo spoje dane linky |
|
53 | 49 |
*/ |
54 |
public Bitmap(Calendar dateFrom, Calendar dateTo, String lineNumber, String connectionNumber) {
|
|
50 |
public Bitmap(Calendar dateFrom, Calendar dateTo, String lineNumber) { |
|
55 | 51 |
this.dateFrom = dateFrom; |
56 | 52 |
this.dateTo = dateTo; |
57 | 53 |
this.lineNumber = lineNumber; |
58 |
this.connectionNumber = connectionNumber; |
|
59 | 54 |
this.bitmap = new int[(int) getDateRange()]; |
60 |
this.firstDayOfWeek = dateFrom.get(Calendar.DAY_OF_WEEK);
|
|
55 |
getEasterHolidays(dateFrom.get(Calendar.YEAR));
|
|
61 | 56 |
} |
62 | 57 |
|
63 | 58 |
|
64 | 59 |
//----------------- Metody ----------------/ |
65 | 60 |
|
66 | 61 |
/** |
67 |
* Metda vrací počet dní uživatelem zvoleného období |
|
62 |
* Metoda vrací počet dní uživatelem zvoleného období
|
|
68 | 63 |
* |
69 | 64 |
* @return Počet dní v uživatelem zvoleném období (rozmezí) |
70 | 65 |
*/ |
... | ... | |
88 | 83 |
|
89 | 84 |
public void setWorkdays(int value) { |
90 | 85 |
value = validateValue(value); |
91 |
int dayOfWeek = this.dateFrom.get(Calendar.DAY_OF_WEEK);
|
|
86 |
Calendar currentDay = (Calendar) this.dateFrom.clone();
|
|
92 | 87 |
|
93 | 88 |
for (int i = 0; i < this.bitmap.length; i++) { |
94 |
if (dayOfWeek != 7 && dayOfWeek != 1) {
|
|
89 |
if (currentDay.get(Calendar.DAY_OF_WEEK) != 7 && currentDay.get(Calendar.DAY_OF_WEEK) != 1 && !isBankHoliday(currentDay)) {
|
|
95 | 90 |
this.bitmap[i] = value; |
96 | 91 |
} |
97 | 92 |
|
98 |
dayOfWeek++; |
|
99 |
if (dayOfWeek == 8) dayOfWeek = 1; |
|
93 |
currentDay.add(Calendar.DATE, 1); |
|
100 | 94 |
} |
101 | 95 |
} |
102 | 96 |
|
103 | 97 |
public void setSundaysAndHolidays(int value) { |
104 | 98 |
value = validateValue(value); |
105 |
int dayOfWeek = firstDayOfWeek;
|
|
99 |
Calendar currentDay = (Calendar) this.dateFrom.clone();
|
|
106 | 100 |
|
107 | 101 |
for (int i = 0; i < this.bitmap.length; i++) { |
108 |
if (dayOfWeek != 7) {
|
|
102 |
if (currentDay.get(Calendar.DAY_OF_WEEK) != 7) {
|
|
109 | 103 |
this.bitmap[i] = value; |
110 | 104 |
} |
111 | 105 |
|
112 |
dayOfWeek++; |
|
113 |
if (dayOfWeek == 8) dayOfWeek = 1; |
|
106 |
currentDay.add(Calendar.DATE, 1); |
|
114 | 107 |
} |
115 | 108 |
} |
116 | 109 |
|
... | ... | |
131 | 124 |
|
132 | 125 |
public void setDaysInRange(Calendar from, Calendar to, int value) { |
133 | 126 |
value = validateValue(value); |
134 |
int dayPositionFrom = (int) getDatePosition(from); |
|
135 |
int dayPositionTo = (int) getDatePosition(to); |
|
127 |
Calendar currentDay = (Calendar) this.dateFrom.clone(); |
|
128 |
to.add(Calendar.DATE, 1); |
|
129 |
from.add(Calendar.DATE, -1); |
|
130 |
|
|
131 |
for (int i = 0; i < this.bitmap.length; i++) { |
|
132 |
if (currentDay.after(from) && currentDay.before(to) && !isBankHoliday(currentDay)) { |
|
133 |
this.bitmap[i] = value; |
|
134 |
} |
|
136 | 135 |
|
137 |
for (int i = dayPositionFrom; i < dayPositionTo; i++) { |
|
138 |
bitmap[i] = value; |
|
136 |
currentDay.add(Calendar.DATE, 1); |
|
139 | 137 |
} |
140 | 138 |
|
141 | 139 |
} |
142 | 140 |
|
143 | 141 |
public void setDaysInWeek(int dayNumber, int value) { |
144 | 142 |
value = validateValue(value); |
145 |
int dayOfWeek = firstDayOfWeek;
|
|
143 |
Calendar currentDay = (Calendar) this.dateFrom.clone();
|
|
146 | 144 |
|
147 | 145 |
for (int i = 0; i < this.bitmap.length; i++) { |
148 |
if (dayOfWeek == dayNumber) {
|
|
146 |
if (currentDay.get(Calendar.DAY_OF_WEEK) == dayNumber) {
|
|
149 | 147 |
this.bitmap[i] = value; |
150 | 148 |
} |
151 | 149 |
|
152 |
dayOfWeek++; |
|
153 |
if (dayOfWeek == 8) dayOfWeek = 1; |
|
150 |
currentDay.add(Calendar.DATE, 1); |
|
154 | 151 |
} |
155 | 152 |
} |
156 | 153 |
|
157 |
|
|
158 |
// TODO: 04.05.2019 ?? Sude/Liche -- Platí pro víkendy ?? |
|
159 | 154 |
public void setWeeks(int value, int remainder) { |
160 | 155 |
value = validateValue(value); |
161 |
int dayOfWeek = this.dateFrom.get(Calendar.DAY_OF_WEEK); |
|
162 |
int weekNumber = this.dateFrom.get(Calendar.WEEK_OF_MONTH); |
|
156 |
Calendar currentDay = (Calendar) this.dateFrom.clone(); |
|
163 | 157 |
|
164 | 158 |
for (int i = 0; i < this.bitmap.length; i++) { |
165 |
if ((weekNumber % 2)==remainder) {
|
|
159 |
if ((currentDay.get(Calendar.WEEK_OF_YEAR)%2)==remainder) {
|
|
166 | 160 |
this.bitmap[i] = value; |
167 | 161 |
} |
168 | 162 |
|
169 |
dayOfWeek++; |
|
170 |
if (dayOfWeek == 8) dayOfWeek = 1; |
|
171 |
if (dayOfWeek == 2) weekNumber++; |
|
163 |
currentDay.add(Calendar.DATE, 1); |
|
172 | 164 |
|
173 | 165 |
} |
174 | 166 |
} |
175 | 167 |
|
176 | 168 |
|
177 | 169 |
public void setWeeksRange(Calendar from, Calendar to, int value, int remainder) { |
170 |
|
|
178 | 171 |
value = validateValue(value); |
179 |
int dayOfWeek = from.get(Calendar.DAY_OF_WEEK); |
|
180 |
int weekNumber = from.get(Calendar.WEEK_OF_MONTH); |
|
181 |
int dayPositionFrom = (int) getDatePosition(from); |
|
182 |
int dayPositionTo = (int) getDatePosition(to); |
|
172 |
Calendar currentDay = (Calendar) this.dateFrom.clone(); |
|
173 |
to.add(Calendar.DATE, 1); |
|
174 |
from.add(Calendar.DATE, -1); |
|
183 | 175 |
|
184 |
for (int i = dayPositionFrom; i < dayPositionTo; i++) { |
|
185 |
if ((weekNumber % 2)==remainder) { |
|
186 |
this.bitmap[i] = value; |
|
176 |
for (int i = 0; i < this.bitmap.length; i++) { |
|
177 |
if (currentDay.after(from) && currentDay.before(to)) { |
|
178 |
if ((currentDay.get(Calendar.WEEK_OF_YEAR)%2)==remainder) { |
|
179 |
this.bitmap[i] = value; |
|
180 |
} |
|
187 | 181 |
} |
188 | 182 |
|
189 |
dayOfWeek++; |
|
190 |
if (dayOfWeek == 8) dayOfWeek = 1; |
|
191 |
if (dayOfWeek == 2) weekNumber++; |
|
183 |
currentDay.add(Calendar.DATE, 1); |
|
192 | 184 |
} |
193 | 185 |
|
194 | 186 |
} |
195 | 187 |
|
196 |
// TODO: 04.05.2019 Kombinace (Sudé/Liché týdny + Časové kódy) |
|
188 |
public void unsetHolidays() { |
|
189 |
Calendar currentDay = (Calendar) this.dateFrom.clone(); |
|
190 |
|
|
191 |
for (int i = 0; i < this.bitmap.length; i++) { |
|
192 |
if (isBankHoliday(currentDay)) { |
|
193 |
this.bitmap[i] = 0; |
|
194 |
} |
|
195 |
|
|
196 |
currentDay.add(Calendar.DATE, 1); |
|
197 |
} |
|
198 |
} |
|
199 |
|
|
197 | 200 |
|
198 | 201 |
/** |
199 | 202 |
* Metoda naplní (přemaže) bitmapu nulami |
... | ... | |
218 | 221 |
return value; |
219 | 222 |
} |
220 | 223 |
|
224 |
public boolean isBankHoliday(Calendar cal) { |
|
225 |
|
|
226 |
int month = cal.get(Calendar.MONTH); |
|
227 |
int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH); |
|
228 |
|
|
229 |
// 1. ledna - Den obnovy samostatného českého státu | Nový rok |
|
230 |
if(month == Calendar.JANUARY && dayOfMonth == 1) { |
|
231 |
return true; |
|
232 |
} |
|
233 |
|
|
234 |
// 1. ledna - Den obnovy samostatného českého státu | Nový rok |
|
235 |
if(month == Calendar.JANUARY && dayOfMonth == 1) { |
|
236 |
return true; |
|
237 |
} |
|
238 |
|
|
239 |
// Velikonoční pondělí |
|
240 |
if(month == easterMonday.get(Calendar.MONTH) && dayOfMonth == easterMonday.get(Calendar.DAY_OF_MONTH)){ |
|
241 |
return true; |
|
242 |
} |
|
243 |
|
|
244 |
// Velký pátek |
|
245 |
if(month == goodFriday.get(Calendar.MONTH) && dayOfMonth == goodFriday.get(Calendar.DAY_OF_MONTH)){ |
|
246 |
return true; |
|
247 |
} |
|
248 |
|
|
249 |
// 1. května - Svátek práce |
|
250 |
if(month == Calendar.MAY && dayOfMonth == 1) { |
|
251 |
return true; |
|
252 |
} |
|
253 |
|
|
254 |
// 8. května - Den vítězství |
|
255 |
if(month == Calendar.MAY && dayOfMonth == 8) { |
|
256 |
return true; |
|
257 |
} |
|
258 |
|
|
259 |
// 5. července - Den slovanských věrozvěstů Cyrila a Metoděje |
|
260 |
if(month == Calendar.JULY && dayOfMonth == 5) { |
|
261 |
return true; |
|
262 |
} |
|
263 |
|
|
264 |
// 6. července - Den upálení mistra Jana Husa |
|
265 |
if(month == Calendar.JULY && dayOfMonth == 6) { |
|
266 |
return true; |
|
267 |
} |
|
268 |
|
|
269 |
// 28. září – Den české státnosti |
|
270 |
if(month == Calendar.SEPTEMBER && dayOfMonth == 28) { |
|
271 |
return true; |
|
272 |
} |
|
273 |
|
|
274 |
// 28. října – Den vzniku samostatného československého státu |
|
275 |
if(month == Calendar.OCTOBER && dayOfMonth == 28) { |
|
276 |
return true; |
|
277 |
} |
|
278 |
|
|
279 |
// 17. listopadu – Den boje za svobodu a demokracii |
|
280 |
if(month == Calendar.NOVEMBER && dayOfMonth == 17) { |
|
281 |
return true; |
|
282 |
} |
|
283 |
|
|
284 |
// 24. prosince – Štědrý den |
|
285 |
if(month == Calendar.DECEMBER && dayOfMonth == 24) { |
|
286 |
return true; |
|
287 |
} |
|
288 |
|
|
289 |
// 25. prosince – 1. svátek vánoční |
|
290 |
if(month == Calendar.DECEMBER && dayOfMonth == 25) { |
|
291 |
return true; |
|
292 |
} |
|
293 |
|
|
294 |
// 26. prosince – 2. svátek vánoční |
|
295 |
if(month == Calendar.DECEMBER && dayOfMonth == 26) { |
|
296 |
return true; |
|
297 |
} |
|
298 |
|
|
299 |
// Není svátek |
|
300 |
return false; |
|
301 |
|
|
302 |
} |
|
303 |
|
|
304 |
public void getEasterHolidays(int year) { |
|
305 |
int Y = year; |
|
306 |
int a = Y % 19; |
|
307 |
int b = Y / 100; |
|
308 |
int c = Y % 100; |
|
309 |
int d = b / 4; |
|
310 |
int e = b % 4; |
|
311 |
int f = (b + 8) / 25; |
|
312 |
int g = (b - f + 1) / 3; |
|
313 |
int h = (19 * a + b - d - g + 15) % 30; |
|
314 |
int i = c / 4; |
|
315 |
int k = c % 4; |
|
316 |
int L = (32 + 2 * e + 2 * i - h - k) % 7; |
|
317 |
int m = (a + 11 * h + 22 * L) / 451; |
|
318 |
int n = h + L - 7 * m + 114; |
|
319 |
int month = n / 31; |
|
320 |
int day = (n % 31) + 1; |
|
321 |
|
|
322 |
Calendar easterMonday = Calendar.getInstance(); |
|
323 |
//Velikonoční pondělí --> Velikonoční neděle + 1 |
|
324 |
easterMonday.setTime(new Date(year-1900, month-1, day+1)); |
|
325 |
//Velký pátek --> Velikonoční neděle - 2 |
|
326 |
Calendar goodFriday = Calendar.getInstance(); |
|
327 |
goodFriday.setTime(new Date(year-1900, month-1, day-2)); |
|
328 |
|
|
329 |
this.easterMonday = easterMonday; |
|
330 |
this.goodFriday = goodFriday; |
|
331 |
} |
|
332 |
|
|
333 |
public String getBitmapString() { |
|
334 |
return Arrays.toString(this.bitmap).replaceAll("\\[|\\]|,|\\s", ""); |
|
335 |
} |
|
336 |
|
|
221 | 337 |
public Calendar getDateFrom() { |
222 | 338 |
return dateFrom; |
223 | 339 |
} |
... | ... | |
242 | 358 |
this.lineNumber = lineNumber; |
243 | 359 |
} |
244 | 360 |
|
245 |
public String getConnectionNumber() { |
|
246 |
return connectionNumber; |
|
247 |
} |
|
248 |
|
|
249 |
public void setConnectionNumber(String connectionNumber) { |
|
250 |
this.connectionNumber = connectionNumber; |
|
251 |
} |
|
252 |
|
|
253 | 361 |
public int[] getBitmap() { |
254 | 362 |
return bitmap; |
255 | 363 |
} |
... | ... | |
258 | 366 |
this.bitmap = bitmap; |
259 | 367 |
} |
260 | 368 |
|
261 |
public int getFirstDayOfWeek() { |
|
262 |
return firstDayOfWeek; |
|
263 |
} |
|
264 |
|
|
265 |
public void setFirstDayOfWeek(int firstDayOfWeek) { |
|
266 |
this.firstDayOfWeek = firstDayOfWeek; |
|
267 |
} |
|
268 |
|
|
269 | 369 |
@Override |
270 | 370 |
public String toString() { |
271 | 371 |
return Arrays.toString(this.bitmap); |
... | ... | |
287 | 387 |
dateTo.setTime(new Date(2019-1900, 4, 31)); // rok udáván od 1900, měsíc se počítá od 0 |
288 | 388 |
|
289 | 389 |
|
290 |
Bitmap bitmap = new Bitmap(dateFrom, dateTo, "143440", "1");
|
|
390 |
Bitmap bitmap = new Bitmap(dateFrom, dateTo, "143440"); |
|
291 | 391 |
|
292 | 392 |
|
293 | 393 |
// ------------- KONTROLNÍ VÝPISY ----------------- |
294 | 394 |
System.out.println("------------- KONTROLNÍ VÝPISY -----------------"); |
295 |
System.out.println("Linka: "+ bitmap.getLineNumber()+" - Spoj:"+bitmap.getConnectionNumber());
|
|
395 |
System.out.println("Linka: "+ bitmap.getLineNumber()); |
|
296 | 396 |
System.out.println("Datum: od: " + bitmap.getDateFrom().getTime() + " | do: " + bitmap.getDateTo().getTime()); |
297 |
System.out.println("První den je: "+bitmap.getFirstDayOfWeek() + " (1 - Neděle; 2 - Pondělí; 3 - Úterý; 4 - Středa; 5 - Čtvrtek; 6 - Pátek; 7 - Sobota)");
|
|
397 |
System.out.println("První den je: "+bitmap.getDateFrom().get(Calendar.DAY_OF_WEEK) + " (1 - Neděle; 2 - Pondělí; 3 - Úterý; 4 - Středa; 5 - Čtvrtek; 6 - Pátek; 7 - Sobota)");
|
|
298 | 398 |
System.out.println("Počet dní v rozmezí: " + bitmap.getDateRange()); |
299 | 399 |
System.out.println(bitmap.toString()); |
300 | 400 |
|
... | ... | |
331 | 431 |
bitmap.setWeeks(1, 1); |
332 | 432 |
System.out.println(bitmap.toString()); |
333 | 433 |
|
334 |
|
|
434 |
//Velikonoce pro svátky |
|
435 |
System.out.println("Velikonoční pondělí: " + bitmap.easterMonday.getTime()); |
|
436 |
System.out.println("Velký pátek: " + bitmap.goodFriday.getTime()); |
|
335 | 437 |
|
336 | 438 |
|
337 | 439 |
} |
src/data/BitmapBuilder.java | ||
---|---|---|
1 | 1 |
package data; |
2 | 2 |
|
3 |
import gui.Window; |
|
4 |
|
|
5 |
import java.io.BufferedWriter; |
|
3 | 6 |
import java.io.File; |
7 |
import java.io.IOException; |
|
8 |
import java.nio.charset.Charset; |
|
9 |
import java.nio.file.Files; |
|
10 |
import java.nio.file.Path; |
|
11 |
import java.nio.file.StandardOpenOption; |
|
12 |
import java.text.SimpleDateFormat; |
|
4 | 13 |
import java.util.ArrayList; |
5 |
|
|
6 |
import gui.Window;
|
|
14 |
import java.util.Arrays; |
|
15 |
import java.util.Calendar;
|
|
7 | 16 |
|
8 | 17 |
public class BitmapBuilder { |
9 | 18 |
|
10 | 19 |
ArrayList<JDFPevnykodRecord> pevnykod = new ArrayList<>(); |
11 | 20 |
ArrayList<JDFCaskodyRecord> caskody = new ArrayList<>(); |
12 | 21 |
ArrayList<JDFSpojeRecord> spoje = new ArrayList<>(); |
22 |
String[] lineList; |
|
23 |
Path outputFile; |
|
13 | 24 |
|
14 | 25 |
private Window window; |
15 | 26 |
|
16 |
public BitmapBuilder(Window window){ |
|
27 |
public BitmapBuilder(Window window, File outputPath){
|
|
17 | 28 |
this.window = window; |
18 | 29 |
window.printMessage("Vytvořen BitmapBuilder"); |
30 |
|
|
31 |
|
|
32 |
// Vytvoření výstupního souboru |
|
33 |
this.outputFile = outputPath.toPath(); |
|
34 |
try { |
|
35 |
if (Files.notExists(outputFile)) { |
|
36 |
Files.createFile(outputFile); |
|
37 |
window.printMessage("Vytvořen soubor: "+outputFile.toString()); |
|
38 |
} |
|
39 |
else { |
|
40 |
window.printMessage("Výstupní soubor již existuje, přepisuji..."); |
|
41 |
Files.deleteIfExists(outputFile); |
|
42 |
Files.createFile(outputFile); |
|
43 |
} |
|
44 |
|
|
45 |
} catch (IOException e) { |
|
46 |
e.printStackTrace(); |
|
47 |
} |
|
19 | 48 |
} |
20 | 49 |
|
21 |
/**
|
|
50 |
/* |
|
22 | 51 |
* |
23 | 52 |
* hlavni metoda pro ozkouseni funkcnosti {@code BitmapBuilder} |
24 | 53 |
*-issue #7314 |
... | ... | |
52 | 81 |
pevnykodRecord = new JDFPevnykodRecord(record); |
53 | 82 |
pevnykod.add(pevnykodRecord); |
54 | 83 |
} |
84 |
window.printMessage("Načten soubor Pevnykod.txt"); |
|
55 | 85 |
} |
56 | 86 |
|
57 | 87 |
public void getCaskody(ArrayList<String[]> loadedData){ |
... | ... | |
60 | 90 |
caskodyRecord = new JDFCaskodyRecord(record); |
61 | 91 |
caskody.add(caskodyRecord); |
62 | 92 |
} |
93 |
window.printMessage("Načten soubor Caskody.txt"); |
|
63 | 94 |
} |
64 | 95 |
|
65 | 96 |
public void getSpoje(ArrayList<String[]> loadedData){ |
... | ... | |
68 | 99 |
spojeRecord = new JDFSpojeRecord(record); |
69 | 100 |
spoje.add(spojeRecord); |
70 | 101 |
} |
102 |
window.printMessage("Načten soubor Spoje.txt"); |
|
103 |
} |
|
104 |
|
|
105 |
public void getLineList(String[] lines){ |
|
106 |
this.lineList = lines; |
|
107 |
window.printMessage("Načten uživatelský seznam linek"); |
|
108 |
window.printMessage("Nalezené linky: "+ Arrays.toString(lineList)); |
|
109 |
} |
|
110 |
|
|
111 |
public void writeBitmaps(Calendar dateFrom, Calendar dateTo) { |
|
112 |
try(BufferedWriter writer = Files.newBufferedWriter(outputFile, Charset.defaultCharset(), StandardOpenOption.APPEND)) { |
|
113 |
SimpleDateFormat format = new SimpleDateFormat("d.M.yyyy"); |
|
114 |
String formatedDateFrom = format.format(dateFrom.getTime()); |
|
115 |
String formatedDateTo = format.format(dateTo.getTime()); |
|
116 |
writer.write("Období;" + formatedDateFrom + ";" + formatedDateTo + "\n\n"); |
|
117 |
|
|
118 |
for (int i = 0; i < lineList.length ; i++) { |
|
119 |
|
|
120 |
|
|
121 |
Bitmap generatedBitmap = new Bitmap(dateFrom, dateTo, lineList[i]); |
|
122 |
|
|
123 |
// TODO: 10.05.2019 Logika procházení seznamu CASKODY | SPOJE | PEVNYKOD -> generování správných bitmap |
|
124 |
|
|
125 |
|
|
126 |
for (JDFCaskodyRecord caskod : caskody) { |
|
127 |
if(caskod.getNumberLine().equals(lineList[i])) { |
|
128 |
writer.write(generatedBitmap.getLineNumber()+caskod.getNumberLineVersion()+"-"+caskod.getTimeCode()); |
|
129 |
writer.write("-X;;"+generatedBitmap.getBitmapString()+"\n"); |
|
130 |
} |
|
131 |
} |
|
132 |
|
|
133 |
|
|
134 |
} |
|
135 |
|
|
136 |
} catch (IOException e) { |
|
137 |
e.printStackTrace(); |
|
138 |
} |
|
71 | 139 |
} |
72 | 140 |
|
73 | 141 |
} |
src/data/DataLoader.java | ||
---|---|---|
1 | 1 |
package data; |
2 | 2 |
|
3 | 3 |
import java.io.*; |
4 |
import java.nio.charset.Charset; |
|
5 |
import java.nio.file.Files; |
|
4 | 6 |
import java.util.ArrayList; |
7 |
import java.util.List; |
|
5 | 8 |
|
6 | 9 |
/** |
7 | 10 |
* |
... | ... | |
115 | 118 |
return loadedData; |
116 | 119 |
} |
117 | 120 |
|
121 |
/** |
|
122 |
* Načte seznam linek z uživatelského soubor a vrátí jej jako pole řetězců |
|
123 |
* |
|
124 |
* @param lineFile cesta k uživatelskému souboru se seznamem linek |
|
125 |
*/ |
|
126 |
public String[] loadLines(File lineFile) { |
|
127 |
|
|
128 |
List<String> linkList = null; |
|
129 |
Charset charset = Charset.defaultCharset(); |
|
130 |
|
|
131 |
//soubor |
|
132 |
File file = lineFile; |
|
133 |
if(!file.isFile()){ |
|
134 |
System.out.println("Soubor neexistuje.."); |
|
135 |
return null; |
|
136 |
} |
|
137 |
|
|
138 |
//nastavení atributů |
|
139 |
setAttributes(file, fileName); |
|
140 |
|
|
141 |
|
|
142 |
try { |
|
143 |
linkList = Files.readAllLines(file.toPath(), charset); |
|
144 |
} catch (IOException e) { |
|
145 |
e.printStackTrace(); |
|
146 |
} |
|
147 |
|
|
148 |
return linkList.toArray(new String[]{}); |
|
149 |
} |
|
150 |
|
|
118 | 151 |
/**, |
119 | 152 |
* Nastavení zbývajících atributů pro DataLoader |
120 | 153 |
* @param file instance souboru |
src/data/JDFCaskodyRecord.java | ||
---|---|---|
25 | 25 |
private final int startDateIndex = 5; |
26 | 26 |
/** konstanta indexu: endDate */ |
27 | 27 |
private final int endDateIndex = 6; |
28 |
/** konstanta indexu: numberLineVersion */ |
|
29 |
private final int numberLineVersionIndex = 8; |
|
28 | 30 |
|
29 | 31 |
//-------------- Atributy --------------/ |
30 | 32 |
private String numberLine; |
... | ... | |
34 | 36 |
private String typeTimeCode; |
35 | 37 |
private String startDate; |
36 | 38 |
private String endDate; |
39 |
private String numberLineVersion; |
|
37 | 40 |
|
38 | 41 |
//-------------- Konstruktor -------------/ |
39 | 42 |
|
... | ... | |
103 | 106 |
return endDate; |
104 | 107 |
} |
105 | 108 |
|
109 |
/** |
|
110 |
* Metoda vrátí cislo verze linky |
|
111 |
* @return cislo verze linky |
|
112 |
*/ |
|
113 |
public String getNumberLineVersion() { |
|
114 |
return numberLineVersion; |
|
115 |
} |
|
116 |
|
|
106 | 117 |
/** |
107 | 118 |
* V metodě se přečte jeden záznam dat a rozřadí do určitých atributů - atributy bude možné dále využívat |
108 | 119 |
* -issue #7319 |
... | ... | |
133 | 144 |
case endDateIndex: |
134 | 145 |
this.endDate = dataRecord[index]; |
135 | 146 |
break; |
147 |
case numberLineVersionIndex: |
|
148 |
this.numberLineVersion = dataRecord[index]; |
|
149 |
break; |
|
136 | 150 |
} |
137 | 151 |
} |
138 | 152 |
} |
src/gui/Window.java | ||
---|---|---|
4 | 4 |
import java.awt.Dimension; |
5 | 5 |
import java.awt.FlowLayout; |
6 | 6 |
import java.awt.GridLayout; |
7 |
import java.awt.event.ActionEvent; |
|
8 |
import java.awt.event.ActionListener; |
|
7 |
import java.awt.event.*; |
|
9 | 8 |
|
10 | 9 |
import java.io.File; |
11 | 10 |
import java.text.DateFormat; |
12 | 11 |
import java.text.ParseException; |
13 | 12 |
import java.text.SimpleDateFormat; |
14 |
import java.util.ArrayList; |
|
15 |
import java.util.Calendar; |
|
16 |
import java.util.Date; |
|
17 |
import java.util.Properties; |
|
13 |
import java.util.*; |
|
18 | 14 |
|
19 |
import javax.swing.JButton; |
|
20 |
import javax.swing.JFileChooser; |
|
15 |
import javax.swing.*; |
|
21 | 16 |
import javax.swing.JFormattedTextField.AbstractFormatter; |
22 |
import javax.swing.JFrame; |
|
23 |
import javax.swing.JLabel; |
|
24 |
import javax.swing.JOptionPane; |
|
25 |
import javax.swing.JPanel; |
|
26 |
import javax.swing.JScrollPane; |
|
27 |
import javax.swing.JTextArea; |
|
28 |
import javax.swing.JTextField; |
|
29 | 17 |
|
30 | 18 |
import org.jdatepicker.impl.JDatePanelImpl; |
31 | 19 |
import org.jdatepicker.impl.JDatePickerImpl; |
... | ... | |
113 | 101 |
/**Dialog pro vybrani data konce*/ |
114 | 102 |
private JDatePickerImpl datePickerTo; |
115 | 103 |
|
116 |
/**TextField pro zobrazeni cesty k souboru se spojema*/
|
|
104 |
/**TextField pro zobrazeni cesty k souboru s linkami*/
|
|
117 | 105 |
private JTextField linkyPathTF; |
118 | 106 |
|
119 | 107 |
/**TextField pro zobrazeni cesty k slozce JDF*/ |
... | ... | |
136 | 124 |
* inicializuje okno, jmenovite jeho panely, komponenty, priradi potrebne listenery a prida je do zobrazeni |
137 | 125 |
*/ |
138 | 126 |
public Window(){ |
139 |
super("POVED"); |
|
127 |
super("POVED - Generování Bitových map");
|
|
140 | 128 |
this.setLayout(new BorderLayout()); |
141 | 129 |
this.setDefaultCloseOperation(EXIT_ON_CLOSE); |
142 | 130 |
|
... | ... | |
148 | 136 |
JPanel jdfPathP = new JPanel(); |
149 | 137 |
JPanel outputP = new JPanel(); |
150 | 138 |
inputP.setLayout(new GridLayout(5, 1)); |
139 |
ImageIcon icon = new ImageIcon(Window.class.getResource("/resources/poved.png")); |
|
140 |
ImageIcon logo = new ImageIcon(Window.class.getResource("/resources/logo.png")); |
|
141 |
this.setIconImage(icon.getImage()); |
|
151 | 142 |
dateFromP.setLayout(new FlowLayout()); |
152 | 143 |
dateToP.setLayout(new FlowLayout()); |
153 | 144 |
spojPathP.setLayout(new FlowLayout()); |
... | ... | |
155 | 146 |
outputP.setLayout(new FlowLayout()); |
156 | 147 |
|
157 | 148 |
//inicializace kompoment |
158 |
JLabel povedLB = new JLabel("POVED", JLabel.CENTER);
|
|
149 |
JLabel povedLB = new JLabel(logo, JLabel.CENTER);
|
|
159 | 150 |
JLabel dateFromLB = new JLabel("Obdobi od: "); |
160 | 151 |
JLabel dateToLB = new JLabel ("Obdobi do: "); |
161 |
JLabel spojPathLB = new JLabel("Spoje: ");
|
|
152 |
JLabel seznamLinekPathLB = new JLabel("Seznam linek: ");
|
|
162 | 153 |
JLabel jdfPathLB = new JLabel("JDF: "); |
163 | 154 |
JLabel outputLB = new JLabel("Vystup: "); |
164 | 155 |
confirmBT = new JButton("Potvrdit"); |
165 | 156 |
endBT = new JButton("Ukoncit"); |
166 |
JButton spojBT = new JButton("Vybrat spoj soubor");
|
|
157 |
JButton seznamLinekBT = new JButton("Vybrat seznam linek");
|
|
167 | 158 |
JButton jdfBT = new JButton("Vybrat JDF slozku"); |
168 | 159 |
JButton outputBT = new JButton("Vybrat vystupni slozku"); |
169 | 160 |
linkyPathTF = new JTextField(TEXT_FIELD_LENGTH); |
... | ... | |
180 | 171 |
jdfPathTF.setEditable(false); |
181 | 172 |
outputPathTF.setEditable(false); |
182 | 173 |
outputNameTF.setText("Nazev souboru"); |
174 |
outputNameTF.addMouseListener(new MouseAdapter() { |
|
175 |
@Override |
|
176 |
public void mouseClicked(MouseEvent e) { |
|
177 |
if (outputNameTF.getText().trim().equals("Nazev souboru") ) outputNameTF.setText(""); |
|
178 |
} |
|
179 |
}); |
|
183 | 180 |
infoTA.setEditable(false); |
184 | 181 |
fileChooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); |
185 | 182 |
|
... | ... | |
198 | 195 |
System.exit(0); |
199 | 196 |
} |
200 | 197 |
}); |
201 |
spojBT.addActionListener(new FileChooserListener(SEZNAM_LINEK_FILE));
|
|
198 |
seznamLinekBT.addActionListener(new FileChooserListener(SEZNAM_LINEK_FILE));
|
|
202 | 199 |
jdfBT.addActionListener(new FileChooserListener(JDF_DIR)); |
203 | 200 |
outputBT.addActionListener(new FileChooserListener(OUTPUT_DIR)); |
204 | 201 |
|
... | ... | |
212 | 209 |
dateFromP.add(datePickerFrom); |
213 | 210 |
dateToP.add(dateToLB); |
214 | 211 |
dateToP.add(datePickerTo); |
215 |
spojPathP.add(spojPathLB);
|
|
212 |
spojPathP.add(seznamLinekPathLB);
|
|
216 | 213 |
spojPathP.add(linkyPathTF); |
217 |
spojPathP.add(spojBT);
|
|
214 |
spojPathP.add(seznamLinekBT);
|
|
218 | 215 |
jdfPathP.add(jdfPathLB); |
219 | 216 |
jdfPathP.add(jdfPathTF); |
220 | 217 |
jdfPathP.add(jdfBT); |
... | ... | |
239 | 236 |
private void initDatePicker(){ |
240 | 237 |
UtilDateModel modelFrom = new UtilDateModel(); |
241 | 238 |
Properties pFrom = new Properties(); |
242 |
pFrom.put("text.today", "Today");
|
|
243 |
pFrom.put("text.month", "Month");
|
|
244 |
pFrom.put("text.year", "Year");
|
|
239 |
pFrom.put("text.today", "Dnes");
|
|
240 |
pFrom.put("text.month", "Měsíc");
|
|
241 |
pFrom.put("text.year", "Rok");
|
|
245 | 242 |
UtilDateModel modelTo = new UtilDateModel(); |
246 | 243 |
Properties pTo = new Properties(); |
247 |
pTo.put("text.today", "Today");
|
|
248 |
pTo.put("text.month", "Month");
|
|
249 |
pTo.put("text.year", "Year");
|
|
244 |
pTo.put("text.today", "Dnes");
|
|
245 |
pTo.put("text.month", "Měsíc");
|
|
246 |
pTo.put("text.year", "Rok");
|
|
250 | 247 |
JDatePanelImpl datePanelFrom = new JDatePanelImpl(modelFrom, pFrom); |
251 | 248 |
JDatePanelImpl datePanelTo = new JDatePanelImpl(modelTo, pTo); |
252 | 249 |
datePickerFrom = new JDatePickerImpl(datePanelFrom, new DateLabelFormatter()); |
... | ... | |
281 | 278 |
} |
282 | 279 |
|
283 | 280 |
private BitmapBuilder createBitmapBuilder(){ |
284 |
return new BitmapBuilder(this); |
|
281 |
return new BitmapBuilder(this, outputFile);
|
|
285 | 282 |
} |
286 | 283 |
|
287 | 284 |
/** |
... | ... | |
306 | 303 |
return; |
307 | 304 |
} |
308 | 305 |
changeToInfo(); |
306 |
|
|
307 |
|
|
308 |
printMessage("Nastaveno období od: " + dateFrom.getTime()); |
|
309 |
printMessage("Nastaveno období do: " + dateTo.getTime()); |
|
310 |
printMessage("Vybrán soubor s linkami: " + linkyFile.toString()); |
|
311 |
printMessage("Vybrán adresář s JDF soubory: " + jdfDir.toString()); |
|
312 |
printMessage("Výstupní soubor nastaven na: " + outputFile.toString()); |
|
313 |
|
|
314 |
|
|
309 | 315 |
ArrayList<String[]> loadedData; |
310 | 316 |
|
311 | 317 |
BitmapBuilder bitmapBuilder = createBitmapBuilder(); |
... | ... | |
313 | 319 |
DataLoader loader = new DataLoader(jdfDir); |
314 | 320 |
|
315 | 321 |
//načítání konkrétních dat |
322 |
|
|
323 |
String[] lineList = loader.loadLines(linkyFile); |
|
324 |
bitmapBuilder.getLineList(lineList); |
|
325 |
|
|
316 | 326 |
loadedData = loader.loadData(PEVNY_KOD); |
317 | 327 |
bitmapBuilder.getPevnyKod(loadedData); |
318 | 328 |
|
... | ... | |
323 | 333 |
loadedData.clear(); |
324 | 334 |
loadedData = loader.loadData(SPOJE); |
325 | 335 |
bitmapBuilder.getSpoje(loadedData); |
336 |
|
|
337 |
printMessage("Zapisuji bitmapy.."); |
|
338 |
bitmapBuilder.writeBitmaps(dateFrom, dateTo); |
|
339 |
|
|
326 | 340 |
printMessage("Ukončuji program.."); |
327 | 341 |
|
328 | 342 |
} |
src/test/testBitmap.java | ||
---|---|---|
38 | 38 |
dateTo.setTime(new Date(2019-1900, 4, 31)); // rok udáván od 1900, měsíc se počítá od 0 |
39 | 39 |
|
40 | 40 |
|
41 |
bitmap = new Bitmap(dateFrom, dateTo, "143440", "1");
|
|
41 |
bitmap = new Bitmap(dateFrom, dateTo, "143440"); |
|
42 | 42 |
|
43 | 43 |
} |
44 | 44 |
|
... | ... | |
70 | 70 |
@Test |
71 | 71 |
public void testsetWorkdays() { |
72 | 72 |
bitmap.setWorkdays(1); |
73 |
assertEquals(0,bitmap.toString().compareToIgnoreCase("[1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1]")); |
|
73 |
// Přidáný svátky |
|
74 |
assertEquals(0,bitmap.toString().compareToIgnoreCase("[0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1]")); |
|
74 | 75 |
} |
75 | 76 |
|
76 | 77 |
@Test |
... | ... | |
96 | 97 |
Calendar date2 = Calendar.getInstance(); |
97 | 98 |
date2.setTime(new Date(2019-1900, 4, 5)); |
98 | 99 |
bitmap.setDaysInRange(date1,date2, 1); |
99 |
//Kromě 5.4. - má být dobře?
|
|
100 |
assertEquals(0,bitmap.toString().compareToIgnoreCase("[0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
|
|
100 |
// Opravdu chyba (poslední den včetně) - Opraveno
|
|
101 |
assertEquals(0,bitmap.toString().compareToIgnoreCase("[0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
|
|
101 | 102 |
} |
102 | 103 |
|
103 | 104 |
@Test |
... | ... | |
110 | 111 |
@Test |
111 | 112 |
public void testsetWeeks(){ |
112 | 113 |
bitmap.setWeeks(1, 1); |
113 |
assertEquals(0,bitmap.toString().compareToIgnoreCase("[1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1]"));
|
|
114 |
assertEquals(0,bitmap.toString().compareToIgnoreCase("[0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0]"));
|
|
114 | 115 |
|
115 | 116 |
} |
116 | 117 |
|
... | ... | |
121 | 122 |
Calendar date2 = Calendar.getInstance(); |
122 | 123 |
date2.setTime(new Date(2019-1900, 4, 13)); |
123 | 124 |
bitmap.setWeeksRange(date1,date2, 1, 1); |
124 |
assertEquals(0,bitmap.toString().compareToIgnoreCase("[1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
|
|
125 |
assertEquals(0,bitmap.toString().compareToIgnoreCase("[0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]"));
|
|
125 | 126 |
|
126 | 127 |
} |
127 | 128 |
|
... | ... | |
181 | 182 |
assertEquals(0,bitmap.getLineNumber().compareToIgnoreCase("143441")); |
182 | 183 |
} |
183 | 184 |
|
184 |
@Test |
|
185 |
public void testgetConnectionNumber() { |
|
186 |
assertEquals(0,bitmap.getConnectionNumber().compareToIgnoreCase("1")); |
|
187 |
} |
|
188 |
|
|
189 |
@Test |
|
190 |
public void testsetConnectionNumber() { |
|
191 |
bitmap.setConnectionNumber("2"); |
|
192 |
assertEquals(0,bitmap.getConnectionNumber().compareToIgnoreCase("2")); |
|
193 |
} |
|
194 |
|
|
195 | 185 |
@Test |
196 | 186 |
public void testgetBitmap() { |
197 | 187 |
int[] array = new int[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; |
... | ... | |
206 | 196 |
assertArrayEquals(array, bitmap.getBitmap()); |
207 | 197 |
this.bitmap = bitmap; |
208 | 198 |
} |
209 |
|
|
210 |
@Test |
|
211 |
public void testgetFirstDayOfWeek() { |
|
212 |
assertEquals(4,bitmap.getFirstDayOfWeek()); |
|
213 |
} |
|
214 |
|
|
215 |
@Test |
|
216 |
public void testsetFirstDayOfWeek() { |
|
217 |
bitmap.setFirstDayOfWeek(5); |
|
218 |
assertEquals(5,bitmap.getFirstDayOfWeek()); |
|
219 |
} |
|
220 | 199 |
|
221 | 200 |
@Test |
222 | 201 |
public void testtoString() { |
Také k dispozici: Unified diff
Propojení tříd, Vytváření a naplnění výstup. souborů, funkcionalita svátků, uživ. seznam linek, úpravy existujících metod a testů, QoL improvements (Re #7419)