I have a collection of objects Employeeand you need to turn it into a map of hyperlink widgets for presentation purposes.
For each employee, an entry is added to the result with a key that is an identifier (here is the national insurance number), and the value is a hyperlink widget. Here's the first attempt:
static Map<String, Hyperlink> toHyperlinksByNIN(Collection<Employee> employees) {
return employees.stream()
.collect(Collectors.toMap(
Employee::determineUniqueNINumber,
employee -> new Hyperlink(
employee.getName(), employee.determineUniqueNINumber())));
}
Unfortunately, this decision will not be fulfilled, since the NI number is not actually part of the employee model, but it must be retrieved from the expensive remote service with every call Employee.determineUniqueNINumber. This method is too expensive to call more than once on an employee record.
How can i get the desired Map
- Stream API,
- / (
Employee.determineUniqueNINumber) ?