Skip to content
Snippets Groups Projects
Shift.java 4.01 KiB
Newer Older
  • Learn to ignore specific revisions
  • eyan_'s avatar
    eyan_ committed
    package com.example.schedulerapp;
    
    
    import java.time.LocalDateTime;
    
    /*
        Name: Shift
        Description: Contains all the shift information
    */
    
    eyan_'s avatar
    eyan_ committed
    public class Shift {
    
        private int EmployeeID;
    
        private LocalDateTime start;
        private LocalDateTime end;
        private boolean available;
    
    ArktikHunter's avatar
    ArktikHunter committed
        private int shiftID;
    
    
        //todo: error checking on start/end? (end cannot be before start)
    
        /*
        Name: Shift
        Parameters:
            String shiftData: All shift information from the server separated by '.'
        Description: Parses and contains the shift information into the class.
        Return: Shift
         */
    
        public Shift(String shiftData){
            try {
                DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-ddHHmm");
                String[] dataSplit = shiftData.split("\\.");
                this.EmployeeID = Integer.parseInt(dataSplit[0]);
                this.shiftID = Integer.parseInt(dataSplit[4]);
                if (dataSplit[2].length() == 3) dataSplit[2] = "0" + dataSplit[2];
                if (dataSplit[3].length() == 3) dataSplit[3] = "0" + dataSplit[3];
                this.start = LocalDateTime.parse(dataSplit[1] + dataSplit[2], formatter);
                this.end = LocalDateTime.parse(dataSplit[1] + dataSplit[3], formatter);
                this.date = dataSplit[1];
                this.available = false;
            } catch (Exception exception) {
                exception.printStackTrace();
            }
    
        /*
        Name: getEmployeeID
        Parameters: none
        Description: Gets the employee id of the shift.
        Return:
            int: The employee id of the shift.
         */
    
        public int getEmployeeID() {
            return EmployeeID;
        }
    
    
        /*
        Name: getStart
        Parameters: none
        Description: Gets the start date and time of the shift.
        Return:
            LocalDateTime: The start date and time of the shift.
         */
    
        public LocalDateTime getStart() {
            return start;
        }
    
    
        /*
        Name: getEnd
        Parameters: none
        Description: Gets the end date and time of the shift.
        Return:
            LocalDateTime: The end date and time of the shift.
         */
    
        public LocalDateTime getEnd() {
            return end;
        }
    
    
        /*
        Name: getDate
        Parameters: none
        Description: Gets the date of the shift.
        Return:
            String: The date of the shift.
         */
    
        /*
        Name: isAvailable
        Parameters: none
        Description: Checks if the shift is available.
        Return:
            boolean: The availability of the shift.
         */
    
        public boolean isAvailable() {
            return available;
        }
    
    
        /*
        Name: setEmployeeID
        Parameters:
            int employeeID: The id of an employee.
        Description: Changes the employee that is working the shift.
        Return: void
         */
    
        public void setEmployeeID(int employeeID) {
            EmployeeID = employeeID;
        }
    
    
        /*
        Name: setStart
        Parameters:
            LocalDateTime start: new LocalDateTime to be set.
        Description: Changes when the shift starts.
        Return: void
         */
    
        public void setStart(LocalDateTime start) {
            this.start = start;
        }
    
    
        /*
        Name: setEnd
        Parameters:
            LocalDateTime end: new LocalDateTime to be set.
        Description: Changes when the shift ends.
        Return: void
         */
    
        public void setEnd(LocalDateTime end) {
            this.end = end;
        }
    
    
        /*
        Name: setAvailable
        Parameters:
            boolean available: The new availability of the shift to be set.
        Description: Sets the availability of the shift
        Return: void
         */
    
        public void setAvailable(boolean available) {
            this.available = available;
        }
    
    
        /*
        Name: getShiftID
        Parameters: none
        Description: Gets the id of the shift.
        Return:
            int: The id of the shift.
         */
    
    ArktikHunter's avatar
    ArktikHunter committed
        public int getShiftID(){
            return shiftID;
        }
    
    
        //todo
        // output: true if this shift and the given shift overlap at all, otherwise false
        public boolean overlaps(Shift otherShift){
            return false;
        }
    
    eyan_'s avatar
    eyan_ committed
    }