} else if (converted instanceof CompoundCriteria) {
converted = rewriteCriteria((CompoundCriteria)converted, false);
}
List<Criteria> critList = null;
if (converted instanceof CompoundCriteria) {
CompoundCriteria other = (CompoundCriteria)converted;
if (other.getOperator() == criteria.getOperator()) {
critList = other.getCriteria();
}
}
if (critList == null) {
critList = Arrays.asList(converted);
}
for (Criteria criteria2 : critList) {
converted = criteria2;
//begin boolean optimizations
if(TRUE_CRITERIA.equals(converted)) {
if(operator == CompoundCriteria.OR) {
// this OR must be true as at least one branch is always true
return converted;
}
} else if(FALSE_CRITERIA.equals(converted)) {
if(operator == CompoundCriteria.AND) {
// this AND must be false as at least one branch is always false
return converted;
}
} else if (UNKNOWN_CRITERIA.equals(converted)) {
if (operator == CompoundCriteria.AND) {
return FALSE_CRITERIA;
}
} else {
if (operator == CompoundCriteria.AND) {
converted = rewriteAndConjunct(converted, exprMap, newCrits);
if (converted != null) {
return converted;
}
} else {
//or
if (converted instanceof SetCriteria) {
SetCriteria sc = (SetCriteria)converted;
if (!sc.isNegated() && sc.isAllConstants()) {
Criteria crit = exprMap.get(sc.getExpression());
if (crit == null) {
exprMap.put(sc.getExpression(), sc);
} else if (crit instanceof SetCriteria) {
SetCriteria other = (SetCriteria)crit;
other.getValues().addAll(sc.getValues());
continue;
} else {
newCrits.remove(crit);
CompareCriteria cc = (CompareCriteria)crit;
sc.getValues().add(cc.getRightExpression());
}
}
} else if (converted instanceof CompareCriteria) {
CompareCriteria cc = (CompareCriteria)converted;
if (cc.getOperator() == CompareCriteria.EQ && cc.getRightExpression() instanceof Constant) {
Criteria crit = exprMap.get(cc.getLeftExpression());
if (crit == null) {
exprMap.put(cc.getLeftExpression(), cc);
} else if (crit instanceof SetCriteria) {
SetCriteria other = (SetCriteria)crit;
other.getValues().add(cc.getRightExpression());
continue;
} else {
newCrits.remove(crit);
CompareCriteria other = (CompareCriteria)crit;
SetCriteria sc = new SetCriteria(cc.getLeftExpression(), new LinkedHashSet<Expression>());
sc.setAllConstants(true);
sc.getValues().add(cc.getRightExpression());
sc.getValues().add(other.getRightExpression());
exprMap.put(sc.getExpression(), sc);
converted = sc;
}
}
}