private void handleExpressions(Expression lhs, Expression rhs) {
if (lhs != null) {
if (Optional.class.isAssignableFrom(rhs.getClass())) {
handleOptional(lhs, rhs);
} else if (Conjunction.class.isAssignableFrom(rhs.getClass())) {
Conjunction conjunction = (Conjunction) rhs;
if (conjunction.getLhs() != null) {
expression = new Conjunction(lhs, rhs);
} else {
conjunction.setLhs(lhs);
expression = rhs;
}
} else if (Constraint.class.isAssignableFrom(rhs.getClass()) &&
(Constraint.class.isAssignableFrom(lhs.getClass()))) {
expression = new Conjunction(lhs, rhs);
} else if (LogicExpression.class.isAssignableFrom(rhs.getClass())) {
expression = new Filter(lhs, (LogicExpression) rhs);
} else if (LogicExpression.class.isAssignableFrom(lhs.getClass())) {
expression = new Filter(rhs, (LogicExpression) lhs);
} else {
expression = new Conjunction(lhs, rhs);
}
} else {
expression = rhs;
}
}