package com.example.schedulerapp; import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; /* Name: Shift Description: Contains all the shift information */ public class Shift { private int EmployeeID; private String date; private LocalDateTime start; private LocalDateTime end; private String position; private boolean available; 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 { System.out.println(shiftData); 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 = 1 == Integer.parseInt(dataSplit[5]); this.position = dataSplit[6]; } 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. */ public String getDate() { return date; } /* 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. */ public int getShiftID(){ return shiftID; } public String getPosition(){ return position; } // output: true if the two overlap at all, otherwise false public static boolean overlaps(Shift a, Shift b){ return a.getEnd().isBefore(b.getStart()) && b.getEnd().isBefore(a.getStart()); } }