Search in sources :

Example 1 with SingleConstraint2

use of org.drools.model.constraints.SingleConstraint2 in project drools by kiegroup.

the class LambdaConstraintTestUtil method createLambdaConstraint2.

public static <T, A, B> LambdaConstraint createLambdaConstraint2(Class<A> patternClass, Class<B> rightClass, Pattern pattern, Pattern varPattern, String varName, Predicate2<A, B> predicate, Index<T, ?> index) {
    String patternName = "GENERATED_$pattern_" + patternClass.getSimpleName();
    DeclarationImpl<A> declA = new DeclarationImpl<A>(patternClass, patternName);
    DeclarationImpl<B> declB = new DeclarationImpl<B>(rightClass, varName);
    SingleConstraint2<A, B> singleConstraint = new SingleConstraint2<A, B>(declA, declB, predicate);
    singleConstraint.setIndex(index);
    Declaration patternDecl = new Declaration(patternName, new PatternExtractor(new ClassObjectType(patternClass, false)), pattern, false);
    Declaration varDecl = new Declaration(varName, new PatternExtractor(new ClassObjectType(rightClass, false)), varPattern, false);
    ConstraintEvaluator constraintEvaluator = new ConstraintEvaluator(new Declaration[] { patternDecl, varDecl }, singleConstraint);
    return new LambdaConstraint(constraintEvaluator);
}
Also used : SingleConstraint2(org.drools.model.constraints.SingleConstraint2) ClassObjectType(org.drools.core.base.ClassObjectType) PatternExtractor(org.drools.core.spi.PatternExtractor) LambdaConstraint(org.drools.modelcompiler.constraints.LambdaConstraint) ConstraintEvaluator(org.drools.modelcompiler.constraints.ConstraintEvaluator) DeclarationImpl(org.drools.model.impl.DeclarationImpl) Declaration(org.drools.core.rule.Declaration)

Aggregations

ClassObjectType (org.drools.core.base.ClassObjectType)1 Declaration (org.drools.core.rule.Declaration)1 PatternExtractor (org.drools.core.spi.PatternExtractor)1 SingleConstraint2 (org.drools.model.constraints.SingleConstraint2)1 DeclarationImpl (org.drools.model.impl.DeclarationImpl)1 ConstraintEvaluator (org.drools.modelcompiler.constraints.ConstraintEvaluator)1 LambdaConstraint (org.drools.modelcompiler.constraints.LambdaConstraint)1