in repository/service/src/main/java/org/apache/karaf/cave/repository/service/bundlerepository/CapabilitySet.java [203:241]
private static boolean matchesInternal(Capability cap, SimpleFilter sf) {
boolean matched = true;
if (sf.getOperation() == SimpleFilter.MATCH_ALL) {
matched = true;
} else if (sf.getOperation() == SimpleFilter.AND) {
// Evaluate each subfilter against the remaining capabilities.
// For AND we calculate the intersection of each subfilter.
// We can short-circuit the AND operation if there are no
// remaining capabilities.
List<SimpleFilter> sfs = (List<SimpleFilter>) sf.getValue();
for (int i = 0; matched && (i < sfs.size()); i++) {
matched = matchesInternal(cap, sfs.get(i));
}
} else if (sf.getOperation() == SimpleFilter.OR) {
// Evaluate each subfilter against the remaining capabilities.
// For OR we calculate the union of each subfilter.
matched = false;
List<SimpleFilter> sfs = (List<SimpleFilter>) sf.getValue();
for (int i = 0; !matched && (i < sfs.size()); i++) {
matched = matchesInternal(cap, sfs.get(i));
}
} else if (sf.getOperation() == SimpleFilter.NOT) {
// Evaluate each subfilter against the remaining capabilities.
// For OR we calculate the union of each subfilter.
List<SimpleFilter> sfs = (List<SimpleFilter>) sf.getValue();
for (SimpleFilter sf1 : sfs) {
matched = !(matchesInternal(cap, sf1));
}
} else {
matched = false;
Object lhs = cap.getAttributes().get(sf.getName());
if (lhs != null) {
matched = compare(lhs, sf.getValue(), sf.getOperation());
}
}
return matched;
}