The objective of this module is to gain hands-on experience with the following Java 8 features:
- Functional Programming
- Lambda Expressions
- Streams
- Optional Class
- Understand and implement Lambda Expressions in Java.
- Understand and implement Streams for processing large datasets.
- Work with the Optional Class.
Process the list of Employees based on the following business requirements:
- Display each employee profile.
- Find an employee based on ID and display their profile. If no employee exists with the specified ID, throw
EmployeeNotFoundException
. - Add a new employee to the list. If the employee already exists, throw
EmployeeAlreadyExistsException
. - Group all employees based on their department, using their designation to filter since there is no department property.
-
Remove Duplicates: Remove duplicate employee objects from
employeeList
added in the previous Lab. -
Create Exception Classes:
- Under the
com.digisafari.exception
package, createEmployeeNotFoundException
andEmployeeAlreadyExistsException
classes. - Use argument constructors for both these Exception classes with the appropriate exception message.
- Under the
-
Create EmployeeService Interface:
- Define the following methods:
public List<Employee> getEmployees(); public Employee findEmployeeById(int empId) throws EmployeeNotFoundException; public Employee addEmployee(Employee employee) throws EmployeeAlreadyExistsException; public Employee updateEmployee(Employee employee) throws EmployeeNotFoundException; public boolean deleteEmployee(int empId) throws EmployeeNotFoundException;
- Define the following methods:
-
Implement EmployeeService Interface:
- Create a class named
EmployeeServiceImpl
that implements theEmployeeService
interface. - Create a property
employeeRepository
of typeEmployeeRepository
. - Initialize the
employeeRepository
property in a no-arg constructor. - Override all the abstract methods with appropriate logic.
- Create a class named
-
Test Implementation:
- In
CollectionTest.java
, create an instance ofEmployeeServiceImpl
and test all the methods by passing the appropriate data.
- In
This README provides an overview of exercises focused on Java 8 features, specifically Lambda Expressions, Streams, and the Optional Class. Follow the tasks to implement the required functionality and ensure proper exception handling and data processing.