Package org.drools.common

Examples of org.drools.common.InternalWorkingMemory


        str += "    otn2,[h2];\n";

        NodeTestResult result = executeTest( str );
        Map<String, Object> map = result.context;

        InternalWorkingMemory wm = (InternalWorkingMemory) map.get( "WorkingMemory" );
        List<InternalFactHandle> handles = (List<InternalFactHandle>) map.get( "Handles" );

        JoinNode join1 = (JoinNode) map.get( "join1" );

        BetaMemory memory = (BetaMemory) wm.getNodeMemory( join1 );
        assertEquals( 1,
                      memory.getRightTupleMemory().size() );

        assertEquals( 1,
                      memory.getLeftTupleMemory().size() );
View Full Code Here


        str += "    rightMemory,[h0];\n";

        NodeTestResult result = executeTest( str );
        Map<String, Object> map = result.context;

        InternalWorkingMemory wm = (InternalWorkingMemory) map.get( "WorkingMemory" );
        List<InternalFactHandle> handles = (List<InternalFactHandle>) map.get( "Handles" );

        JoinNode join1 = (JoinNode) map.get( "join1" );

        BetaMemory memory = (BetaMemory) wm.getNodeMemory( join1 );
        assertEquals( 1,
                      memory.getRightTupleMemory().size() );

        assertEquals( 1,
                      memory.getLeftTupleMemory().size() );
View Full Code Here

        str += "    rightMemory, [h4];\n";

        NodeTestResult result = executeTest( str );
        Map<String, Object> map = result.context;

        InternalWorkingMemory wm = (InternalWorkingMemory) map.get( "WorkingMemory" );
        List<InternalFactHandle> handles = (List<InternalFactHandle>) map.get( "Handles" );

        JoinNode join1 = (JoinNode) map.get( "join1" );

        BetaMemory memory = (BetaMemory) wm.getNodeMemory( join1 );
        assertEquals( 1,
                      memory.getRightTupleMemory().size() );

        assertEquals( 1,
                      memory.getLeftTupleMemory().size() );
View Full Code Here

        str += "    rightMemory, [h4];\n";

        NodeTestResult result = executeTest( str );
        Map<String, Object> map = result.context;

        InternalWorkingMemory wm = (InternalWorkingMemory) map.get( "WorkingMemory" );
        List<InternalFactHandle> handles = (List<InternalFactHandle>) map.get( "Handles" );

        JoinNode join1 = (JoinNode) map.get( "join1" );

        BetaMemory memory = (BetaMemory) wm.getNodeMemory( join1 );
        assertEquals( 1,
                      memory.getRightTupleMemory().size() );

        assertEquals( 1,
                      memory.getLeftTupleMemory().size() );
View Full Code Here

        str += "    rightMemory, [];\n";
       
        NodeTestResult result = executeTest( str );
        Map<String, Object> map = result.context;

        InternalWorkingMemory wm = (InternalWorkingMemory) map.get( "WorkingMemory" );
        List<InternalFactHandle> handles = (List<InternalFactHandle>) map.get( "Handles" );

        JoinNode join1 = (JoinNode) map.get( "join1" );

        BetaMemory memory = (BetaMemory) wm.getNodeMemory( join1 );
        assertEquals( 2,
                      memory.getRightTupleMemory().size() );

        assertEquals( 3,
                      memory.getLeftTupleMemory().size() );
       
        JoinNode join2 = (JoinNode) map.get( "join2" );

        memory = (BetaMemory) wm.getNodeMemory( join2 );
        assertEquals( 0,
                      memory.getRightTupleMemory().size() );

        assertEquals( 2,
                      memory.getLeftTupleMemory().size() );
View Full Code Here

    }

    @Test
    public void testId() {
        final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
        InternalWorkingMemory workingMemory = (InternalWorkingMemory) ruleBase.newStatefulSession();
        assertEquals( 0,
                      workingMemory.getId() );
        workingMemory = (InternalWorkingMemory) ruleBase.newStatefulSession();
        assertEquals( 1,
                      workingMemory.getId() );
    }
View Full Code Here

                 "value1" );
        map.put( "global2",
                 "value2" );
        final GlobalResolver resolver = new MapGlobalResolver(map);
        final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
        final InternalWorkingMemory workingMemory = (InternalWorkingMemory) ruleBase.newStatefulSession();
        workingMemory.setGlobalResolver( resolver );
        assertEquals( "value1",
                      workingMemory.getGlobal( "global1" ) );
        assertEquals( "value2",
                      workingMemory.getGlobal( "global2" ) );
    }
View Full Code Here

     * @throws IntrospectionException
     */
    @Test
    public void testLiteralConstraint() throws IntrospectionException {
        final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
        final InternalWorkingMemory workingMemory = (InternalWorkingMemory) ruleBase.newStatefulSession();

        final ClassFieldReader extractor = store.getReader( Cheese.class,
                                                            "type",
                                                            getClass().getClassLoader() );

        final FieldValue field = FieldFactory.getFieldValue( "cheddar" );

        final Evaluator evaluator = equals.getEvaluator( ValueType.STRING_TYPE,
                                                         Operator.EQUAL );

        final LiteralConstraint constraint = new LiteralConstraint( extractor,
                                                                    evaluator,
                                                                    field );
        final ContextEntry context = constraint.createContextEntry();

        final Cheese cheddar = new Cheese( "cheddar",
                                           5 );

        final InternalFactHandle cheddarHandle = (InternalFactHandle) workingMemory.insert( cheddar );

        // check constraint
        assertTrue( constraint.isAllowed( cheddarHandle,
                                          workingMemory,
                                          context ) );

        final Cheese stilton = new Cheese( "stilton",
                                           5 );

        final InternalFactHandle stiltonHandle = (InternalFactHandle) workingMemory.insert( stilton );

        // check constraint
        assertFalse( constraint.isAllowed( stiltonHandle,
                                           workingMemory,
                                           context ) );
View Full Code Here

     * @throws IntrospectionException
     */
    @Test
    public void testPrimitiveLiteralConstraint() throws IntrospectionException {
        final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
        final InternalWorkingMemory workingMemory = (InternalWorkingMemory) ruleBase.newStatefulSession();

        final ClassFieldReader extractor = store.getReader( Cheese.class,
                                                            "price",
                                                            getClass().getClassLoader() );

        final FieldValue field = FieldFactory.getFieldValue( 5 );

        final Evaluator evaluator = equals.getEvaluator( ValueType.PINTEGER_TYPE,
                                                         Operator.EQUAL );

        final LiteralConstraint constraint = new LiteralConstraint( extractor,
                                                                    evaluator,
                                                                    field );
        final ContextEntry context = constraint.createContextEntry();

        final Cheese cheddar = new Cheese( "cheddar",
                                           5 );

        final InternalFactHandle cheddarHandle = (InternalFactHandle) workingMemory.insert( cheddar );

        // check constraint
        assertTrue( constraint.isAllowed( cheddarHandle,
                                          workingMemory,
                                          context ) );

        final Cheese stilton = new Cheese( "stilton",
                                           10 );

        final InternalFactHandle stiltonHandle = (InternalFactHandle) workingMemory.insert( stilton );

        // check constraint
        assertFalse( constraint.isAllowed( stiltonHandle,
                                           workingMemory,
                                           context ) );
View Full Code Here

     * @throws IntrospectionException
     */
    @Test
    public void testPredicateConstraint() throws IntrospectionException {
        final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
        final InternalWorkingMemory workingMemory = (InternalWorkingMemory) ruleBase.newStatefulSession();

        final InternalReadAccessor priceExtractor = store.getReader( Cheese.class,
                                                                     "price",
                                                                     getClass().getClassLoader() );

        Pattern pattern = new Pattern( 0,
                                       new ClassObjectType( Cheese.class ) );

        // Bind the extractor to a decleration
        // Declarations know the pattern they derive their value form
        final Declaration price1Declaration = new Declaration( "price1",
                                                               priceExtractor,
                                                               pattern );

        pattern = new Pattern( 1,
                               new ClassObjectType( Cheese.class ) );

        // Bind the extractor to a decleration
        // Declarations know the pattern they derive their value form
        final Declaration price2Declaration = new Declaration( "price2",
                                                               priceExtractor,
                                                               pattern );

        final PredicateExpression evaluator = new PredicateExpression() {

            private static final long serialVersionUID = 510l;

            public boolean evaluate(Object object,
                                    Tuple tuple,
                                    Declaration[] previousDeclarations,
                                    Declaration[] localDeclarations,
                                    WorkingMemory workingMemory,
                                    Object context) {
                int price1 = previousDeclarations[0].getIntValue( (InternalWorkingMemory) workingMemory,
                                                                  workingMemory.getObject( tuple.get( previousDeclarations[0] ) ) );
                int price2 = localDeclarations[0].getIntValue( (InternalWorkingMemory) workingMemory,
                                                               object );

                return (price2 == (price1 * 2));

            }

            public Object createContext() {
                return null;
            }

            public void readExternal(ObjectInput in) throws IOException,
                                                    ClassNotFoundException {
            }

            public void writeExternal(ObjectOutput out) throws IOException {
            }
        };

        final PredicateConstraint constraint1 = new PredicateConstraint( evaluator,
                                                                         new Declaration[]{price1Declaration},
                                                                         new Declaration[]{price2Declaration},
                                                                         new String[]{},
                                                                         new String[]{});

        final Cheese cheddar0 = new Cheese( "cheddar",
                                            5 );
        final InternalFactHandle f0 = (InternalFactHandle) workingMemory.insert( cheddar0 );
        LeftTupleImpl tuple = new LeftTupleImpl( f0,
                                         null,
                                         true );

        final Cheese cheddar1 = new Cheese( "cheddar",
                                            10 );
        final InternalFactHandle f1 = (InternalFactHandle) workingMemory.insert( cheddar1 );

        tuple = new LeftTupleImpl( tuple,
                               new RightTuple( f1,
                                               null ),
                               null,
View Full Code Here

TOP

Related Classes of org.drools.common.InternalWorkingMemory

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.