[jboss-svn-commits] JBL Code SVN: r32380 - 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
Sat Apr 3 14:36:59 EDT 2010
Author: tirelli
Date: 2010-04-03 14:36:58 -0400 (Sat, 03 Apr 2010)
New Revision: 32380
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeLeftTupleSinkAdapter.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EmptyLeftTupleSinkAdapter.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/JoinNode.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTupleSinkPropagator.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleLeftTupleSinkAdapter.java
Log:
Fixing tests
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java 2010-04-03 18:04:39 UTC (rev 32379)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java 2010-04-03 18:36:58 UTC (rev 32380)
@@ -154,6 +154,8 @@
// add a match
addMatch( leftTuple,
rightTuple,
+ null,
+ null,
workingMemory,
memory,
accresult );
@@ -243,6 +245,8 @@
final AccumulateContext accctx = (AccumulateContext) memory.betaMemory.getCreatedHandles().get( leftTuple );
addMatch( leftTuple,
rightTuple,
+ null,
+ null,
workingMemory,
memory,
accctx );
@@ -335,6 +339,8 @@
// add a new match
addMatch( leftTuple,
rightTuple,
+ null,
+ null,
workingMemory,
memory,
accctx );
@@ -348,10 +354,12 @@
if ( this.constraints.isAllowedCachedLeft( memory.betaMemory.getContext(),
handle ) ) {
- if ( childLeftTuple != null && childLeftTuple.getRightParent() != rightTuple ) {
+ if ( childLeftTuple == null || childLeftTuple.getRightParent() != rightTuple ) {
// add a new match
addMatch( leftTuple,
rightTuple,
+ childLeftTuple,
+ null,
workingMemory,
memory,
accctx );
@@ -359,7 +367,6 @@
// we must re-add this to ensure deterministic iteration
LeftTuple temp = childLeftTuple.getLeftParentNext();
childLeftTuple.reAddRight();
- childLeftTuple.reAddLeft();
childLeftTuple = temp;
}
} else if ( childLeftTuple != null && childLeftTuple.getRightParent() == rightTuple ) {
@@ -450,6 +457,8 @@
// add a new match
addMatch( leftTuple,
rightTuple,
+ null,
+ null,
workingMemory,
memory,
accctx );
@@ -467,24 +476,30 @@
if ( this.constraints.isAllowedCachedRight( memory.betaMemory.getContext(),
leftTuple ) ) {
final AccumulateContext accctx = (AccumulateContext) memory.betaMemory.getCreatedHandles().get( leftTuple );
- if ( childLeftTuple == null || childLeftTuple.getLeftParent() == leftTuple ) {
+ LeftTuple temp = null;
+ if ( childLeftTuple != null && childLeftTuple.getLeftParent() == leftTuple ) {
+ temp = childLeftTuple.getRightParentNext();
// we must re-add this to ensure deterministic iteration
childLeftTuple.reAddLeft();
- childLeftTuple.reAddRight();
removeMatch( rightTuple,
childLeftTuple,
workingMemory,
memory,
accctx,
true );
-
+ childLeftTuple = childLeftTuple.getRightParentNext();
}
// add a new match
addMatch( leftTuple,
rightTuple,
+ null,
+ childLeftTuple,
workingMemory,
memory,
accctx );
+ if( temp != null ) {
+ childLeftTuple = temp;
+ }
evaluateResultConstraints( ActivitySource.RIGHT,
leftTuple,
context,
@@ -617,6 +632,8 @@
// assert
this.sink.propagateAssertLeftTuple( leftTuple,
accctx.result,
+ null,
+ null,
context,
workingMemory,
this.tupleMemoryEnabled );
@@ -643,6 +660,8 @@
true );
sink.assertLeftTuple( new LeftTuple( leftTuple,
accctx.result,
+ null,
+ null,
sink,
this.tupleMemoryEnabled ),
context,
@@ -713,6 +732,8 @@
private void addMatch(final LeftTuple leftTuple,
final RightTuple rightTuple,
+ final LeftTuple currentLeftChild,
+ final LeftTuple currentRightChild,
final InternalWorkingMemory workingMemory,
final AccumulateMemory memory,
final AccumulateContext accresult) {
@@ -734,6 +755,8 @@
// linking left and right by creating a new left tuple
new LeftTuple( leftTuple,
rightTuple,
+ currentLeftChild,
+ currentRightChild,
this,
this.tupleMemoryEnabled );
}
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 2010-04-03 18:04:39 UTC (rev 32379)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java 2010-04-03 18:36:58 UTC (rev 32380)
@@ -180,6 +180,8 @@
handle ) ) {
addMatch( leftTuple,
rightTuple,
+ null,
+ null,
colctx );
}
}
@@ -265,6 +267,8 @@
final CollectContext colctx = (CollectContext) memory.betaMemory.getCreatedHandles().get( leftTuple );
addMatch( leftTuple,
rightTuple,
+ null,
+ null,
colctx );
evaluateResultConstraints( ActivitySource.RIGHT,
leftTuple,
@@ -356,6 +360,8 @@
// add a new match
addMatch( leftTuple,
rightTuple,
+ null,
+ null,
colctx );
}
@@ -367,16 +373,17 @@
if ( this.constraints.isAllowedCachedLeft( memory.betaMemory.getContext(),
handle ) ) {
- if ( childLeftTuple != null && childLeftTuple.getRightParent() != rightTuple ) {
+ if ( childLeftTuple == null || childLeftTuple.getRightParent() != rightTuple ) {
// add a new match
addMatch( leftTuple,
rightTuple,
+ childLeftTuple,
+ null,
colctx );
} else {
// we must re-add this to ensure deterministic iteration
LeftTuple temp = childLeftTuple.getLeftParentNext();
childLeftTuple.reAddRight();
- childLeftTuple.reAddLeft();
childLeftTuple = temp;
}
} else if ( childLeftTuple != null && childLeftTuple.getRightParent() == rightTuple ) {
@@ -453,6 +460,8 @@
// add a new match
addMatch( leftTuple,
rightTuple,
+ null,
+ null,
colctx );
evaluateResultConstraints( ActivitySource.RIGHT,
leftTuple,
@@ -468,10 +477,11 @@
if ( this.constraints.isAllowedCachedRight( memory.betaMemory.getContext(),
leftTuple ) ) {
final CollectContext colctx = (CollectContext) memory.betaMemory.getCreatedHandles().get( leftTuple );
- if ( childLeftTuple == null || childLeftTuple.getLeftParent() == leftTuple ) {
+ LeftTuple temp = null;
+ if ( childLeftTuple != null && childLeftTuple.getLeftParent() == leftTuple ) {
// we must re-add this to ensure deterministic iteration
+ temp = childLeftTuple.getRightParentNext();
childLeftTuple.reAddLeft();
- childLeftTuple.reAddRight();
removeMatch( rightTuple,
childLeftTuple,
colctx );
@@ -479,7 +489,12 @@
// add a new match
addMatch( leftTuple,
rightTuple,
+ null,
+ childLeftTuple,
colctx );
+ if( temp != null ) {
+ childLeftTuple = temp;
+ }
evaluateResultConstraints( ActivitySource.RIGHT,
leftTuple,
context,
@@ -588,6 +603,8 @@
// assert
this.sink.propagateAssertLeftTuple( leftTuple,
colctx.resultTuple,
+ null,
+ null,
context,
workingMemory,
this.tupleMemoryEnabled );
@@ -638,6 +655,8 @@
true );
sink.assertLeftTuple( new LeftTuple( leftTuple,
colctx.resultTuple,
+ null,
+ null,
sink,
this.tupleMemoryEnabled ),
context,
@@ -686,6 +705,8 @@
@SuppressWarnings("unchecked")
private void addMatch(final LeftTuple leftTuple,
final RightTuple rightTuple,
+ final LeftTuple currentLeftChild,
+ final LeftTuple currentRightChild,
final CollectContext colctx) {
InternalFactHandle handle = rightTuple.getFactHandle();
if ( this.unwrapRightObject ) {
@@ -698,6 +719,8 @@
// linking left and right by creating a new left tuple
new LeftTuple( leftTuple,
rightTuple,
+ currentLeftChild,
+ currentRightChild,
this,
this.tupleMemoryEnabled );
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeLeftTupleSinkAdapter.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeLeftTupleSinkAdapter.java 2010-04-03 18:04:39 UTC (rev 32379)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CompositeLeftTupleSinkAdapter.java 2010-04-03 18:36:58 UTC (rev 32380)
@@ -32,6 +32,8 @@
public void propagateAssertLeftTuple(final LeftTuple leftTuple,
final RightTuple rightTuple,
+ final LeftTuple currentLeftChild,
+ final LeftTuple currentRightChild,
final PropagationContext context,
final InternalWorkingMemory workingMemory,
final boolean leftTupleMemoryEnabled) {
@@ -39,6 +41,8 @@
for ( LeftTupleSinkNode sink = this.sinks.getFirst(); sink != null; sink = sink.getNextLeftTupleSinkNode() ) {
LeftTuple newLeftTuple = new LeftTuple( leftTuple,
rightTuple,
+ currentLeftChild,
+ currentRightChild,
sink,
leftTupleMemoryEnabled );
doPropagateAssertLeftTuple( context,
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EmptyLeftTupleSinkAdapter.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EmptyLeftTupleSinkAdapter.java 2010-04-03 18:04:39 UTC (rev 32379)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/EmptyLeftTupleSinkAdapter.java 2010-04-03 18:36:58 UTC (rev 32380)
@@ -25,6 +25,8 @@
public void propagateAssertLeftTuple(final LeftTuple leftTuple,
final RightTuple rightTuple,
+ final LeftTuple currentLeftChild,
+ final LeftTuple currentRightChild,
final PropagationContext context,
final InternalWorkingMemory workingMemory,
final boolean leftTupleMemoryEnabled) {
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java 2010-04-03 18:04:39 UTC (rev 32379)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/FromNode.java 2010-04-03 18:36:58 UTC (rev 32380)
@@ -260,6 +260,8 @@
// this is a new match, so propagate as assert
this.sink.propagateAssertLeftTuple( leftTuple,
rightTuple,
+ null,
+ null,
context,
workingMemory,
this.tupleMemoryEnabled );
@@ -395,6 +397,8 @@
for ( RightTuple rightTuple = rightTuples; rightTuple != null; rightTuple = (RightTuple) rightTuples.getNext() ) {
this.sink.propagateAssertLeftTuple( leftTuple,
rightTuple,
+ null,
+ null,
context,
workingMemory,
this.tupleMemoryEnabled );
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/JoinNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/JoinNode.java 2010-04-03 18:04:39 UTC (rev 32379)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/JoinNode.java 2010-04-03 18:36:58 UTC (rev 32380)
@@ -72,6 +72,8 @@
handle ) ) {
this.sink.propagateAssertLeftTuple( leftTuple,
rightTuple,
+ null,
+ null,
context,
workingMemory,
this.tupleMemoryEnabled );
@@ -113,6 +115,8 @@
// wm.marshaller.write( i, leftTuple )
this.sink.propagateAssertLeftTuple( leftTuple,
rightTuple,
+ null,
+ null,
context,
workingMemory,
this.tupleMemoryEnabled );
@@ -199,6 +203,8 @@
leftTuple ) ) {
this.sink.propagateAssertLeftTuple( leftTuple,
rightTuple,
+ null,
+ null,
context,
workingMemory,
this.tupleMemoryEnabled );
@@ -209,9 +215,11 @@
for ( ; leftTuple != null; leftTuple = (LeftTuple) leftTuple.getNext() ) {
if ( this.constraints.isAllowedCachedRight( memory.getContext(),
leftTuple ) ) {
- if ( childLeftTuple != null && childLeftTuple.getLeftParent() != leftTuple ) {
+ if ( childLeftTuple == null || childLeftTuple.getLeftParent() != leftTuple ) {
this.sink.propagateAssertLeftTuple( leftTuple,
rightTuple,
+ null,
+ childLeftTuple,
context,
workingMemory,
this.tupleMemoryEnabled );
@@ -225,7 +233,6 @@
this.tupleMemoryEnabled );
// we must re-add this to ensure deterministic iteration
temp.reAddLeft();
- temp.reAddRight();
}
} else if ( childLeftTuple != null && childLeftTuple.getLeftParent() == leftTuple ) {
childLeftTuple = this.sink.propagateRetractChildLeftTuple( childLeftTuple,
@@ -281,6 +288,8 @@
handle ) ) {
this.sink.propagateAssertLeftTuple( leftTuple,
rightTuple,
+ null,
+ null,
context,
workingMemory,
this.tupleMemoryEnabled );
@@ -293,9 +302,11 @@
if ( this.constraints.isAllowedCachedLeft( memory.getContext(),
handle ) ) {
- if ( childLeftTuple != null && childLeftTuple.getRightParent() != rightTuple ) {
+ if ( childLeftTuple == null || childLeftTuple.getRightParent() != rightTuple ) {
this.sink.propagateAssertLeftTuple( leftTuple,
rightTuple,
+ childLeftTuple,
+ null,
context,
workingMemory,
this.tupleMemoryEnabled );
@@ -309,7 +320,6 @@
this.tupleMemoryEnabled );
// we must re-add this to ensure deterministic iteration
temp.reAddRight();
- temp.reAddLeft();
}
} else if ( childLeftTuple != null && childLeftTuple.getRightParent() == rightTuple ) {
childLeftTuple = this.sink.propagateRetractChildLeftTuple( childLeftTuple,
@@ -344,6 +354,8 @@
rightTuple.getFactHandle() ) ) {
sink.assertLeftTuple( new LeftTuple( leftTuple,
rightTuple,
+ null,
+ null,
sink,
this.tupleMemoryEnabled ),
context,
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 2010-04-03 18:04:39 UTC (rev 32379)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTuple.java 2010-04-03 18:36:58 UTC (rev 32380)
@@ -100,30 +100,70 @@
public LeftTuple(final LeftTuple leftTuple,
final RightTuple rightTuple,
- LeftTupleSink sink,
- boolean leftTupleMemoryEnabled) {
+ final LeftTupleSink sink,
+ final boolean leftTupleMemoryEnabled) {
+ this( leftTuple,
+ rightTuple,
+ null,
+ null,
+ sink,
+ leftTupleMemoryEnabled );
+ }
+
+ public LeftTuple(final LeftTuple leftTuple,
+ final RightTuple rightTuple,
+ final LeftTuple currentLeftChild,
+ final LeftTuple currentRightChild,
+ final LeftTupleSink sink,
+ final boolean leftTupleMemoryEnabled) {
this.handle = rightTuple.getFactHandle();
this.index = leftTuple.index + 1;
this.parent = leftTuple;
if ( leftTupleMemoryEnabled ) {
this.leftParent = leftTuple;
- if ( leftTuple.lastChild != null ) {
- this.leftParentPrevious = leftTuple.lastChild;
- this.leftParentPrevious.leftParentNext = this;
+ this.rightParent = rightTuple;
+ if( currentLeftChild == null ) {
+ // insert at the end of the list
+ if ( leftTuple.lastChild != null ) {
+ this.leftParentPrevious = leftTuple.lastChild;
+ this.leftParentPrevious.leftParentNext = this;
+ } else {
+ leftTuple.firstChild = this;
+ }
+ leftTuple.lastChild = this;
} else {
- leftTuple.firstChild = this;
+ // insert before current child
+ this.leftParentNext = currentLeftChild;
+ this.leftParentPrevious = currentLeftChild.leftParentPrevious;
+ currentLeftChild.leftParentPrevious = this;
+ if( this.leftParentPrevious == null ) {
+ this.leftParent.firstChild = this;
+ } else {
+ this.leftParentPrevious.leftParentNext = this;
+ }
}
- leftTuple.lastChild = this;
- this.rightParent = rightTuple;
- if ( rightTuple.lastChild != null ) {
- this.rightParentPrevious = rightTuple.lastChild;
- this.rightParentPrevious.rightParentNext = this;
+ if( currentRightChild == null ) {
+ // insert at the end of the list
+ if ( rightTuple.lastChild != null ) {
+ this.rightParentPrevious = rightTuple.lastChild;
+ this.rightParentPrevious.rightParentNext = this;
+ } else {
+ rightTuple.firstChild = this;
+ }
+ rightTuple.lastChild = this;
} else {
- rightTuple.firstChild = this;
+ // insert before current child
+ this.rightParentNext = currentRightChild;
+ this.rightParentPrevious = currentRightChild.rightParentPrevious;
+ currentRightChild.rightParentPrevious = this;
+ if( this.rightParentPrevious == null ) {
+ this.rightParent.firstChild = this;
+ } else {
+ this.rightParentPrevious.rightParentNext = this;
+ }
}
- rightTuple.lastChild = this;
}
this.sink = sink;
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTupleSinkPropagator.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTupleSinkPropagator.java 2010-04-03 18:04:39 UTC (rev 32379)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftTupleSinkPropagator.java 2010-04-03 18:36:58 UTC (rev 32380)
@@ -12,6 +12,8 @@
Externalizable {
public void propagateAssertLeftTuple(LeftTuple leftTuple,
RightTuple rightTuple,
+ LeftTuple currentLeftChild, // insert new tuple before this child in the child list
+ LeftTuple currentRightChild, // insert new tuple before this child in the child list
PropagationContext context,
InternalWorkingMemory workingMemory,
boolean leftTupleMemoryEnabled);
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleLeftTupleSinkAdapter.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleLeftTupleSinkAdapter.java 2010-04-03 18:04:39 UTC (rev 32379)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/SingleLeftTupleSinkAdapter.java 2010-04-03 18:36:58 UTC (rev 32380)
@@ -26,6 +26,8 @@
public void propagateAssertLeftTuple(final LeftTuple leftTuple,
final RightTuple rightTuple,
+ final LeftTuple currentLeftChild,
+ final LeftTuple currentRightChild,
final PropagationContext context,
final InternalWorkingMemory workingMemory,
boolean leftTupleMemoryEnabled) {
@@ -33,6 +35,8 @@
workingMemory,
new LeftTuple( leftTuple,
rightTuple,
+ currentLeftChild,
+ currentRightChild,
this.sink,
leftTupleMemoryEnabled ) );
}
More information about the jboss-svn-commits
mailing list