org.jboss.weld.metadata.ScanningPredicate Maven / Gradle / Ivy
package org.jboss.weld.metadata;
import java.util.Collection;
import org.jboss.weld.util.Predicate;
public class ScanningPredicate implements Predicate {
private final Collection> includes;
private final Collection> excludes;
public ScanningPredicate(Collection> includes, Collection> excludes) {
this.includes = includes;
this.excludes = excludes;
}
public boolean test(T input) {
// Initial state - all classes are included if no includes are specified
boolean apply = includes.isEmpty();
for (Predicate include : includes) {
// If any include matches, we should include the class
if (include.test(input)) {
apply = true;
}
}
for (Predicate exclude : excludes) {
// If any exclude matches, we exclude the class - we can then short-circuit
if (exclude.test(input)) {
return false;
}
}
return apply;
}
}