@@ -207,6 +207,9 @@ private static boolean isBooleanLiteral(Expression expr, boolean value) {
207207 return expr instanceof LiteralBoolean && expr .isBooleanTrue () == value ;
208208 }
209209
210+ /**
211+ * Checks if c2 is a conjunct in c1
212+ */
210213 private static boolean containsConjunct (Predicate c1 , Predicate c2 ) {
211214 if (c1 .toString ().equals (c2 .toString ()))
212215 return true ;
@@ -216,6 +219,10 @@ private static boolean containsConjunct(Predicate c1, Predicate c2) {
216219 return false ;
217220 }
218221
222+ /**
223+ * Creates a new predicate representing the conjunction of c1 and c2
224+ * Contains simplification rules for redundant conjuncts such as not adding conjunct if already present in conjunction
225+ */
219226 public static Predicate createConjunction (Predicate c1 , Predicate c2 ) {
220227 // simplification: (true && x) = x, (false && x) = false
221228 if (isBooleanLiteral (c1 .getExpression (), true ))
@@ -227,9 +234,11 @@ public static Predicate createConjunction(Predicate c1, Predicate c2) {
227234 if (isBooleanLiteral (c2 .getExpression (), false ))
228235 return c2 ;
229236
230- // check if c2 is already present in the conjunctions of c1
237+ // check if conjunct is already present in the conjunction
231238 if (containsConjunct (c1 , c2 ))
232239 return c1 ;
240+ if (containsConjunct (c2 , c1 ))
241+ return c2 ;
233242
234243 return new Predicate (new BinaryExpression (c1 .getExpression (), Ops .AND , c2 .getExpression ()));
235244 }
0 commit comments