commit cbd6adb3a7f15b8f5f6d6437b6f1ca5e0861f429
Author: Daniel Stuš <stusd@students.zcu.cz>
Date:   Sat May 4 00:46:12 2019 +0200

    Vytvoření třídy Bitmap + základní metody pro operace s Bitmapou (Re #7374)

diff --git a/src/data/Bitmap.java b/src/data/Bitmap.java
new file mode 100644
index 0000000..0bb61cf
--- /dev/null
+++ b/src/data/Bitmap.java
@@ -0,0 +1,329 @@
+package data;
+
+import java.time.LocalDate;
+import java.time.ZoneId;
+import java.time.temporal.ChronoUnit;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Date;
+
+//------ TO-DO LIST ----
+// TODO: 04.05.2019 JavaDoc - Dokumentace
+
+/**
+ *
+ * Trida uchovavajici informace a umoznujici praci s bitmapou
+ *
+ * @author  Daniel Stus, Marek Sobota, Lukas Scurko, Jan Jirman
+ * @version 0.5
+ *
+ */
+public class Bitmap {
+
+    //-------------- Atributy --------------/
+
+    /** Atribut -  Datum zacatku obdobi */
+    private Calendar dateFrom;
+
+    /** Atribut -  Datum konce obdobi */
+    private Calendar dateTo;
+
+    /** Atribut s cislem linky pro kterou je generovana bitmapa */
+    private String lineNumber;
+
+    /** Atribut s cislem spoje linky pro kterou je generovana bitmapa */
+    private String connectionNumber;
+
+    /** Pole uchovavajici bitmapu */
+    private int[] bitmap;
+
+    /** Atribut uchovavajici hodnotu dne (ktery den v tydnu odpovida) pocatku obdobi */
+    private int firstDayOfWeek;
+
+
+    //-------------- Konstruktor -------------/
+
+    /**
+     * Konstruktor incializuje a nastavuje důležité parametry tridy (@code Bitmap)
+     *
+     * @param dateFrom Datum zacatku obdobi
+     * @param dateTo Datum konce obdobi
+     * @param lineNumber Cislo linky
+     * @param connectionNumber Cislo spoje dane linky
+     */
+    public Bitmap(Calendar dateFrom, Calendar dateTo, String lineNumber, String connectionNumber) {
+        this.dateFrom = dateFrom;
+        this.dateTo = dateTo;
+        this.lineNumber = lineNumber;
+        this.connectionNumber = connectionNumber;
+        this.bitmap = new int[(int) getDateRange()];
+        this.firstDayOfWeek = dateFrom.get(Calendar.DAY_OF_WEEK);
+    }
+
+
+    //----------------- Metody ----------------/
+
+    /**
+     * Metda vrací počet dní uživatelem zvoleného období
+     *
+     * @return Počet dní v uživatelem zvoleném období (rozmezí)
+     */
+    public long getDateRange() {
+        LocalDate from = this.dateFrom.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
+        LocalDate to = this.dateTo.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
+
+        long noOfDaysBetween = ChronoUnit.DAYS.between(from, to);
+        return noOfDaysBetween+1;
+    }
+
+    public long getDatePosition(Calendar date) {
+        LocalDate from = this.dateFrom.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
+        LocalDate to = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
+
+        long datePosition = ChronoUnit.DAYS.between(from, to);
+        return datePosition+1;
+    }
+
+
+    public void setWorkdays(int value) {
+        value = validateValue(value);
+        int dayOfWeek = this.dateFrom.get(Calendar.DAY_OF_WEEK);
+
+        for (int i = 0; i < this.bitmap.length; i++) {
+            if (dayOfWeek != 7 && dayOfWeek != 1) {
+                this.bitmap[i] = value;
+            }
+
+            dayOfWeek++;
+            if (dayOfWeek == 8) dayOfWeek = 1;
+        }
+    }
+
+    public void setSundaysAndHolidays(int value) {
+        value = validateValue(value);
+        int dayOfWeek = firstDayOfWeek;
+
+        for (int i = 0; i < this.bitmap.length; i++) {
+            if (dayOfWeek != 7) {
+                this.bitmap[i] = value;
+            }
+
+            dayOfWeek++;
+            if (dayOfWeek == 8) dayOfWeek = 1;
+        }
+    }
+
+    public void setDay(Calendar day, int value) {
+        value = validateValue(value);
+        int dayPosition = (int) getDatePosition(day);
+
+        bitmap[dayPosition] = value;
+    }
+
+
+    public void setOneDayOnly(Calendar day) {
+        fillWithZeros();
+        int dayPosition = (int) getDatePosition(day);
+
+        bitmap[dayPosition] = 1;
+    }
+
+    public void setDaysInRange(Calendar from, Calendar to, int value) {
+        value = validateValue(value);
+        int dayPositionFrom = (int) getDatePosition(from);
+        int dayPositionTo = (int) getDatePosition(to);
+
+        for (int i = dayPositionFrom; i < dayPositionTo; i++) {
+            bitmap[i] = value;
+        }
+
+    }
+
+    public void setDaysInWeek(int dayNumber, int value) {
+        value = validateValue(value);
+        int dayOfWeek = firstDayOfWeek;
+
+        for (int i = 0; i < this.bitmap.length; i++) {
+            if (dayOfWeek == dayNumber) {
+                this.bitmap[i] = value;
+            }
+
+            dayOfWeek++;
+            if (dayOfWeek == 8) dayOfWeek = 1;
+        }
+    }
+
+
+    // TODO: 04.05.2019 ?? Sude/Liche -- Platí pro víkendy ?? 
+    public void setWeeks(int value, int remainder) {
+        value = validateValue(value);
+        int dayOfWeek =  this.dateFrom.get(Calendar.DAY_OF_WEEK);
+        int weekNumber = this.dateFrom.get(Calendar.WEEK_OF_MONTH);
+
+        for (int i = 0; i < this.bitmap.length; i++) {
+            if ((weekNumber % 2)==remainder) {
+                this.bitmap[i] = value;
+            }
+
+            dayOfWeek++;
+            if (dayOfWeek == 8) dayOfWeek = 1;
+            if (dayOfWeek == 2) weekNumber++;
+
+        }
+    }
+
+
+    public void setWeeksRange(Calendar from, Calendar to, int value, int remainder) {
+        value = validateValue(value);
+        int dayOfWeek =  from.get(Calendar.DAY_OF_WEEK);
+        int weekNumber = from.get(Calendar.WEEK_OF_MONTH);
+        int dayPositionFrom = (int) getDatePosition(from);
+        int dayPositionTo = (int) getDatePosition(to);
+
+        for (int i = dayPositionFrom; i < dayPositionTo; i++) {
+            if ((weekNumber % 2)==remainder) {
+                this.bitmap[i] = value;
+            }
+
+            dayOfWeek++;
+            if (dayOfWeek == 8) dayOfWeek = 1;
+            if (dayOfWeek == 2) weekNumber++;
+        }
+
+    }
+
+    // TODO: 04.05.2019 Kombinace (Sudé/Liché týdny + Časové kódy) 
+
+    /**
+     * Metoda naplní (přemaže) bitmapu nulami
+     */
+    public void fillWithZeros() {
+        Arrays.fill(this.bitmap, 0);
+    }
+
+    /**
+     * Metoda overuje spravnost zadane hodnoty
+     * - do bitmapy lze zadat pouze 1 nebo 0
+     * - v pripade ze uzivatel zada cislo vetsi nez jedna metoda vrati jednotku
+     * - v pripade ze uzivatel zada cislo mensi nez nula metoda vrati nulu
+     *
+     * @param value Uzivatelem zadana hodnota
+     * @return Nova (spravna hodnota) ukladajici se do bitmapy
+     */
+    public static int validateValue(int value) {
+        if (value < 0) value = 0;
+        else if (value > 0) value = 1;
+        else return value;
+        return value;
+    }
+
+    public Calendar getDateFrom() {
+        return dateFrom;
+    }
+
+    public void setDateFrom(Calendar dateFrom) {
+        this.dateFrom = dateFrom;
+    }
+
+    public Calendar getDateTo() {
+        return dateTo;
+    }
+
+    public void setDateTo(Calendar dateTo) {
+        this.dateTo = dateTo;
+    }
+
+    public String getLineNumber() {
+        return lineNumber;
+    }
+
+    public void setLineNumber(String lineNumber) {
+        this.lineNumber = lineNumber;
+    }
+
+    public String getConnectionNumber() {
+        return connectionNumber;
+    }
+
+    public void setConnectionNumber(String connectionNumber) {
+        this.connectionNumber = connectionNumber;
+    }
+
+    public int[] getBitmap() {
+        return bitmap;
+    }
+
+    public void setBitmap(int[] bitmap) {
+        this.bitmap = bitmap;
+    }
+
+    public int getFirstDayOfWeek() {
+        return firstDayOfWeek;
+    }
+
+    public void setFirstDayOfWeek(int firstDayOfWeek) {
+        this.firstDayOfWeek = firstDayOfWeek;
+    }
+
+    @Override
+    public String toString() {
+        return Arrays.toString(this.bitmap);
+    }
+
+
+    /**
+     *
+     * hlavni metoda pro ozkouseni funkcnosti {@code Bitmap}
+     *-issue #7374
+     *
+     * @param args parametry programu
+     */
+    public static void main(String[] args) {
+
+        Calendar dateFrom = Calendar.getInstance();
+        Calendar dateTo = Calendar.getInstance();
+        dateFrom.setTime(new Date(2019-1900, 4, 1)); // -- Jen pro testování Deprecated --
+        dateTo.setTime(new Date(2019-1900, 4, 31)); // rok udáván od 1900, měsíc se počítá od 0
+
+
+        Bitmap bitmap = new Bitmap(dateFrom, dateTo, "143440", "1");
+
+
+        // ------------- KONTROLNÍ VÝPISY -----------------
+        System.out.println("------------- KONTROLNÍ VÝPISY -----------------");
+        System.out.println("Linka: "+ bitmap.getLineNumber()+" - Spoj:"+bitmap.getConnectionNumber());
+        System.out.println("Datum: od: " + bitmap.getDateFrom().getTime() + " | do: " + bitmap.getDateTo().getTime());
+        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)");
+        System.out.println("Počet dní v rozmezí: " + bitmap.getDateRange());
+        System.out.println(bitmap.toString());
+
+        //Jede pouze v pracovní dny
+        bitmap.setWorkdays(1);
+        System.out.println("\nJede v pracovní dny:");
+        System.out.println(bitmap.toString());
+
+        // Kontrola přemazání
+        System.out.println("\nKontrola přemazání:");
+        bitmap.fillWithZeros();
+        System.out.println(bitmap.toString());
+
+        //Nastavit pouze Pondělky - atribut 2
+        System.out.println("\nJede každé pondělí:");
+        bitmap.setDaysInWeek(2, 1);
+        System.out.println(bitmap.toString());
+
+        //přemazání
+        bitmap.fillWithZeros();
+
+        //Nastavit liché týdny (zbytek(remainder) 1 - liché)
+        System.out.println("\nLiché týdny:");
+        bitmap.setWeeks(1, 1);
+        System.out.println(bitmap.toString());
+
+
+
+
+    }
+
+
+}
