Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,18 @@ public Predicate clone() {
return new Predicate(exp.clone());
}

@Override
public boolean equals(Object obj) {
Copy link
Collaborator Author

@rcosta358 rcosta358 Mar 17, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added missing equals() for predicates anyway.

if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Predicate other = (Predicate) obj;
return exp.equals(other.exp);
}

public Expression getExpression() {
return exp;
}
Expand All @@ -195,6 +207,15 @@ private static boolean isBooleanLiteral(Expression expr, boolean value) {
return expr instanceof LiteralBoolean && expr.isBooleanTrue() == value;
}

private static boolean containsConjunct(Predicate c1, Predicate c2) {
if (c1.toString().equals(c2.toString()))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used string comparison instead of equals() to handle inconsistent GroupExpression wrapping.

return true;
if (c1.getExpression()instanceof BinaryExpression be && be.getOperator().equals(Ops.AND))
return containsConjunct(new Predicate(be.getFirstOperand()), c2)
|| containsConjunct(new Predicate(be.getSecondOperand()), c2);
return false;
}

public static Predicate createConjunction(Predicate c1, Predicate c2) {
// simplification: (true && x) = x, (false && x) = false
if (isBooleanLiteral(c1.getExpression(), true))
Expand All @@ -205,6 +226,11 @@ public static Predicate createConjunction(Predicate c1, Predicate c2) {
return c1;
if (isBooleanLiteral(c2.getExpression(), false))
return c2;

// check if c2 is already present in the conjunctions of c1
if (containsConjunct(c1, c2))
return c1;

return new Predicate(new BinaryExpression(c1.getExpression(), Ops.AND, c2.getExpression()));
}

Expand Down
Loading