Skip to content
Snippets Groups Projects
Employee.java 9 KiB
Newer Older
  • Learn to ignore specific revisions
  • eyan_'s avatar
    eyan_ committed
    package com.example.schedulerapp;
    
    
    ArktikHunter's avatar
    ArktikHunter committed
    import java.time.LocalTime;
    
    /*
        Name: Employee
        Description: Contains all employee information
    */
    
    eyan_'s avatar
    eyan_ committed
    public class Employee {
    
        private int employeeID;
        private String firstName;
        private String lastName;
    
        private boolean isManager;
    
        private String email;
        private String phoneNumber;
        private float wage;
    
        private final ArrayList<String> positions = new ArrayList<>();
    
    ArktikHunter's avatar
    ArktikHunter committed
        private final LocalTime[][] availability = new LocalTime[7][2];
    
        private final ArrayList<Integer> timeOff = new ArrayList<>();
    
        /*
        Name: Employee
        Parameters:
            String employeeData: All employee information from the server separated by '.'
        Description: Parses and contains the employee information into the class.
        Return: Employee
         */
    
        public Employee(String employeeData){
            try {
    
                String[] dataSplit = employeeData.split(",");
    
                this.employeeID = Integer.parseInt(dataSplit[0]);
                this.firstName = dataSplit[1];
                this.lastName = dataSplit[2];
    
                this.isManager = Boolean.parseBoolean(dataSplit[3]);
                this.email = dataSplit[4];
                this.phoneNumber = dataSplit[5];
                this.wage = Float.parseFloat(dataSplit[6]);
    
                this.positions.addAll(Arrays.asList(dataSplit[7].split("\\.")));
    
            } catch (Exception exception) {
                exception.printStackTrace();
            }
        }
    
    
        /*
        Name: getEmployeeID
        Parameters: none
        Description: Gets the employee id of the employee.
        Return:
            int: The id of the employee.
         */
    
        public int getEmployeeID() {
            return employeeID;
        }
    
    
        /*
        Name: isManager
        Parameters: none
        Description: Check if an employee is a manager.
        Return:
            Boolean: true if manager, false if not.
         */
        public boolean isManager() { return isManager; }
    
        /*
        Name: getFullName
        Parameters: none
        Description: Gets the full name of the employee.
        Return:
            String: The full name of the employee.
         */
    
        public String getFullName() {
            return firstName + " " + lastName;
        }
    
    
        /*
        Name: getFirstName
        Parameters: none
        Description: Gets the fist name of the employee.
        Return:
            String: The first name of the employee.
         */
    
        public String getFirstName() {
            return firstName;
        }
    
    
        /*
        Name: getLastName
        Parameters: none
        Description: Gets the last name of the employee.
        Return:
            String: The first name of the employee.
         */
    
        public String getLastName() {
            return lastName;
        }
    
    
        /*
        Name: getWage
        Parameters: none
        Description: Gets the wage of the employee.
        Return:
            float: The wage of the employee.
         */
    
        /*
        Name: getEmail
        Parameters: none
        Description: Gets the email of the employee.
        Return:
            String: The email of the employee.
         */
    
        /*
        Name: getPhoneNumber
        Parameters: none
        Description: Gets the phone number of the employee.
        Return:
            String: The phone number of the employee.
         */
    
        public String getPhoneNumber() {
            return phoneNumber;
        }
    
    
        /*
        Name: getPositions
        Parameters: none
        Description: Gets all the positions the employee is trained for.
        Return:
            String[]: String list of all trained positions.
         */
    
        /*
        Name: getAvailabilityForDay
        Parameters:
            int dayOfTheWeek: int representing the day of the week. 0=sunday,1=monday,...
        Description: Gets the availability of the employee for a given day of the week.
        Return:
            int[2] : The availability of the employee where the index 0 is the start time and index 1 is the end time.
         */
    
    ArktikHunter's avatar
    ArktikHunter committed
        public LocalTime[] getAvailabilityForDay(int dayOfTheWeek) {
    
        /*
        Name: getAvailability
        Parameters: none
        Description: Gets the availability of the employee.
        Return:
    
            int[7][2] : The availability of the employee, where the first index is the day of the week and the second index
            the start and end times.
         */
    
    ArktikHunter's avatar
    ArktikHunter committed
        public LocalTime[][] getAvailability() {
    
        /*
        ONLY USE for updating locally, if you're trying to update it on the server look for a method in the Model class.
        This is for the ReceiveThread class to update changes from the server.
    
    
        Name: populateAvailability
        Parameters:
            String[] availabilitySplit: all the start and end times for each day of the week.
        Description: Adds the availability to the employee object.
        Return: void
    
        public void populateAvailability(String[] availabilitySplit) {
    
    ArktikHunter's avatar
    ArktikHunter committed
            availability[0][0] = LocalTime.parse(availabilitySplit[1]);
            availability[0][1] = LocalTime.parse(availabilitySplit[2]);
            availability[1][0] = LocalTime.parse(availabilitySplit[3]);
            availability[1][1] = LocalTime.parse(availabilitySplit[4]);
            availability[2][0] = LocalTime.parse(availabilitySplit[5]);
            availability[2][1] = LocalTime.parse(availabilitySplit[6]);
            availability[3][0] = LocalTime.parse(availabilitySplit[7]);
            availability[3][1] = LocalTime.parse(availabilitySplit[8]);
            availability[4][0] = LocalTime.parse(availabilitySplit[9]);
            availability[4][1] = LocalTime.parse(availabilitySplit[10]);
            availability[5][0] = LocalTime.parse(availabilitySplit[11]);
            availability[5][1] = LocalTime.parse(availabilitySplit[12]);
            availability[6][0] = LocalTime.parse(availabilitySplit[13]);
            availability[6][1] = LocalTime.parse(availabilitySplit[14]);
    
        }
    
        /*
        ONLY USE for updating locally, if you're trying to update it on the server look for a method in the Model class.
        This is for the ReceiveThread class to update changes from the server.
    
    
        Name: updateAvailability
        Parameters:
            int dayOfTheWeek: The day of the week, where 0=sunday, 1=monday,..., 6=saturday.
            int startTime: Start time represented in 24-hour format. Example: 1330 (1:30-PM)
            int endTime: End time represented in 24-hour format. Example: 1330 (1:30-PM)
        Description: Updates the availability start and end time for a specific day of the week.
        Return: void
    
    ArktikHunter's avatar
    ArktikHunter committed
        public void updateAvailability(int dayOfTheWeek, LocalTime startTime, LocalTime endTime) {
    
            availability[dayOfTheWeek][0] = startTime;
            availability[dayOfTheWeek][1] = endTime;
        }
    
    
        /*
        Name: getTimeOffID
        Parameters: none
        Description: Gets the list of time off ids for the employee. This can be used on the time off hash map to get more
        detail about the specific time off request.
        Return:
            ArrayList<Integer>: A list of time off requests.
         */
    
        public ArrayList<Integer> getTimeOffID() {
            return this.timeOff;
        }
    
        /*
        ONLY USE for updating locally, if you're trying to update it on the server look for a method in the Model class.
        This is for the ReceiveThread class to update changes from the server.
    
    
        Name: addTimeOffID
        Parameters:
            int timeOffID: The id of a time off request.
        Description: Adds the time off id to the list of time off request made my the employee.
        Return: void
    
         */
        public void addTimeOffID(int timeOffID) {
            this.timeOff.add(timeOffID);
        }
    
        /*
        ONLY USE for updating locally, if you're trying to update it on the server look for a method in the Model class.
        This is for the ReceiveThread class to update changes from the server.
    
    
        Name: removeTimeOffID
        Parameters:
            int timeOffID: The id of a time off request.
        Description: Removes the time off id from the list of time off request made my the employee.
        Return: void
    
        public void removeTimeOffID(Integer timeOffID) {
            this.timeOff.remove(timeOffID);
    
    
        /*
        ONLY USE for updating locally, if you're trying to update it on the server look for a method in the Model class.
        This is for the ReceiveThread class to update changes from the server.
    
    
        Name: addPosition
        Parameters:
            String position: Position in the hashmap (keys) of possible positions.
        Description: Adds a position to the list of trained positions in the employee object.
        Return: void
    
         */
        public void addPosition(String position) {
            this.positions.add(position);
        }
    
        /*
        ONLY USE for updating locally, if you're trying to update it on the server look for a method in the Model class.
        This is for the ReceiveThread class to update changes from the server.
    
         Name: removePosition
        Parameters:
            String position: Position in the hashmap (keys) of possible positions.
        Description: Removes a position from the list of trained positions in the employee object.
        Return: void
    
         */
        public void removePosition(String position) {
            this.positions.remove(position);
        }
    
    eyan_'s avatar
    eyan_ committed
    }