Java tutorial
//package com.java2s; //License from project: Open Source License import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; import java.util.Set; import com.google.common.collect.Multiset; import com.google.common.collect.Multiset.Entry; import com.google.common.collect.Sets; public class Main { /** * Return the elements that have been seen at most nSeen times. * * @param nSeen * @param baseMultiset * @return */ public static <T> Set<T> getElementsWithLessThanCount(final int nSeen, final Multiset<T> baseMultiset) { checkArgument(nSeen > 0); final Set<T> toKeep = Sets.newHashSet(); for (final Entry<T> entry : checkNotNull(baseMultiset).entrySet()) { if (entry.getCount() < nSeen) { toKeep.add(entry.getElement()); } } return toKeep; } }