From 57b9a8b61b8652a4dcd12cab55aabd29f6dda5aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timo=20Westk=C3=A4mper?= Date: Wed, 16 Feb 2011 07:36:58 +0000 Subject: [PATCH] #719837 : added BooleanExpression andAnyOf and orAllOf --- .../query/types/expr/BooleanExpression.java | 49 +++++++++++++------ 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/querydsl-core/src/main/java/com/mysema/query/types/expr/BooleanExpression.java b/querydsl-core/src/main/java/com/mysema/query/types/expr/BooleanExpression.java index 92ca88a43..d393fba96 100644 --- a/querydsl-core/src/main/java/com/mysema/query/types/expr/BooleanExpression.java +++ b/querydsl-core/src/main/java/com/mysema/query/types/expr/BooleanExpression.java @@ -7,7 +7,7 @@ package com.mysema.query.types.expr; import javax.annotation.Nullable; -import com.mysema.query.types.Operator; +import com.mysema.query.types.ExpressionUtils; import com.mysema.query.types.Ops; import com.mysema.query.types.Path; import com.mysema.query.types.PathImpl; @@ -23,13 +23,13 @@ import com.mysema.query.types.Predicate; public abstract class BooleanExpression extends ComparableExpression implements Predicate{ private static final long serialVersionUID = 3797956062512074164L; - + @Nullable private volatile BooleanExpression eqTrue, eqFalse; /** * Return the intersection of the given Boolean expressions - * + * * @param exprs * @return */ @@ -44,7 +44,7 @@ public abstract class BooleanExpression extends ComparableExpression im /** * Return the union of the given Boolean expressions - * + * * @param exprs * @return */ @@ -64,16 +64,14 @@ public abstract class BooleanExpression extends ComparableExpression im super(Boolean.class); } - @SuppressWarnings("unchecked") @Override public BooleanExpression as(Path alias) { - return BooleanOperation.create((Operator)Ops.ALIAS, this, alias); + return BooleanOperation.create(Ops.ALIAS, this, alias); } - - @SuppressWarnings("unchecked") + @Override public BooleanExpression as(String alias) { - return BooleanOperation.create((Operator)Ops.ALIAS, this, new PathImpl(getType(), alias)); + return as(new PathImpl(Boolean.class, alias)); } /** @@ -90,6 +88,16 @@ public abstract class BooleanExpression extends ComparableExpression im } } + /** + * Get an intersection of this and the union of the given predicates + * + * @param predicates + * @return + */ + public BooleanExpression andAnyOf(Predicate... predicates){ + return and(ExpressionUtils.anyOf(predicates)); + } + /** * Get a negation of this boolean expression * @@ -114,27 +122,36 @@ public abstract class BooleanExpression extends ComparableExpression im }else{ return this; } - } - + + /** + * Get a union of this and the intersection of the given predicates + * + * @param predicates + * @return + */ + public BooleanExpression orAllOf(Predicate... predicates){ + return or(ExpressionUtils.allOf(predicates)); + } + /** * Get a this == true expression - * + * * @return */ public BooleanExpression isTrue(){ return eq(true); } - + /** * Get a this == false expression - * + * * @return */ public BooleanExpression isFalse(){ return eq(false); } - + @Override public BooleanExpression eq(Boolean right) { if (right.booleanValue()){ @@ -147,6 +164,6 @@ public abstract class BooleanExpression extends ComparableExpression im eqFalse = super.eq(false); } return eqFalse; - } + } } }