Skip to content
Snippets Groups Projects
Employee.java 10.06 KiB
package com.example.schedulerapp;

import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Arrays;

/*
    Name: Employee
    Description: Contains all employee information
*/
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<>();
    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 = true;  //todo: change back
            this.isManager = Integer.parseInt(dataSplit[3]) == 1;
            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.
     */
    public float getWage() {
        return wage;
    }

    /*
    Name: getEmail
    Parameters: none
    Description: Gets the email of the employee.
    Return:
        String: The email of the employee.
     */
    public String getEmail() {
        return email;
    }

    /*
    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.
     */
    public ArrayList<String> getPositions() {
        return 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.
     */
    public LocalTime[] getAvailabilityForDay(int dayOfTheWeek) {
        return availability[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.
     */
    public LocalTime[][] getAvailability() {
        System.out.println("model: " + availability[0][0] + " " + availability[0][1]);
        return availability;
    }

    /*
    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[] aSplit) {
        String[] availabilitySplit = availabilityPreprocessing(aSplit);
        DateTimeFormatter dbTimeFormat = DateTimeFormatter.ofPattern("kkmm");
        availability[0][0] = LocalTime.parse(availabilitySplit[1],dbTimeFormat);
        availability[0][1] = LocalTime.parse(availabilitySplit[2],dbTimeFormat);
        availability[1][0] = LocalTime.parse(availabilitySplit[3],dbTimeFormat);
        availability[1][1] = LocalTime.parse(availabilitySplit[4],dbTimeFormat);
        availability[2][0] = LocalTime.parse(availabilitySplit[5],dbTimeFormat);
        availability[2][1] = LocalTime.parse(availabilitySplit[6],dbTimeFormat);
        availability[3][0] = LocalTime.parse(availabilitySplit[7],dbTimeFormat);
        availability[3][1] = LocalTime.parse(availabilitySplit[8],dbTimeFormat);
        availability[4][0] = LocalTime.parse(availabilitySplit[9],dbTimeFormat);
        availability[4][1] = LocalTime.parse(availabilitySplit[10],dbTimeFormat);
        availability[5][0] = LocalTime.parse(availabilitySplit[11],dbTimeFormat);
        availability[5][1] = LocalTime.parse(availabilitySplit[12],dbTimeFormat);
        availability[6][0] = LocalTime.parse(availabilitySplit[13],dbTimeFormat);
        availability[6][1] = LocalTime.parse(availabilitySplit[14],dbTimeFormat);
        System.out.println("populate: " + availability[0][0] + " " + availability[0][1]);
    }


    public String[] availabilityPreprocessing(String[] s){
        String[] result = new String[15];
        String sub = "0000";
        for (int i = 1; i < 15; i++){
            if (s[i].length() < 4){
                result[i] = sub.substring(0, 4-s[i].length()) + s[i];
            } else {
                result[i] = s[i];
            }
        }
        return result;
    }

    /*
    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
     */
    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);
    }

    public String toString(){
        return this.employeeID + " - " + this.getFullName();
    }
}