final List<FilterCriteria> criteria = filter.getFilterCriteria();
final Map<KAMStoreDaoImpl.AnnotationType, AnnotationFilterCriteria> amap =
sizedHashMap(criteria.size());
for (final FilterCriteria c : criteria) {
final AnnotationFilterCriteria afc = (AnnotationFilterCriteria) c;
amap.put(afc.getAnnotationType(), afc);
}
for (Collection<Statement> stmts : results.values()) {
final Iterator<Statement> stmtIt = stmts.iterator();
while (stmtIt.hasNext()) {
final Statement stmt = stmtIt.next();
// guard against empty annotations
if (stmt == null ||
stmt.getAnnotationGroup() == null ||
stmt.getAnnotationGroup().getAnnotations() == null)
continue;
final List<Annotation> annotations = stmt.getAnnotationGroup().getAnnotations();
for (final FilterCriteria c : criteria) {
// criteria is invalid, continue
if (c == null) {
continue;
}
final AnnotationFilterCriteria afc =
(AnnotationFilterCriteria) c;
// criteria's annotation type is invalid, continue
if (afc.getAnnotationType() == null) {
continue;
}
Annotation matchedAnnotation = null;
for (final Annotation annotation : annotations) {
if (annotation.getDefinition().getId().equals(afc.getAnnotationType().getName())) {
matchedAnnotation = annotation;
}
}
if (matchedAnnotation == null) {
if (c.isInclude()) {
stmtIt.remove();
}
} else {
boolean valueMatch = afc.getValues().contains(
matchedAnnotation.getValue());
if (valueMatch && !c.isInclude()) {
stmtIt.remove();
}
}