public final void addCriterion(final Criterion criterion) {
if (!(criterion instanceof AttributeCriterion)) {
throw new UnsupportedOperationException("ConjunctionCriterionImpl.addCriterion can only add an AttributeCriterion.");
}
final AttributeCriterion attrCrit = (AttributeCriterion) criterion;
boolean found = false;
for (int i = 0; i < criteria.size(); i++) {
final Criterion iterCrit = criteria.get(i);
if (!(iterCrit instanceof AttributeCriterion)) {
continue;
}
final AttributeCriterion iterAttrCrit = (AttributeCriterion) iterCrit;
if (found && !iterAttrCrit.getAttribute().equals(attrCrit.getAttribute())) {
// First criterion found for other attribute than the to add attr.
criteria.add(i, criterion);
return;
} else {
found = found || iterAttrCrit.getAttribute().equals(attrCrit.getAttribute());
}
}
// No next criterion found, so add at the end of the List.
criteria.add(criterion);
}