org.aksw.commons.collection.observable.PredicateFromMultisetOfDiscardedItems Maven / Gradle / Ivy
package org.aksw.commons.collection.observable;
import java.util.function.Predicate;
import com.google.common.collect.Multiset;
/**
* A predicate backed by a multiset of items that are considered as discarded.
* predicate.test(x) will return false as long as the multiset contains x (true otherwise).
* Whenever the multiset contained x then x's cardinality is reduced by 1
* (by removing one occurrence of x from the multiset)
*
* This is useful to create collection views that hide a specific number of items.
*
*
* @author raven
*
* @param
*/
public class PredicateFromMultisetOfDiscardedItems
implements Predicate
{
protected Multiset discards;
public PredicateFromMultisetOfDiscardedItems(Multiset discards) {
super();
this.discards = discards;
}
public static Predicate create(Multiset discards) {
return new PredicateFromMultisetOfDiscardedItems<>(discards);
}
@Override
public boolean test(T t) {
boolean isDiscarded = discards.contains(t);
if (isDiscarded) {
discards.remove(t);
}
return !isDiscarded;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy