Package org.drools.compiler.lang.descr

Examples of org.drools.compiler.lang.descr.PatternDescr


                      pkg.getRules().size() );
        final RuleDescr rule = (RuleDescr) pkg.getRules().get( 0 );
        assertEquals( 1,
                      rule.getLhs().getDescrs().size() );

        final PatternDescr out = (PatternDescr) rule.getLhs().getDescrs().get( 0 );
        final AccumulateDescr accumulate = (AccumulateDescr) out.getSource();

        PatternDescr person = (PatternDescr) accumulate.getInputPattern();
        assertEquals( "Person",
                      person.getObjectType() );

        final CollectDescr collect2 = (CollectDescr) person.getSource();

        final PatternDescr people = collect2.getInputPattern();
        assertEquals( "People",
                      people.getObjectType() );
    }
View Full Code Here


        RuleDescr rule = (RuleDescr) pkg.getRules().get( 0 );
        assertEquals( 1,
                      rule.getLhs().getDescrs().size() );

        PatternDescr out = (PatternDescr) rule.getLhs().getDescrs().get( 0 );
        assertEquals( "Object[]",
                      out.getObjectType() );
        AccumulateDescr accum = (AccumulateDescr) out.getSource();
        assertTrue( accum.isExternalFunction() );

        List<AccumulateFunctionCallDescr> functions = accum.getFunctions();
        assertEquals( 3,
                      functions.size() );
        assertEquals( "average",
                      functions.get( 0 ).getFunction() );
        assertEquals( "$a1",
                      functions.get( 0 ).getBind() );
        assertEquals( "$price",
                      functions.get( 0 ).getParams()[0] );

        assertEquals( "min",
                      functions.get( 1 ).getFunction() );
        assertEquals( "$m1",
                      functions.get( 1 ).getBind() );
        assertEquals( "$price",
                      functions.get( 1 ).getParams()[0] );

        assertEquals( "max",
                      functions.get( 2 ).getFunction() );
        assertEquals( "$M1",
                      functions.get( 2 ).getBind() );
        assertEquals( "$price",
                      functions.get( 2 ).getParams()[0] );

        final PatternDescr pattern = (PatternDescr) accum.getInputPattern();
        assertEquals( "Cheese",
                      pattern.getObjectType() );
    }
View Full Code Here

        RuleDescr rule = (RuleDescr) pkg.getRules().get( 0 );
        assertEquals( 1,
                      rule.getLhs().getDescrs().size() );

        PatternDescr out = (PatternDescr) rule.getLhs().getDescrs().get( 0 );
        assertEquals( "Object[]",
                      out.getObjectType() );
        AccumulateDescr accum = (AccumulateDescr) out.getSource();
        assertTrue( accum.isExternalFunction() );

        List<AccumulateFunctionCallDescr> functions = accum.getFunctions();
        assertEquals( 1,
                      functions.size() );
        assertEquals( "average",
                      functions.get( 0 ).getFunction() );
        assertEquals( "$a1",
                      functions.get( 0 ).getBind() );
        assertEquals( "$price",
                      functions.get( 0 ).getParams()[0] );

        final PatternDescr pattern = (PatternDescr) accum.getInputPattern();
        assertEquals( "Cheese",
                      pattern.getObjectType() );
    }
View Full Code Here

        RuleDescr rule = (RuleDescr) pkg.getRules().get( 0 );
        assertEquals( 1,
                      rule.getLhs().getDescrs().size() );

        PatternDescr out = (PatternDescr) rule.getLhs().getDescrs().get( 0 );
        assertEquals( "Number",
                      out.getObjectType() );
        AccumulateDescr accum = (AccumulateDescr) out.getSource();
        assertTrue( accum.isExternalFunction() );

        List<AccumulateFunctionCallDescr> functions = accum.getFunctions();
        assertEquals( 1,
                      functions.size() );
        assertEquals( "average",
                      functions.get( 0 ).getFunction() );
        assertEquals( "$price",
                      functions.get( 0 ).getParams()[0] );

        final PatternDescr pattern = (PatternDescr) accum.getInputPattern();
        assertEquals( "Cheese",
                      pattern.getObjectType() );
    }
View Full Code Here

        RuleDescr rule = (RuleDescr) pkg.getRules().get( 0 );
        assertEquals( 1,
                      rule.getLhs().getDescrs().size() );

        PatternDescr out = (PatternDescr) rule.getLhs().getDescrs().get( 0 );
        assertEquals( "Object[]",
                      out.getObjectType() );
        AccumulateDescr accum = (AccumulateDescr) out.getSource();
        assertTrue( accum.isExternalFunction() );

        List<AccumulateFunctionCallDescr> functions = accum.getFunctions();
        assertEquals( 2,
                      functions.size() );
        assertEquals( "baz",
                functions.get( 0 ).getFunction() );
        assertEquals( "$v1",
                functions.get( 0 ).getBind() );
        assertEquals( "$price",
                      functions.get( 0 ).getParams()[0] );

        assertEquals( "baz2",
                functions.get( 1 ).getFunction() );
        assertEquals( "$v2",
                functions.get( 1 ).getBind() );
        assertEquals( "$price",
                      functions.get( 1 ).getParams()[0] );

        final PatternDescr pattern = (PatternDescr) accum.getInputPattern();
        assertEquals( "Cheese",
                      pattern.getObjectType() );
    }
View Full Code Here

        RuleDescr rule = (RuleDescr) pkg.getRules().get( 0 );
        assertEquals( 1,
                      rule.getLhs().getDescrs().size() );

        PatternDescr out = (PatternDescr) rule.getLhs().getDescrs().get( 0 );
        assertEquals( "Object[]",
                      out.getObjectType() );
        assertEquals( 2,
                      out.getConstraint().getDescrs().size() );
        assertEquals( "$a1 > 10 && $M1 <= 100",
                      out.getConstraint().getDescrs().get( 0 ).toString() );
        assertEquals( "$m1 == 5",
                      out.getConstraint().getDescrs().get( 1 ).toString() );
        AccumulateDescr accum = (AccumulateDescr) out.getSource();
        assertTrue( accum.isExternalFunction() );

        List<AccumulateFunctionCallDescr> functions = accum.getFunctions();
        assertEquals( 3,
                      functions.size() );
        assertEquals( "average",
                      functions.get( 0 ).getFunction() );
        assertEquals( "$a1",
                      functions.get( 0 ).getBind() );
        assertEquals( "$price",
                      functions.get( 0 ).getParams()[0] );

        assertEquals( "min",
                      functions.get( 1 ).getFunction() );
        assertEquals( "$m1",
                      functions.get( 1 ).getBind() );
        assertEquals( "$price",
                      functions.get( 1 ).getParams()[0] );

        assertEquals( "max",
                      functions.get( 2 ).getFunction() );
        assertEquals( "$M1",
                      functions.get( 2 ).getBind() );
        assertEquals( "$price",
                      functions.get( 2 ).getParams()[0] );

        final PatternDescr pattern = (PatternDescr) accum.getInputPattern();
        assertEquals( "Cheese",
                      pattern.getObjectType() );
    }
View Full Code Here

                      pkg.getRules().size() );
        final RuleDescr rule = (RuleDescr) pkg.getRules().get( 0 );
        assertEquals( 2,
                      rule.getLhs().getDescrs().size() );

        final PatternDescr person = (PatternDescr) rule.getLhs().getDescrs().get( 0 );
        assertEquals( "Person",
                      person.getObjectType() );
        assertEquals( "$p",
                      person.getIdentifier() );

        final OrDescr or = (OrDescr) rule.getLhs().getDescrs().get( 1 );
        assertEquals( 2,
                      or.getDescrs().size() );

        final PatternDescr cheese1 = (PatternDescr) or.getDescrs().get( 0 );
        assertEquals( "Cheese",
                      cheese1.getObjectType() );
        assertEquals( "$c",
                      cheese1.getIdentifier() );
        final PatternDescr cheese2 = (PatternDescr) or.getDescrs().get( 1 );
        assertEquals( "Cheese",
                      cheese2.getObjectType() );
        assertNull( cheese2.getIdentifier() );
    }
View Full Code Here

                      or.getDescrs().size() );
        NotDescr not = (NotDescr) or.getDescrs().get( 0 );
        AndDescr and = (AndDescr) or.getDescrs().get( 1 );
        assertEquals( 1,
                      not.getDescrs().size() );
        PatternDescr person = (PatternDescr) not.getDescrs().get( 0 );
        assertEquals( "Person",
                      person.getObjectType() );
        assertEquals( 3,
                      and.getDescrs().size() );
        PatternDescr cheese = (PatternDescr) and.getDescrs().get( 0 );
        assertEquals( "Cheese",
                      cheese.getObjectType() );
        PatternDescr meat = (PatternDescr) and.getDescrs().get( 1 );
        assertEquals( "Meat",
                      meat.getObjectType() );
        PatternDescr wine = (PatternDescr) and.getDescrs().get( 2 );
        assertEquals( "Wine",
                      wine.getObjectType() );

    }
View Full Code Here

                      pkg.getRules().size() );
        final RuleDescr rule = (RuleDescr) pkg.getRules().get( 0 );
        assertEquals( 1,
                      rule.getLhs().getDescrs().size() );

        final PatternDescr outPattern = (PatternDescr) rule.getLhs().getDescrs().get( 0 );
        final AccumulateDescr accum = (AccumulateDescr) outPattern.getSource();
        assertEqualsIgnoreWhitespace( "$counter",
                                      outPattern.getIdentifier() );
        assertEqualsIgnoreWhitespace( "int x = 0 ;",
                                      accum.getInitCode() );
        assertEqualsIgnoreWhitespace( "x++;",
                                      accum.getActionCode() );
        assertEqualsIgnoreWhitespace( "new Integer(x)",
                                      accum.getResultCode() );

        final AndDescr and = (AndDescr) accum.getInput();
        assertEquals( 2,
                      and.getDescrs().size() );
        final PatternDescr person = (PatternDescr) and.getDescrs().get( 0 );
        final PatternDescr cheese = (PatternDescr) and.getDescrs().get( 1 );
        assertEquals( "Person",
                      person.getObjectType() );
        assertEquals( "Cheese",
                      cheese.getObjectType() );
    }
View Full Code Here

                      pkg.getRules().size() );
        final RuleDescr rule = (RuleDescr) pkg.getRules().get( 0 );
        assertEquals( 5,
                      rule.getLhs().getDescrs().size() );

        final PatternDescr eventA = (PatternDescr) rule.getLhs().getDescrs().get( 0 );
        assertEquals( "$a",
                      eventA.getIdentifier() );
        assertEquals( "EventA",
                      eventA.getObjectType() );

        final PatternDescr eventB = (PatternDescr) rule.getLhs().getDescrs().get( 1 );
        assertEquals( "$b",
                      eventB.getIdentifier() );
        assertEquals( "EventB",
                      eventB.getObjectType() );
        assertEquals( 1,
                      eventB.getConstraint().getDescrs().size() );
        assertEquals( 1,
                      eventB.getConstraint().getDescrs().size() );

        final ExprConstraintDescr fcdB = (ExprConstraintDescr) eventB.getConstraint().getDescrs().get( 0 );
        assertEquals( "this after[1,10] $a || this not after[15,20] $a",
                      fcdB.getExpression() );

        final PatternDescr eventC = (PatternDescr) rule.getLhs().getDescrs().get( 2 );
        assertEquals( "$c",
                      eventC.getIdentifier() );
        assertEquals( "EventC",
                      eventC.getObjectType() );
        assertEquals( 1,
                      eventC.getConstraint().getDescrs().size() );
        final ExprConstraintDescr fcdC = (ExprConstraintDescr) eventC.getConstraint().getDescrs().get( 0 );
        assertEquals( "this finishes $b",
                      fcdC.getExpression() );

        final PatternDescr eventD = (PatternDescr) rule.getLhs().getDescrs().get( 3 );
        assertEquals( "$d",
                      eventD.getIdentifier() );
        assertEquals( "EventD",
                      eventD.getObjectType() );
        assertEquals( 1,
                      eventD.getConstraint().getDescrs().size() );
        final ExprConstraintDescr fcdD = (ExprConstraintDescr) eventD.getConstraint().getDescrs().get( 0 );
        assertEquals( "this not starts $a",
                      fcdD.getExpression() );

        final PatternDescr eventE = (PatternDescr) rule.getLhs().getDescrs().get( 4 );
        assertEquals( "$e",
                      eventE.getIdentifier() );
        assertEquals( "EventE",
                      eventE.getObjectType() );
        assertEquals( 1,
                      eventE.getConstraint().getDescrs().size() );

        ExprConstraintDescr fcdE = (ExprConstraintDescr) eventE.getConstraint().getDescrs().get( 0 );
        assertEquals( "this not before[1, 10] $b || after[1, 10] $c && this after[1, 5] $d",
                      fcdE.getExpression() );
    }
View Full Code Here

TOP

Related Classes of org.drools.compiler.lang.descr.PatternDescr

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.