I have a snippet of code like this:
public Map<String, Details> getAllDetails(final String name) {
Optional<List<JobExecution>> allJobExecutionsByName = Optional.ofNullable(jobExecutionDao.getAllJobExecutionsByName(name));
// return allJobExecutionsByName.map(x -> x.stream()
// .map(execution -> Pair.of(getJobParam(execution, "id"), getDetailsFromExecution(execution)))
// .collect(toList()))
// .orElse(emptyList());
}
Instead of returning List<Pair<String, Details>>, I want to return Map<String, Details>
How can I convert Optional<List<JobExecution>> to a Map with the key being id and value being the Detail object?