I ran into a difficult problem in Streams API. Well, this is solvable, but not elegantly within the same call, from what I can say. Below, using the FeatureContentWeight stream of objects, I want to group by Feature and Content and get the maximum weight for each function and content. I get the values ββfrom the map at the very end, since I do not need to support the map. The problem is that I only need groups in which there are more than three elements. Therefore, I want the maximum weight for each category and content for Feature and Content pairs to exceed the specified score. In SQL, it will just be just a HAVING clause. This doesnβt look like this in the Streams API, but I have already been in the Streams API for several days.
Any ideas are appreciated.
List<FeatureContentWeight> nearestNeighbors = neighborPostings
.stream()
.collect(
groupingBy(
p -> FeatureContent.Create(p.getFeatureId(), p.getContentId()),
collectingAndThen(maxBy(comparingDouble(FeatureContentWeight::getWeight)),Optional::get))).values();
user4256874
source
share