I want to take a list of tasks (called resultStream) and calculate the percentage of work completed in full.
public class Job {
private Date date;
private String success;
}
The list contains the following:
new Job("TODAY", "YES");
new Job("TODAY", "YES");
new Job("YESTERDAY", "YES");
new Job("TODAY", "NO");
Here is the code that I still have:
resultStream.stream().parallel().filter(result -> {
if ("YES".contains(result.getSuccess())) {
return true;
} else {
return false;
}
}).collect(groupingBy(Job::getDate, HashMap::new, counting()));
This returns me a HashMap (Date, Long) with the following:
TODAY, 2
YESTERDAYS, 1
I really want to get the following result:
TODAY, 66%
YESTERDAY, 100%
Thanks in advance.
source
share