Constraint right = replaceReferences(context, and.getRight(), mapping, node);
if (left == and.getLeft() && right == and.getRight()) return and;
return new And(left, right);
}
if (constraint instanceof Or) {
Or or = (Or)constraint;
Constraint left = replaceReferences(context, or.getLeft(), mapping, node);
Constraint right = replaceReferences(context, or.getRight(), mapping, node);
if (left == or.getLeft() && right == or.getRight()) return or;
return new Or(left, right);
}
if (constraint instanceof Not) {
Not not = (Not)constraint;
Constraint wrapped = replaceReferences(context, not.getConstraint(), mapping, node);
return wrapped == not.getConstraint() ? not : new Not(wrapped);