// EmployeeFind Project // EmployeeRoster class -- Source code file EmployeeRoster // Project: EmployeeFind // No additional modules defined // Source code file: EmployeeRoster.java. // Show how to search collection for a specified substring. import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Map.Entry; public class EmployeeRoster { private HashMap col; public EmployeeRoster( ) { col = new HashMap( ); } // Add new Employee object to EmployeeRoster public void add(Employee emp) { String empId = emp.getId( ); col.put(empId, emp); } // find all names that contain a specified substring. public ArrayList find(String substring) { ArrayList output = new ArrayList( ); for(Entry entry : col.entrySet( )) { Employee emp = entry.getValue( ); String name = emp.getName( ).toUpperCase( ); if (name.indexOf(substring) > -1) { output.add(emp); } } // Sort objects by name before returning array list. Collections.sort(output); return output; } @Override public String toString( ) { String output = "EmployeeRoster: \n"; for (Entry entry : col.entrySet( )) { output += entry.getValue( ).toString( ) + "\n"; } return output; } }