HHH-5736 Removing unnecessary instance check. Applying Hibernate formatting.

This commit is contained in:
Hardy Ferentschik 2010-12-17 15:36:10 +01:00
parent 0b2d6da3a3
commit d333d98f58
1 changed files with 38 additions and 38 deletions

View File

@ -24,15 +24,15 @@
package org.hibernate.ejb.criteria.predicate; package org.hibernate.ejb.criteria.predicate;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import javax.persistence.criteria.Predicate; import java.util.List;
import javax.persistence.criteria.Expression; import javax.persistence.criteria.Expression;
import javax.persistence.criteria.Predicate;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl; import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler; import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.Renderable; import org.hibernate.ejb.criteria.Renderable;
/** /**
@ -50,9 +50,9 @@ public class CompoundPredicate
/** /**
* Constructs an empty conjunction or disjunction. * Constructs an empty conjunction or disjunction.
* *
* @param criteriaBuilder The query builder from whcih this originates. * @param criteriaBuilder The query builder from which this originates.
* @param operator Indicates whether this predicate will funtion * @param operator Indicates whether this predicate will function
* as a conjunction or disjuntion. * as a conjunction or disjunction.
*/ */
public CompoundPredicate(CriteriaBuilderImpl criteriaBuilder, BooleanOperator operator) { public CompoundPredicate(CriteriaBuilderImpl criteriaBuilder, BooleanOperator operator) {
super( criteriaBuilder ); super( criteriaBuilder );
@ -63,31 +63,31 @@ public class CompoundPredicate
* Constructs a conjunction or disjunction over the given expressions. * Constructs a conjunction or disjunction over the given expressions.
* *
* @param criteriaBuilder The query builder from which this originates. * @param criteriaBuilder The query builder from which this originates.
* @param operator Indicates whether this predicate will funtion * @param operator Indicates whether this predicate will function
* as a conjunction or disjuntion. * as a conjunction or disjunction.
* @param expressions The expressions to be grouped. * @param expressions The expressions to be grouped.
*/ */
public CompoundPredicate( public CompoundPredicate(
CriteriaBuilderImpl criteriaBuilder, CriteriaBuilderImpl criteriaBuilder,
BooleanOperator operator, BooleanOperator operator,
Expression<Boolean>... expressions) { Expression<Boolean>... expressions) {
this( criteriaBuilder, operator ); this( criteriaBuilder, operator );
applyExpressions( expressions ); applyExpressions( expressions );
} }
/** /**
* Constructs a conjunction or disjunction over the given expressions. * Constructs a conjunction or disjunction over the given expressions.
* *
* @param criteriaBuilder The query builder from whcih this originates. * @param criteriaBuilder The query builder from which this originates.
* @param operator Indicates whether this predicate will funtion * @param operator Indicates whether this predicate will function
* as a conjunction or disjuntion. * as a conjunction or disjunction.
* @param expressions The expressions to be grouped. * @param expressions The expressions to be grouped.
*/ */
public CompoundPredicate( public CompoundPredicate(
CriteriaBuilderImpl criteriaBuilder, CriteriaBuilderImpl criteriaBuilder,
BooleanOperator operator, BooleanOperator operator,
List<Expression<Boolean>> expressions) { List<Expression<Boolean>> expressions) {
this( criteriaBuilder, operator ); this( criteriaBuilder, operator );
applyExpressions( expressions ); applyExpressions( expressions );
} }
@ -110,7 +110,7 @@ public class CompoundPredicate
public void registerParameters(ParameterRegistry registry) { public void registerParameters(ParameterRegistry registry) {
for ( Expression expression : getExpressions() ) { for ( Expression expression : getExpressions() ) {
Helper.possibleParameter(expression, registry); Helper.possibleParameter( expression, registry );
} }
} }
@ -125,7 +125,7 @@ public class CompoundPredicate
: "0=1"; // false : "0=1"; // false
} }
if ( getExpressions().size() == 1 ) { if ( getExpressions().size() == 1 ) {
return ( (Renderable) getExpressions().get(0) ).render( renderingContext ); return ( (Renderable) getExpressions().get( 0 ) ).render( renderingContext );
} }
final StringBuilder buffer = new StringBuilder(); final StringBuilder buffer = new StringBuilder();
String sep = ""; String sep = "";
@ -149,28 +149,28 @@ public class CompoundPredicate
return render( renderingContext ); return render( renderingContext );
} }
/** /**
* Create negation of compound predicate by using logic rules: * Create negation of compound predicate by using logic rules:
* 1. not (x || y) is (not x && not y) * 1. not (x || y) is (not x && not y)
* 2. not (x && y) is (not x || not y) * 2. not (x && y) is (not x || not y)
* */
*/ @Override
@Override public Predicate not() {
public Predicate not() { toggleOperator();
if (this.operator == BooleanOperator.AND) { for ( Expression expr : this.getExpressions() ) {
this.operator = BooleanOperator.OR; if ( Predicate.class.isInstance( expr ) ) {
} else { ( (Predicate) expr ).not();
this.operator = BooleanOperator.AND; }
} }
for (Expression expr : this.getExpressions()) { return this;
if (Predicate.class.isInstance(expr)) { }
( (Predicate) expr ).not();
}
else if(CompoundPredicate.class.isInstance(expr)) {
( (CompoundPredicate) expr ).not();
}
}
return this; private void toggleOperator() {
} if ( this.operator == BooleanOperator.AND ) {
this.operator = BooleanOperator.OR;
}
else {
this.operator = BooleanOperator.AND;
}
}
} }