If I understand you correctly, I'm not sure if Predicate is the right solution here:
Creating such a predicate will require preserving some state (i.e. preserving the set of things that he has already seen). This is explicitly prohibited in javadoc.
The usual way to get individual items in a collection is to simply add them to the set. i.e:
Set<T> uniqueItems = Sets.newHashSet(collectionWithPotentialDuplicates);
If the equals () and hashCode () methods on <T> do not define uniqueness the way you want, then you should write a utility method that works with Collection<T> and Function<T, Object> , which returns elements of type T , which are unique after conversion with Function
source share