I have a list of "Articles" that I need to group and get the most recent group. Assume my object to be
private interface Article {
Date getCreated();
String getAuthor();
}
I need to find unique names from the most recent group. Here's a workaround I've come up with but I'm unsure about the time-complexity or the caveats.
Set<String> previous = Optional.ofNullable(articles
.stream()
.collect(Collectors.groupingBy(Article::getCreated, () -> new TreeMap<>(Comparator.reverseOrder()), Collectors.toList()))
.firstEntry())
.map(entries -> entries.getValue()
.stream()
.map(event -> event.getAuthor())
.collect(Collectors.toSet()))
.orElse(Collections.emptySet());
Is there a less convoluted way to do this?