Package org.drools.reteoo

Examples of org.drools.reteoo.RightTuple


            this.current = first;
        }

        public Object next() {
            if ( this.current != null ) {
                RightTuple returnValue = this.current;
                this.current = (RightTuple) current.getNext();
                return returnValue;
            } else {
                return null;
            }
View Full Code Here


                    LeftTuple firstTuple = new LeftTupleImpl( first.get( 0 ),
                                                              null,
                                                              false);
                    for ( int i = 1; i < first.size(); i++ ) {
                        firstTuple = new LeftTupleImpl( firstTuple,
                                                        new RightTuple( first.get( i )),
                                                        null,
                                                        false );
                    }

                    List<LeftTuple> leftTuples = new ArrayList<LeftTuple>();

                    for ( LeftTuple leftTuple = getFirst(memory.getLeftTupleMemory(), firstTuple); leftTuple != null; leftTuple = (LeftTuple) leftTuple.getNext() ) {
                        leftTuples.add( leftTuple );
                    }
                   
                    if ( lrUnlinkingEnabled ) {
                        // When L&R Unlinking is active, we need to sort the
                        // tuples here,
                        // because we might have asserted things in the wrong
                        // order,
                        // since linking a node's side means populating its
                        // memory
                        // from the OTN which stores things in a hash-set, so
                        // insertion order is not kept.
                        Collections.sort( leftTuples,
                                          new LeftTupleComparator() );

                    }
                   
                    List<List<InternalFactHandle>> actualLeftTuples = getHandlesList( leftTuples );


                    if ( !expectedLeftTuples.equals( actualLeftTuples ) ) {
                        throw new AssertionError( "line " + step.getLine() + ": left Memory expected " + expectedLeftTuples + " actually " + actualLeftTuples );
                    }

                } else if ( cmd[0].equals( "rightMemory" ) ) {
                    String args = cmd[1];
                    String listString = args.replaceAll( "h(\\d+)",
                                                         "h[$1]" );
                    Map<String, Object> vars = new HashMap<String, Object>();
                    vars.put( "h",
                              handles );
                    List< ? > expectedFactHandles = (List< ? >) MVEL.eval( listString,
                                                                           vars );

                    RightTupleMemory rightMemory = memory.getRightTupleMemory();

                    if ( expectedFactHandles.isEmpty() && rightMemory.size() != 0 ) {
                        throw new AssertionError( "line " + step.getLine() + ": right Memory expected [] actually " + print( rightMemory ));
                    } else if ( expectedFactHandles.isEmpty() && rightMemory.size() == 0 ) {
                        continue;
                    }

                    RightTuple first = new RightTuple( (InternalFactHandle) expectedFactHandles.get( 0 ) );
                    List<RightTuple> actualRightTuples = new ArrayList<RightTuple>();
                    for ( RightTuple rightTuple = getFirst(memory.getRightTupleMemory(), first); rightTuple != null; rightTuple = (RightTuple) rightTuple.getNext() ) {
                        actualRightTuples.add( rightTuple );
                    }
View Full Code Here

                        LeftTuple tuple = new LeftTupleImpl( tlist.get( 0 ),
                                                         null,
                                                         false );
                        for ( int i = 1; i < tlist.size(); i++ ) {
                            tuple = new LeftTupleImpl( tuple,
                                                   new RightTuple( tlist.get( i ) ),
                                                   null,
                                                   false );
                        }
                        leftTuples.add( tuple );
View Full Code Here

                tuple = new LeftTupleImpl( handle,
                                           null,
                                           false ); // do not keep generated tuples on the handle list
            } else {
                tuple = new LeftTupleImpl( tuple,
                                           new RightTuple( handle ),
                                           null,
                                           true );
            }
        }
        context.put( id,
View Full Code Here

        InternalFactHandle fh10 = (InternalFactHandle) ss.insert( new Foo( "mars", 0) );
        InternalFactHandle fh11 = (InternalFactHandle) ss.insert( new Foo( "snicker", 0) );
        InternalFactHandle fh12 = (InternalFactHandle) ss.insert( new Foo( "snicker", 0) );
        InternalFactHandle fh13 = (InternalFactHandle) ss.insert( new Foo( "snicker", 0) );
       
        betaMemory.getRightTupleMemory().add( new RightTuple( fh1, null ) );
        betaMemory.getRightTupleMemory().add( new RightTuple( fh2, null ) );
        betaMemory.getRightTupleMemory().add( new RightTuple( fh3, null ) );
        betaMemory.getRightTupleMemory().add( new RightTuple( fh4, null ) );
        betaMemory.getRightTupleMemory().add( new RightTuple( fh5, null ) );
        betaMemory.getRightTupleMemory().add( new RightTuple( fh6, null ) );
        betaMemory.getRightTupleMemory().add( new RightTuple( fh7, null ) );
        betaMemory.getRightTupleMemory().add( new RightTuple( fh8, null ) );
        betaMemory.getRightTupleMemory().add( new RightTuple( fh9, null ) );
       
        RightTupleIndexHashTable hashTable = (RightTupleIndexHashTable) betaMemory.getRightTupleMemory();
        // can't create a 0 hashCode, so forcing
        RightTupleList rightTupleList = new RightTupleList();
        rightTupleList.add( new RightTuple( fh10, null) );
        hashTable.getTable()[0] = rightTupleList;
        rightTupleList = new RightTupleList();
        rightTupleList.add( new RightTuple( fh11, null ) );
        rightTupleList.add( new RightTuple( fh12, null ) );
        rightTupleList.add( new RightTuple( fh13, null ) );
        ((RightTupleList)hashTable.getTable()[0]).setNext( rightTupleList );
       
        Entry[] table = hashTable.getTable();
        List list = new ArrayList();
        for ( int i = 0; i < table.length; i++ ) {
View Full Code Here

                                            35 );
        final InternalFactHandle h1 = new DefaultFactHandle( 1,
                                                             stilton1 );

        // test add
        RightTuple h1RightTuple = new RightTuple( h1, null );
        index.add( h1RightTuple );

        final RightTuple entry1 = index.first;
        assertSame( h1,
                    entry1.getFactHandle() );
        assertNull( entry1.getNext() );
        assertSame( entry1,
                    index.get( h1 ) );

        // test get
        final RightTuple entry2 = index.get( new RightTuple( h1, null ) );
        assertSame( entry1,
                    entry2 );

        // test remove
        index.remove( h1RightTuple );
View Full Code Here

        final Cheese stilton2 = new Cheese( "stilton",
                                            59 );
        final InternalFactHandle h2 = new DefaultFactHandle( 2,
                                                             stilton2 );
       
        RightTuple h1RightTuple = new RightTuple( h1, null );
        RightTuple h2RightTuple = new RightTuple( h2, null );

        // test add
        index.add( h1RightTuple );
        index.add( h2RightTuple );
        assertEquals( h1,
                      index.first.getFactHandle() );
        assertEquals( h2,
                      ((RightTuple) index.first.getNext()).getFactHandle() );

        // test get
        assertEquals( h1,
                      index.get( h1 ).getFactHandle() );
        assertEquals( h2,
                      index.get( h2 ).getFactHandle() );

        // test removal for combinations
        // remove first
        index.remove( h2RightTuple );
        assertEquals( h1RightTuple.getFactHandle(),
                      index.first.getFactHandle() );

        // remove second
        index.add( h2RightTuple );
        index.remove( h1RightTuple );
        assertEquals( h2RightTuple.getFactHandle(),
                      index.first.getFactHandle() );

        // check index type does not change, as this fact is removed
        stilton1.setType( "cheddar" );
    }
View Full Code Here

        final Cheese stilton3 = new Cheese( "stilton",
                                            59 );
        final InternalFactHandle h3 = new DefaultFactHandle( 3,
                                                             stilton3 );

        RightTuple h1RightTuple = new RightTuple( h1, null );
        RightTuple h2RightTuple = new RightTuple( h2, null );
        RightTuple h3RightTuple = new RightTuple( h3, null );
       
        // test add
        index.add( h1RightTuple );
        index.add( h2RightTuple );
        index.add( h3RightTuple );
View Full Code Here

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

        tuple = new LeftTupleImpl( tuple,
                               new RightTuple( f1,
                                               null ),
                               null,
                               true );

        final PredicateContextEntry context = (PredicateContextEntry) constraint1.createContextEntry();
View Full Code Here

        final Cheese cheddar1 = new Cheese( "cheddar",
                                            10 );
        final InternalFactHandle f1 = (InternalFactHandle) workingMemory.insert( cheddar1 );
        tuple = new LeftTupleImpl( tuple,
                               new RightTuple( f1,
                                               null ),
                               null,
                               true );

        final ReturnValueContextEntry context1 = (ReturnValueContextEntry) constraint1.createContextEntry();
View Full Code Here

TOP

Related Classes of org.drools.reteoo.RightTuple

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.