I have below existing implementation
CompletableFuture<Employee>[] employeeDetails =
empIds.stream().map(empId ->
employeeService.employeeDetails(Integer.valueOf(empId)))
.filter(Objects::nonNull)
.toArray(CompletableFuture[]::new);
In this code I need to check in HashMap that empId is already present or not as below - if empId is not present in HashMap then call service and put it into HashMap for future purpose.
Map<String, CompletableFuture<Employee>[]> employeeCache = new HashMap<>();
..........
CompletableFuture<Employee>[] employeeDetails =
empIds.stream().map(empId ->
//Here I need to check in HashMap that empId is present or not if present then fetch from Map instead of calling service.
employeeService.employeeDetails(Integer.valueOf(empId)))
.filter(Objects::nonNull)
.toArray(CompletableFuture[]::new);
How I can add if check in stream() api as shown in above and if present then get from Map.