Package org.drools.core.reteoo

Examples of org.drools.core.reteoo.LeftTupleImpl


        from.addTupleSink( sink );

        final Person person1 = new Person( "xxx1",
                                           30 );
        final FactHandle person1Handle = workingMemory.insert( person1 );
        final LeftTuple tuple1 = new LeftTupleImpl( (DefaultFactHandle) person1Handle,
                                                    from,
                                                    true );
        from.assertLeftTuple( tuple1,
                              context,
                              workingMemory );

        // nothing should be asserted, as cheese1 is cheddar and we are filtering on stilton
        assertEquals( 0,
                      sink.getAsserted().size() );

        //Set cheese1 to stilton and it should now propagate
        cheese1.setType( "stilton" );
        final Person person2 = new Person( "xxx2",
                                           30 );
        final FactHandle person2Handle = workingMemory.insert( person2 );
        final LeftTuple tuple2 = new LeftTupleImpl( (DefaultFactHandle) person2Handle,
                                                    from,
                                                    true );
        from.assertLeftTuple( tuple2,
                              context,
                              workingMemory );

        final List asserted = sink.getAsserted();
        assertEquals( 1,
                      asserted.size() );
        Tuple tuple = (Tuple) ((Object[]) asserted.get( 0 ))[0];
        assertSame( person2,
                    tuple.toFactHandles()[0].getObject() );
        assertSame( cheese1,
                    tuple.toFactHandles()[1].getObject() );

        cheese2.setType( "stilton" );
        final Person person3 = new Person( "xxx2",
                                           30 );
        final FactHandle person3Handle = workingMemory.insert( person3 );
        final LeftTuple tuple3 = new LeftTupleImpl( (DefaultFactHandle) person3Handle,
                                                    from,
                                                    true );
        from.assertLeftTuple( tuple3,
                              context,
                              workingMemory );
View Full Code Here


        from.addTupleSink( sink );

        final Person person1 = new Person( "xxx1",
                                           30 );
        final FactHandle person1Handle = workingMemory.insert( person1 );
        final LeftTuple tuple1 = new LeftTupleImpl( (DefaultFactHandle) person1Handle,
                                                    from,
                                                    true );
        from.assertLeftTuple( tuple1,
                              context,
                              workingMemory );

        // nothing should be asserted, as cheese1 is cheddar and we are filtering on stilton
        assertEquals( 0,
                      sink.getAsserted().size() );

        //Set cheese1 to stilton and it should now propagate
        cheese1.setPrice( 30 );
        final Person person2 = new Person( "xxx2",
                                           30 );
        final FactHandle person2Handle = workingMemory.insert( person2 );
        final LeftTuple tuple2 = new LeftTupleImpl( (DefaultFactHandle) person2Handle,
                                                    from,
                                                    true );
        from.assertLeftTuple( tuple2,
                              context,
                              workingMemory );

        final List asserted = sink.getAsserted();
        assertEquals( 1,
                      asserted.size() );
        Tuple tuple = (Tuple) ((Object[]) asserted.get( 0 ))[0];
        assertSame( person2,
                    tuple.toFactHandles()[0].getObject() );
        assertSame( cheese1,
                    tuple.toFactHandles()[1].getObject() );

        cheese2.setPrice( 30 );
        final Person person3 = new Person( "xxx2",
                                           30 );
        final FactHandle person3Handle = workingMemory.insert( person3 );
        final LeftTuple tuple3 = new LeftTupleImpl( (DefaultFactHandle) person3Handle,
                                                    from,
                                                    true );
        from.assertLeftTuple( tuple3,
                              context,
                              workingMemory );
View Full Code Here

        final List asserted = sink.getAsserted();

        final Person person1 = new Person( "xxx2",
                                           30 );
        final FactHandle person1Handle = workingMemory.insert( person1 );
        final LeftTuple tuple = new LeftTupleImpl( (DefaultFactHandle) person1Handle,
                                                   from,
                                                   true );
        from.assertLeftTuple( tuple,
                              context,
                              workingMemory );

        assertEquals( 2,
                      asserted.size() );

        final FromMemory memory = (FromMemory) workingMemory.getNodeMemory( from );
        assertEquals( 1,
                      memory.betaMemory.getLeftTupleMemory().size() );
        assertNull( memory.betaMemory.getRightTupleMemory() );
        RightTuple rightTuple2 = tuple.getFirstChild().getRightParent();
        RightTuple rightTuple1 = tuple.getFirstChild().getLeftParentNext().getRightParent();
        assertFalse( rightTuple1.equals( rightTuple2 ) );
        assertNull( tuple.getFirstChild().getLeftParentNext().getLeftParentNext() );

        final InternalFactHandle handle2 = rightTuple2.getFactHandle();
        final InternalFactHandle handle1 = rightTuple1.getFactHandle();
        assertEquals( handle1.getObject(),
                      cheese2 );
View Full Code Here

       
        final MockLeftTupleSink sink = new MockLeftTupleSink( 5 );
        from.addTupleSink( sink );

        final FactHandle handle = workingMemory.insert( "xxx" );
        final LeftTuple tuple1 = new LeftTupleImpl( (DefaultFactHandle) handle,
                                                    from,
                                                    true );
        from.assertLeftTuple( tuple1,
                              context,
                              workingMemory );
View Full Code Here

                                              any( InternalFactHandle.class ) ) ).thenReturn( true );
        when( constraint.isAllowedCachedRight( any( LeftTupleImpl.class ),
                                               any( ContextEntry.class ) ) ).thenReturn( true );

        final DefaultFactHandle f0 = new DefaultFactHandle( 0, "cheese" );
        final LeftTupleImpl tuple0 = new LeftTupleImpl( f0, this.node, true );

        // assert tuple, should add one to left memory
        this.node.assertLeftTuple( tuple0,
                                   this.context,
                                   this.workingMemory );
        // check memories, left memory is populated, right memory is emptys
        assertEquals( 1,
                      this.memory.getLeftTupleMemory().size() );
        assertEquals( 0,
                      this.memory.getRightTupleMemory().size() );

        // assert tuple, should add left memory should be 2
        final DefaultFactHandle f1 = new DefaultFactHandle( 1, "cheese" );
        final LeftTupleImpl tuple1 = new LeftTupleImpl( f1, this.node, true );
        this.node.assertLeftTuple( tuple1,
                                   this.context,
                                   this.workingMemory );
        assertEquals( 2,
                      this.memory.getLeftTupleMemory().size() );
View Full Code Here

        this.node.addTupleSink( this.sink );

        this.memory = (BetaMemory) this.workingMemory.getNodeMemory( this.node );

        final DefaultFactHandle f0 = new DefaultFactHandle( 0, "cheese" );
        final LeftTupleImpl tuple0 = new LeftTupleImpl( f0, this.node, true );

        this.node.assertObject( f0,
                                pctxFactory.createPropagationContext(0, PropagationContext.INSERTION, null, null, f0),
                                this.workingMemory );

        // assert tuple
        this.node.assertLeftTuple( tuple0,
                                   pctxFactory.createPropagationContext(0, PropagationContext.INSERTION, null, null, f0),
                                   this.workingMemory );

        assertEquals( 1,
                      this.sink.getAsserted().size() );

        assertNull( this.memory.getLeftTupleMemory() );

        assertEquals( 1,
                      this.memory.getRightTupleMemory().size() );

        assertEquals( new LeftTupleImpl( tuple0, f0.getFirstRightTuple(), this.sink,
                                         true ),
                      ( (Object[]) this.sink.getAsserted().get( 0 ) )[0] );
    }
View Full Code Here

                                this.context,
                                this.workingMemory );
        assertEquals( 2,
                      this.memory.getRightTupleMemory().size() );

        RightTuple rightTuple = this.memory.getRightTupleMemory().getFirst( new LeftTupleImpl( f0, this.node, true ), null, null );

        final InternalFactHandle rf0 = rightTuple.getFactHandle();
        final InternalFactHandle rf1 = ( (RightTuple) rightTuple.getNext() )
                .getFactHandle();
View Full Code Here

                                this.context,
                                this.workingMemory );

        // assert tuple, should add left memory should be 2
        final DefaultFactHandle f1 = new DefaultFactHandle( 1, "cheese" );
        final LeftTupleImpl tuple1 = new LeftTupleImpl( f1, this.node, true );
        this.node.assertLeftTuple( tuple1,
                                   this.context,
                                   this.workingMemory );

        assertEquals( 1,
                      this.sink.getAsserted().size() );

        assertEquals( new LeftTupleImpl( tuple1, f0.getFirstRightTuple(), this.sink,
                                         true ),
                      ( (Object[]) this.sink.getAsserted().get( 0 ) )[0] );

        final DefaultFactHandle f2 = new DefaultFactHandle( 2, "cheese" );
        final LeftTupleImpl tuple2 = new LeftTupleImpl( f2, this.node, true );
        this.node.assertLeftTuple( tuple2,
                                   this.context,
                                   this.workingMemory );

        assertEquals( 2,
                      this.sink.getAsserted().size() );
        assertEquals( new LeftTupleImpl( tuple2, f0.getFirstRightTuple(), this.sink,
                                         true ),
                      ( (Object[]) this.sink.getAsserted().get( 1 ) )[0] );

        final DefaultFactHandle f3 = (DefaultFactHandle) this.workingMemory
                .insert( "test2" );
        this.node.assertObject( f3,
                                this.context,
                                this.workingMemory );

        assertEquals( 4,
                      this.sink.getAsserted().size() );

        final List tuples = new ArrayList();
        tuples.add( ( (Object[]) this.sink.getAsserted().get( 2 ) )[0] );
        tuples.add( ( (Object[]) this.sink.getAsserted().get( 3 ) )[0] );

        assertTrue( tuples.contains( new LeftTupleImpl( tuple1, f3
                .getFirstRightTuple(), this.sink, true ) ) );
        assertTrue( tuples.contains( new LeftTupleImpl( tuple2, f3
                .getFirstRightTuple(), this.sink, true ) ) );
    }
View Full Code Here

                                this.context,
                                this.workingMemory );

        final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory
                .insert( "test1" );
        final LeftTupleImpl tuple1 = new LeftTupleImpl( f1, this.node, true );
        this.node.assertLeftTuple( tuple1,
                                   this.context,
                                   this.workingMemory );

        final DefaultFactHandle f2 = (DefaultFactHandle) this.workingMemory
                .insert( "test2" );
        final LeftTupleImpl tuple2 = new LeftTupleImpl( f2, this.node, true );
        this.node.assertLeftTuple( tuple2,
                                   this.context,
                                   this.workingMemory );

        final DefaultFactHandle f3 = (DefaultFactHandle) this.workingMemory
                .insert( "test3" );
        this.node.assertObject( f3,
                                this.context,
                                this.workingMemory );

        final DefaultFactHandle f4 = (DefaultFactHandle) this.workingMemory
                .insert( "test4" );
        this.node.assertObject( f4,
                                this.context,
                                this.workingMemory );

        assertLength( 6,
                      this.sink.getAsserted() );

        // Double check the item is in memory
        final BetaMemory memory = (BetaMemory) this.workingMemory
                .getNodeMemory( this.node );
        assertTrue( memory.getRightTupleMemory().contains(
                                                           f0.getFirstRightTuple() ) );

        // Retract an object, check propagations and memory
        this.node.retractRightTuple( f0.getFirstRightTuple(),
                                     this.context,
                                     this.workingMemory );
        assertLength( 2,
                      this.sink.getRetracted() );

        List tuples = new ArrayList();
        tuples.add( ( (Object[]) this.sink.getRetracted().get( 0 ) )[0] );
        tuples.add( ( (Object[]) this.sink.getRetracted().get( 1 ) )[0] );

        assertTrue( tuples.contains( new LeftTupleImpl( tuple1, f0
                .getFirstRightTuple(), this.sink, true ) ) );
        assertTrue( tuples.contains( new LeftTupleImpl( tuple1, f0
                .getFirstRightTuple(), this.sink, true ) ) );

        // Now check the item is no longer in memory
        assertFalse( memory.getRightTupleMemory().contains(
                                                            f0.getFirstRightTuple() ) );

        this.node.retractLeftTuple( tuple2,
                                    this.context,
                                    this.workingMemory );
        assertEquals( 4,
                      this.sink.getRetracted().size() );

        tuples = new ArrayList();
        tuples.add( ( (Object[]) this.sink.getRetracted().get( 2 ) )[0] );
        tuples.add( ( (Object[]) this.sink.getRetracted().get( 3 ) )[0] );

        assertTrue( tuples.contains( new LeftTupleImpl( tuple2, f3
                .getFirstRightTuple(), this.sink, true ) ) );
        assertTrue( tuples.contains( new LeftTupleImpl( tuple2, f4
                .getFirstRightTuple(), this.sink, true ) ) );
    }
View Full Code Here

                                this.context,
                                this.workingMemory );

        // assert tuple, should add left memory should be 2
        final DefaultFactHandle f1 = new DefaultFactHandle( 1, "cheese" );
        final LeftTupleImpl tuple1 = new LeftTupleImpl( f1, this.node, true );
        this.node.assertLeftTuple( tuple1,
                                   this.context,
                                   this.workingMemory );

        // Should be no assertions
View Full Code Here

TOP

Related Classes of org.drools.core.reteoo.LeftTupleImpl

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.