Skip to content
Snippets Groups Projects
Employee.java 7.19 KiB
Newer Older
eyan_'s avatar
eyan_ committed
package com.example.schedulerapp;

/*
    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<>();
    private final int[][] availability = new int[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.
     */
    public int[] 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 int[][] getAvailability() {
        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.
     */
    public void populateAvailability(String[] availabilitySplit) {
        availability[0][0] = Integer.parseInt(availabilitySplit[1]);
        availability[0][1] = Integer.parseInt(availabilitySplit[2]);
        availability[1][0] = Integer.parseInt(availabilitySplit[3]);
        availability[1][1] = Integer.parseInt(availabilitySplit[4]);
        availability[2][0] = Integer.parseInt(availabilitySplit[5]);
        availability[2][1] = Integer.parseInt(availabilitySplit[6]);
        availability[3][0] = Integer.parseInt(availabilitySplit[7]);
        availability[3][1] = Integer.parseInt(availabilitySplit[8]);
        availability[4][0] = Integer.parseInt(availabilitySplit[9]);
        availability[4][1] = Integer.parseInt(availabilitySplit[10]);
        availability[5][0] = Integer.parseInt(availabilitySplit[11]);
        availability[5][1] = Integer.parseInt(availabilitySplit[12]);
        availability[6][0] = Integer.parseInt(availabilitySplit[13]);
        availability[6][1] = Integer.parseInt(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.
     */
    public void updateAvailability(int dayOfTheWeek, int startTime, int endTime) {
        availability[dayOfTheWeek][0] = startTime;
        availability[dayOfTheWeek][1] = endTime;
    }

    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.
     */
    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.
    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.
     */
    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.
     */
    public void removePosition(String position) {
        this.positions.remove(position);
    }
eyan_'s avatar
eyan_ committed
}