in repository/service/src/main/java/org/apache/karaf/cave/repository/service/bundlerepository/CapabilitySet.java [145:196]
private Set<Capability> match(Set<Capability> caps, SimpleFilter sf) {
Set<Capability> matches = new HashSet<>();
if (sf.getOperation() == SimpleFilter.MATCH_ALL) {
matches.addAll(caps);
} 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; (caps.size() > 0) && (i < sfs.size()); i++) {
matches = match(caps, sfs.get(i));
caps = matches;
}
} else if (sf.getOperation() == SimpleFilter.OR) {
// 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) {
matches.addAll(match(caps, sf1));
}
} else if (sf.getOperation() == SimpleFilter.NOT) {
// Evaluate each subfilter against the remaining capabilities.
// For OR we calculate the union of each subfilter.
matches.addAll(caps);
List<SimpleFilter> sfs = (List<SimpleFilter>) sf.getValue();
for (SimpleFilter sf1 : sfs) {
matches.removeAll(match(caps, sf1));
}
} else {
Map<Object, Set<Capability>> index = indices.get(sf.getName());
if ((sf.getOperation() == SimpleFilter.EQ) && (index != null)) {
Set<Capability> existingCaps = index.get(sf.getValue());
if (existingCaps != null) {
matches.addAll(existingCaps);
matches.retainAll(caps);
}
} else {
for (Capability cap : caps) {
Object lhs = cap.getAttributes().get(sf.getName());
if (lhs != null) {
if (compare(lhs, sf.getValue(), sf.getOperation())) {
matches.add(cap);
}
}
}
}
}
return matches;
}