I am trying to get the number of ocurrences of an object in the set of values in a list using Java 8 streams, but I can't get the hang of it yet.
This is what I am trying to do:
int threshold = 5;
for (Player player : match) { // match is a Set<Player>
int count = 0;
for (Set<Player> existingMatch : matches)
if (existingMatch.contains(player))
count++;
if (count >= threshold )
throw new IllegalArgumentException("...");
}
I know I can group with collect and groupingBy, and use a filter saying that the operation to apply is contains with the new method reference operator. But I am still too green with these new Java 8 features and cannot put it all together.
So how could I extract the number of ocurrences of player in all set of values in a list, using Stream?