package java112.employee; import java.util.*; import java.io.*; /** * EmployeeDirectory Class * *@author Sirirut Jaikongla */ public class EmployeeDirectory extends java.lang.Object { private List empList; private Map mapId = new HashMap(); private Map mapLast = new HashMap(); private BufferedReader in; private int empId; private String employeeFile; private Properties props; /** * Returns the value of empList. * *@return The empList value */ public List getEmpList() { return empList; } /** * Sets the value of empList. * *@param empList The value to assign empList. */ public void setEmpList(List empList) { this.empList = empList; } /** * Returns the value of mapld. * *@return The mapld value */ public Map getMapId() { return mapId; } /** * Sets the value of mapld. * *@param mapId The new mapId value */ public void setMapId(Map mapId) { this.mapId = mapId; } /** * Returns the value of mapLast. * *@return The mapLast value */ public Map getMapLast() { return mapLast; } /** * Sets the value of mapLast. * *@param mapLast The value to assign mapLast. */ public void setMapLast(Map mapLast) { this.mapLast = mapLast; } /** * load method will load a file from disk and create the employee * collections. * *@param inputFilePath Description of the Parameter *@exception FileNotFoundException Description of the Exception *@exception IOException Description of the Exception */ public void load(String inputFilePath) throws FileNotFoundException, IOException { Employee em; List employs; employeeFile = inputFilePath; BufferedReader in = new BufferedReader(new FileReader(inputFilePath)); while (in.ready()) { String line = in.readLine(); String[] tokens = line.split("\t"); em = new Employee(tokens[0], tokens[1], tokens[2], tokens[3], tokens[4], tokens[5], tokens[6]); empId = Integer.parseInt(tokens[0]); empList.add(em); mapId.put(tokens[0], em); employs = new ArrayList(); if (mapLast.containsKey(tokens[2])) { employs = (List) mapLast.get(tokens[2]); employs.add(em); mapLast.put(tokens[2], employs); } else { employs = new ArrayList(); employs.add(em); mapLast.put(tokens[2], employs); } } } /** * Adds a feature to the NewEmploy attribute of the EmployeeDirectory * object * *@param firstName The feature to be added to the NewEmploy attribute *@param lastName The feature to be added to the NewEmploy attribute *@param ssn The feature to be added to the NewEmploy attribute *@param department The feature to be added to the NewEmploy attribute *@param roomNumber The feature to be added to the NewEmploy attribute *@param phoneNumber The feature to be added to the NewEmploy attribute */ public void addNewEmploy(String firstName, String lastName, String ssn, String department, String roomNumber, String phoneNumber) { //The method will create a new Employee object and populate it with the data in the arguments to the method. Employee employs; empId++; employs = new Employee(Integer.toString(empId), firstName, lastName, ssn, department, roomNumber, phoneNumber); //The method will add the new Employee object to the employee collections. empList.add(employs); mapId.put(Integer.toString(empId), employs); mapLast.put(lastName, employs); } /** * method will take an Employee object an append it to the end of teh employee.dat file. * *@param emp Description of the Parameter */ public synchronized void appendEmployee(Employee emp)throws FileNotFoundException, IOException { // List returnList = new ArrayList(); PrintWriter pw = new PrintWriter(new FileWriter(employeeFile, true)); pw.close(); } /** * Description of the Method * *@param employID Description of the Parameter *@return Description of the Return Value */ public List searchById(String employID) { empList = new ArrayList(); if (mapId.containsKey(employID)) { empList.add(mapId.get(employID)); } return empList; } /** * Description of the Method * *@param lastName Description of the Parameter *@return Description of the Return Value */ public List searchByLastName(String lastName) { empList = new ArrayList(); if (mapLast.containsKey(lastName)) { empList.add(mapLast.get(lastName)); } return (ArrayList) mapLast.get(lastName); } } // -- end class EmployeeDirectory