[jboss-svn-commits] JBL Code SVN: r19400 - labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Apr 3 18:25:32 EDT 2008


Author: tirelli
Date: 2008-04-03 18:25:31 -0400 (Thu, 03 Apr 2008)
New Revision: 19400

Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java
Log:
JBRULES-1520: fixing accumulate

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java	2008-04-03 20:04:35 UTC (rev 19399)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java	2008-04-03 22:25:31 UTC (rev 19400)
@@ -126,7 +126,6 @@
     public void assertLeftTuple(final LeftTuple leftTuple,
                                 final PropagationContext context,
                                 final InternalWorkingMemory workingMemory) {
-        if ( this.getId() == 7 ) System.out.println( "AssertLeft  : " + leftTuple );
 
         final CollectMemory memory = (CollectMemory) workingMemory.getNodeMemory( this );
 
@@ -143,7 +142,8 @@
         if ( this.tupleMemoryEnabled ) {
             memory.betaMemory.getLeftTupleMemory().add( leftTuple );
             memory.betaMemory.getCreatedHandles().put( leftTuple,
-                                                       colctx );
+                                                       colctx,
+                                                       false );
         }
 
         this.constraints.updateFromTuple( memory.betaMemory.getContext(),
@@ -186,8 +186,6 @@
                                  final PropagationContext context,
                                  final InternalWorkingMemory workingMemory) {
 
-        if ( this.getId() == 7 ) System.out.println( "RetractLeft : " + leftTuple );
-
         final CollectMemory memory = (CollectMemory) workingMemory.getNodeMemory( this );
         memory.betaMemory.getLeftTupleMemory().remove( leftTuple );
         final CollectContext colctx = (CollectContext) memory.betaMemory.getCreatedHandles().remove( leftTuple );
@@ -212,26 +210,6 @@
     }
 
     /**
-     * @param leftTuple
-     * @param colctx
-     * @return
-     */
-    private LeftTuple getFirstMatch(final LeftTuple leftTuple,
-                                    final CollectContext colctx) {
-        // unlink all right matches 
-        LeftTuple child = leftTuple.getBetaChildren();
-
-        if ( colctx.propagated ) {
-            // To do that, we need to skip the first N children that are in fact
-            // the propagated tuples
-            for ( int i = 0; i < this.sink.size(); i++ ) {
-                child = child.getLeftParentNext();
-            }
-        }
-        return child;
-    }
-
-    /**
      * @inheritDoc
      *
      *  When a new object is asserted into a CollectNode, do this:
@@ -244,8 +222,6 @@
                              final PropagationContext context,
                              final InternalWorkingMemory workingMemory) {
 
-        if ( this.getId() == 7 ) System.out.println( "AssertRight : " + factHandle );
-
         final CollectMemory memory = (CollectMemory) workingMemory.getNodeMemory( this );
         final RightTuple rightTuple = new RightTuple( factHandle,
                                                       this );
@@ -289,12 +265,11 @@
     public void retractRightTuple(final RightTuple rightTuple,
                                   final PropagationContext context,
                                   final InternalWorkingMemory workingMemory) {
-        if ( this.getId() == 7 ) System.out.println( "retractRight: " + rightTuple );
 
         final CollectMemory memory = (CollectMemory) workingMemory.getNodeMemory( this );
         memory.betaMemory.getRightTupleMemory().remove( rightTuple );
 
-        for ( LeftTuple leftTuple = getFirstMatchFromRight( rightTuple ); leftTuple != null; ) {
+        for ( LeftTuple leftTuple = rightTuple.getBetaChildren(); leftTuple != null; ) {
             LeftTuple tmp = leftTuple.getRightParentNext();
             this.modifyTuple( false,
                               leftTuple.getParent(),
@@ -306,14 +281,6 @@
         }
     }
 
-    private LeftTuple getFirstMatchFromRight(RightTuple rightTuple) {
-        LeftTuple match = rightTuple.getBetaChildren();
-        while( match.getRightParent() != rightTuple ) {
-            match = match.getRightParentNext();
-        }
-        return match;
-    }
-
     /**
      * Modifies the results match for a tuple, retracting it and repropagating
      * if constraints allow it
@@ -340,6 +307,7 @@
             if( firstMatch != null ) { 
                 // temporarily break the linked list to avoid wrong retracts
                 firstMatch.getLeftParentPrevious().setLeftParentNext( null );
+                firstMatch.setLeftParentPrevious( null );
             }
             this.sink.propagateRetractLeftTuple( leftTuple,
                                                  context,
@@ -434,6 +402,29 @@
         }
     }
 
+    /**
+     * Skips the propagated tuple handles and return the first handle
+     * in the list that correspond to a match
+     * 
+     * @param leftTuple
+     * @param colctx
+     * @return
+     */
+    private LeftTuple getFirstMatch(final LeftTuple leftTuple,
+                                    final CollectContext colctx) {
+        // unlink all right matches 
+        LeftTuple child = leftTuple.getBetaChildren();
+
+        if ( colctx.propagated ) {
+            // To do that, we need to skip the first N children that are in fact
+            // the propagated tuples
+            for ( int i = 0; i < this.sink.size(); i++ ) {
+                child = child.getLeftParentNext();
+            }
+        }
+        return child;
+    }
+
     public void updateSink(final LeftTupleSink sink,
                            final PropagationContext context,
                            final InternalWorkingMemory workingMemory) {

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java	2008-04-03 20:04:35 UTC (rev 19399)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java	2008-04-03 22:25:31 UTC (rev 19400)
@@ -163,10 +163,6 @@
         this.leftParentNext = null;
         //
         this.blocker = null;
-        //
-        this.rightParent = null;
-        this.rightParentPrevious = null;
-        this.rightParentNext = null;
     }
 
     public void unlinkFromRightParent() {
@@ -190,10 +186,6 @@
 
         //this.parent  = null;
 
-        this.leftParent = null;
-        this.leftParentPrevious = null;
-        this.leftParentNext = null;
-
         this.blocker = null;
 
         this.rightParent = null;




More information about the jboss-svn-commits mailing list