Example usage for org.apache.commons.collections.functors AllPredicate getInstance

List of usage examples for org.apache.commons.collections.functors AllPredicate getInstance

Introduction

In this page you can find the example usage for org.apache.commons.collections.functors AllPredicate getInstance.

Prototype

public static Predicate getInstance(Collection predicates) 

Source Link

Document

Factory to create the predicate.

Usage

From source file:net.sourceforge.fenixedu.presentationTier.util.CollectionFilter.java

public Set<T> filter(Set<T> elements) {
    Set<T> filtered;//  w w w .j a  v  a2  s.  c  o  m

    if (comparator == null) {
        filtered = new HashSet<T>();
    } else {
        filtered = new TreeSet<T>(comparator);
    }

    final Set<Predicate> predicates = getPredicates();

    if (predicates == null || predicates.isEmpty()) {
        filtered.addAll(elements);
        return Collections.unmodifiableSet(filtered);
    }
    Predicate predicate;
    if (predicates.size() == 1) {
        predicate = predicates.iterator().next();
    } else {
        predicate = AllPredicate.getInstance(predicates);
    }
    for (T element : elements) {
        if (predicate.evaluate(element)) {
            filtered.add(element);
        }
    }
    return Collections.unmodifiableSet(filtered);
}