Package org.drools.rule

Examples of org.drools.rule.LiteralConstraint


        final CompositeObjectSinkAdapter ad = new CompositeObjectSinkAdapter();
        InternalReadAccessor extractor = store.getReader( Cheese.class,
                                                          "type",
                                                          this.getClass().getClassLoader() );

        final LiteralConstraint lit = new LiteralConstraint( extractor,
                                                             equals.getEvaluator( ValueType.STRING_TYPE,
                                                                                  Operator.EQUAL ),
                                                             new ObjectFieldImpl( "stilton" ) );
        final AlphaNode al = new AlphaNode( buildContext.getNextId(),
                                            lit,
                                            new MockObjectSource( buildContext.getNextId() ),
                                            buildContext );

        ad.addObjectSink( al );

        assertNull( ad.otherSinks );
        assertNotNull( ad.hashedFieldIndexes );
        assertEquals( 1,
                      ad.hashableSinks.size() );
        assertEquals( al,
                      ad.getSinks()[0] );

        final LiteralConstraint lit2 = new LiteralConstraint( extractor,
                                                              equals.getEvaluator( ValueType.STRING_TYPE,
                                                                                   Operator.EQUAL ),
                                                              new ObjectFieldImpl( "cheddar" ) );
        final AlphaNode al2 = new AlphaNode( buildContext.getNextId(),
                                             lit2,
                                             new MockObjectSource( buildContext.getNextId() ),
                                             buildContext );

        ad.addObjectSink( al2 );

        assertNull( ad.hashedSinkMap );
        assertEquals( 2,
                      ad.hashableSinks.size() );

        final LiteralConstraint lit3 = new LiteralConstraint( extractor,
                                                              equals.getEvaluator( ValueType.STRING_TYPE,
                                                                                   Operator.EQUAL ),
                                                              new ObjectFieldImpl( "stinky" ) );
        final AlphaNode al3 = new AlphaNode( buildContext.getNextId(),
                                             lit3,
View Full Code Here


        final CompositeObjectSinkAdapter ad = new CompositeObjectSinkAdapter();
        InternalReadAccessor extractor = store.getReader( Cheese.class,
                                                          "charType",
                                                          this.getClass().getClassLoader() );

        final LiteralConstraint lit = new LiteralConstraint( extractor,
                                                             equals.getEvaluator( extractor.getValueType(),
                                                                                  Operator.EQUAL ),
                                                             new LongFieldImpl( 65 ) ); // chars are handled as integers
        final AlphaNode al = new AlphaNode( buildContext.getNextId(),
                                            lit,
                                            new MockObjectSource( buildContext.getNextId() ),
                                            buildContext );

        ad.addObjectSink( al );

        assertNull( ad.otherSinks );
        assertNotNull( ad.hashedFieldIndexes );
        assertEquals( 1,
                      ad.hashableSinks.size() );
        assertEquals( al,
                      ad.getSinks()[0] );

        final LiteralConstraint lit2 = new LiteralConstraint( extractor,
                                                              equals.getEvaluator( extractor.getValueType(),
                                                                                   Operator.EQUAL ),
                                                              new LongFieldImpl( 66 ) );
        final AlphaNode al2 = new AlphaNode( buildContext.getNextId(),
                                             lit2,
                                             new MockObjectSource( buildContext.getNextId() ),
                                             buildContext );

        ad.addObjectSink( al2 );

        assertNull( ad.hashedSinkMap );
        assertEquals( 2,
                      ad.hashableSinks.size() );

        final LiteralConstraint lit3 = new LiteralConstraint( extractor,
                                                              equals.getEvaluator( extractor.getValueType(),
                                                                                   Operator.EQUAL ),
                                                              new LongFieldImpl( 67 ) );
        final AlphaNode al3 = new AlphaNode( buildContext.getNextId(),
                                             lit3,
View Full Code Here

        final CompositeObjectSinkAdapter ad = new CompositeObjectSinkAdapter();
        InternalReadAccessor extractor = store.getReader( Cheese.class,
                                                          "charObjectType",
                                                          this.getClass().getClassLoader() );

        final LiteralConstraint lit = new LiteralConstraint( extractor,
                                                             equals.getEvaluator( extractor.getValueType(),
                                                                                  Operator.EQUAL ),
                                                             new LongFieldImpl( 65 ) ); // chars are handled as integers
        final AlphaNode al = new AlphaNode( buildContext.getNextId(),
                                            lit,
                                            new MockObjectSource( buildContext.getNextId() ),
                                            buildContext );

        ad.addObjectSink( al );

        assertNull( ad.otherSinks );
        assertNotNull( ad.hashedFieldIndexes );
        assertEquals( 1,
                      ad.hashableSinks.size() );
        assertEquals( al,
                      ad.getSinks()[0] );

        final LiteralConstraint lit2 = new LiteralConstraint( extractor,
                                                              equals.getEvaluator( extractor.getValueType(),
                                                                                   Operator.EQUAL ),
                                                              new LongFieldImpl( 66 ) );
        final AlphaNode al2 = new AlphaNode( buildContext.getNextId(),
                                             lit2,
                                             new MockObjectSource( buildContext.getNextId() ),
                                             buildContext );

        ad.addObjectSink( al2 );

        assertNull( ad.hashedSinkMap );
        assertEquals( 2,
                      ad.hashableSinks.size() );

        final LiteralConstraint lit3 = new LiteralConstraint( extractor,
                                                              equals.getEvaluator( extractor.getValueType(),
                                                                                   Operator.EQUAL ),
                                                              new LongFieldImpl( 67 ) );
        final AlphaNode al3 = new AlphaNode( buildContext.getNextId(),
                                             lit3,
View Full Code Here

        final CompositeObjectSinkAdapter ad = new CompositeObjectSinkAdapter();
        InternalReadAccessor extractor = store.getReader( Cheese.class,
                                                          "type",
                                                          this.getClass().getClassLoader() );
        final LiteralConstraint lit1 = new LiteralConstraint( extractor,
                                                              equals.getEvaluator( ValueType.STRING_TYPE,
                                                                                   Operator.EQUAL ),
                                                              new ObjectFieldImpl( "stilton" ) );
        final AlphaNode al1 = new AlphaNode( buildContext.getNextId(),
                                             lit1,
                                             new MockObjectSource( buildContext.getNextId() ),
                                             buildContext );

        final LiteralConstraint lit2 = new LiteralConstraint( extractor,
                                                              equals.getEvaluator( ValueType.STRING_TYPE,
                                                                                   Operator.EQUAL ),
                                                              new ObjectFieldImpl( "brie" ) );
        final AlphaNode al2 = new AlphaNode( buildContext.getNextId(),
                                             lit2,
                                             new MockObjectSource( buildContext.getNextId() ),
                                             buildContext );

        final LiteralConstraint lit3 = new LiteralConstraint( extractor,
                                                              equals.getEvaluator( ValueType.STRING_TYPE,
                                                                                   Operator.EQUAL ),
                                                              new ObjectFieldImpl( "muzzarela" ) );
        final AlphaNode al3 = new AlphaNode( buildContext.getNextId(),
                                             lit3,
View Full Code Here

        Rule rule2 = ((KnowledgePackageImp)pkg2).pkg.getRule( "rule1" );
        Rule rule3 = ((KnowledgePackageImp)pkg3).pkg.getRule( "rule1" );
       
        // test return value
        Pattern p1 = ( Pattern ) rule1.getLhs().getChildren().get( 0 );
        LiteralConstraint rvc1 = ( LiteralConstraint ) p1.getConstraints().get( 0 );       
       
        Pattern p2 = ( Pattern ) rule2.getLhs().getChildren().get( 0 );       
        LiteralConstraint rvc2 = ( LiteralConstraint ) p2.getConstraints().get( 0 );       
       
        assertNotSame( rvc1, rvc2 );
        assertEquals( rvc1, rvc2 );
       
        Pattern p3 = ( Pattern ) rule3.getLhs().getChildren().get( 0 );
        LiteralConstraint rvc3 = ( LiteralConstraint ) p3.getConstraints().get( 0 );       
       
        assertNotSame( rvc1, rvc3 );
        assertThat(rvc1, not( equalTo( rvc3 ) ) );
       
        // test inline eval
View Full Code Here

                           pkgBuilder.getErrors().isEmpty() );

        final Rule rule = pkgBuilder.getPackages()[0].getRule( "Test Rule" );
        final GroupElement and = rule.getLhs();
        final Pattern pat = (Pattern) and.getChildren().get( 0 );
        final LiteralConstraint fc = (LiteralConstraint) pat.getConstraints().get( 0 );
        assertTrue( "Wrong class. Expected java.math.BigDecimal. Found: " + fc.getField().getValue().getClass(),
                    fc.getField().getValue() instanceof BigDecimal );
    }
View Full Code Here

                           pkgBuilder.getErrors().isEmpty() );

        final Rule rule = pkgBuilder.getPackages()[0].getRule( "Test Rule" );
        final GroupElement and = rule.getLhs();
        final Pattern pat = (Pattern) and.getChildren().get( 0 );
        final LiteralConstraint fc = (LiteralConstraint) pat.getConstraints().get( 0 );
        assertTrue( "Wrong class. Expected java.math.BigInteger. Found: " + fc.getField().getValue().getClass(),
                    fc.getField().getValue() instanceof BigInteger );
    }
View Full Code Here

                    }
                }
            }

            if ( restriction != null ) {
                pattern.addConstraint( new LiteralConstraint( extractor,
                                                              (LiteralRestriction) restriction ) );
                continue;
            }

            Declaration declr = null;
View Full Code Here

        final FieldValue field = FieldFactory.getFieldValue( queryDescr.getName(),
                                                             ValueType.STRING_TYPE,
                                                             context.getPackageBuilder().getDateFormats() );

        final LiteralConstraint constraint = new LiteralConstraint( extractor,
                                                                    context.getConfiguration().getEvaluatorRegistry().getEvaluator( ValueType.STRING_TYPE,
                                                                                                                                    Operator.EQUAL ),
                                                                    field );
       
        PatternBuilder.registerReadAccessor( context, queryObjectType, "name", constraint );
View Full Code Here

        final GroupElement or = (GroupElement) lhs.getChildren().get( 0 );
        assertLength( 1,
                      or.getChildren() );
        final Pattern pattern = (Pattern) or.getChildren().get( 0 );

        final LiteralConstraint literalConstarint = (LiteralConstraint) pattern.getConstraints().get( 0 );
    }
View Full Code Here

TOP

Related Classes of org.drools.rule.LiteralConstraint

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.