[jboss-svn-commits] JBL Code SVN: r6223 - 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 Sep 14 08:56:08 EDT 2006


Author: mark.proctor at jboss.com
Date: 2006-09-14 08:56:06 -0400 (Thu, 14 Sep 2006)
New Revision: 6223

Added:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java
Log:
JBRULES-494 Linked Tuple
-Added missing BetaNodeBinder renaming to BetaNodeCosntraints

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java	2006-09-14 12:55:24 UTC (rev 6222)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java	2006-09-14 12:56:06 UTC (rev 6223)
@@ -0,0 +1,200 @@
+package org.drools.reteoo;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.drools.common.DefaultFactHandle;
+import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.rule.Declaration;
+import org.drools.spi.Activation;
+import org.drools.spi.PropagationContext;
+import org.drools.spi.Tuple;
+import org.drools.util.AbstractBaseLinkedListNode;
+import org.drools.util.BaseMultiLinkedListNode;
+import org.drools.util.LinkedList;
+import org.drools.util.LinkedListNode;
+import org.drools.util.LinkedListEntry;
+
+public class ReteTuple extends AbstractBaseLinkedListNode
+    implements
+    Tuple {
+    private int                      index;
+
+    private final InternalFactHandle handle;
+
+    private ReteTuple                parent;
+
+    private final TupleSink          sink;
+
+    private LinkedList               children;
+
+    /** The <code>Map</code> of <code>FactHandleImpl</code> matches */
+    private Map                      matches = Collections.EMPTY_MAP;
+
+    private Activation               activation;
+
+    private long                     recency;
+
+    // ------------------------------------------------------------
+    // Constructors
+    // ------------------------------------------------------------
+    public ReteTuple(final ReteTuple parentEntry) {
+        this( parentEntry, null );
+    }
+    public ReteTuple(final InternalFactHandle handle,
+                     final TupleSink sink) {
+        this.index = 0;
+        this.parent = null;
+        this.recency = handle.getRecency();
+        this.handle = handle;
+        this.sink = sink;
+    }
+
+    public ReteTuple(final ReteTuple entry,
+                     final TupleSink sink) {
+        this.index = entry.index;
+        this.parent = entry.parent;
+        this.recency = entry.recency;
+        this.handle = entry.handle;
+        this.sink = sink;
+    }
+
+    public ReteTuple(final ReteTuple parentEntry,
+                     final InternalFactHandle handle,
+                     final TupleSink sink) {
+        this.index = parentEntry.index + 1;
+        this.parent = parentEntry;
+        this.recency = parentEntry.recency + handle.getRecency();
+        this.handle = handle;
+        this.sink = sink;
+    }
+
+    public void addChildEntry(ReteTuple entry) {
+        if ( this.children == null ) {
+            this.children = new LinkedList();
+        }
+        this.children.add( new LinkedListEntry( entry ) );
+    }
+
+    public void modifyChildEntries(PropagationContext context,
+                                   InternalWorkingMemory workingMemory) {
+        for ( LinkedListNode node = this.children.getFirst(); node != null; node = node.getNext() ) {
+            ReteTuple tuple = (ReteTuple) ((LinkedListEntry) node).getObject();
+            tuple.modifyTuple( context,
+                               workingMemory );
+        }
+    }
+
+    public void retractChildEntries(PropagationContext context,
+                                    InternalWorkingMemory workingMemory) {
+        for ( LinkedListNode node = this.children.getFirst(); node != null; node = node.getNext() ) {
+            ReteTuple tuple = (ReteTuple) ((LinkedListEntry) node).getObject();
+            tuple.retractTuple( context,
+                                workingMemory );
+        }
+    }
+
+    public void addTupleMatch(InternalFactHandle handle,
+                              TupleMatch tupleMatch) {
+        if ( this.matches == Collections.EMPTY_MAP ) {
+            this.matches = new HashMap();
+        }
+        this.matches.put( handle,
+                          tupleMatch );
+    }
+
+    public void clearChildEntries() {
+        this.children.clear();
+    }
+
+    public void clearTupleMatches() {
+        this.matches.clear();
+    }
+
+    public InternalFactHandle get(int index) {
+        ReteTuple entry = this;
+        while ( entry.index != index ) {
+            entry = entry.parent;
+        }
+        return entry.handle;
+    }
+
+    public InternalFactHandle get(Declaration declaration) {
+        return get( declaration.getColumn().getIndex() );
+    }
+
+    public Activation getActivation() {
+        return this.activation;
+    }
+
+    public LinkedList getChildEntries() {
+        return this.children;
+    }
+
+    public InternalFactHandle[] getFactHandles() {
+        List list = new ArrayList();
+        ReteTuple entry = this;
+        while ( entry != null ) {
+            list.add( entry.handle );
+            entry = entry.parent;
+        }
+
+        return (InternalFactHandle[]) list.toArray( new InternalFactHandle[list.size()] );
+    }
+
+    public long getRecency() {
+        return this.recency;
+    }
+
+    public TupleMatch getTupleMatch(DefaultFactHandle handle) {
+        return (TupleMatch) this.matches.get( handle );
+    }
+
+    public Map getTupleMatches() {
+        return this.matches;
+    }
+
+    public TupleSink getTupleSink() {
+        return this.sink;
+    }
+
+    public int matchesSize() {
+        return this.matches.size();
+    }
+
+    public TupleMatch removeMatch(InternalFactHandle handle) {
+        return (TupleMatch) this.matches.remove( handle );
+    }
+
+    public void retractTuple(PropagationContext context,
+                             InternalWorkingMemory workingMemory) {
+        this.parent = null;
+        this.sink.retractTuple( this,
+                                context,
+                                workingMemory );
+    }
+
+    public void assertTuple(PropagationContext context,
+                            InternalWorkingMemory workingMemory) {
+        this.sink.assertTuple( this,
+                               context,
+                               workingMemory );
+    }
+
+    public void modifyTuple(PropagationContext context,
+                            InternalWorkingMemory workingMemory) {
+        this.sink.modifyTuple( this,
+                               context,
+                               workingMemory );
+    }
+
+    public void setActivation(Activation activation) {
+        this.activation = activation;
+    }
+        
+}




More information about the jboss-svn-commits mailing list