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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Oct 23 09:14:54 EDT 2006


Author: tirelli
Date: 2006-10-23 09:14:49 -0400 (Mon, 23 Oct 2006)
New Revision: 7016

Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/AbstractCompositeRestriction.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/AndCompositeRestriction.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/MultiRestrictionFieldConstraint.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/OrCompositeRestriction.java
Log:
Fixing MultiRestriction constraint

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/AbstractCompositeRestriction.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/AbstractCompositeRestriction.java	2006-10-23 12:41:02 UTC (rev 7015)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/AbstractCompositeRestriction.java	2006-10-23 13:14:49 UTC (rev 7016)
@@ -4,18 +4,23 @@
 import java.util.HashSet;
 import java.util.Set;
 
+import org.drools.common.InternalFactHandle;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.reteoo.ReteTuple;
 import org.drools.spi.Restriction;
 
 public abstract class AbstractCompositeRestriction
     implements
     Restriction {
 
-    private static final long     serialVersionUID = 320L;
+    private static final long             serialVersionUID = 320L;
 
-    protected final Restriction[] restrictions;
+    protected final Restriction[]         restrictions;
+    protected final CompositeContextEntry contextEntry;
 
     public AbstractCompositeRestriction(final Restriction[] restriction) {
         this.restrictions = restriction;
+        this.contextEntry = new CompositeContextEntry( this.restrictions );
     }
 
     public Declaration[] getRequiredDeclarations() {
@@ -67,4 +72,47 @@
         }
         return true;
     }
+
+    public ContextEntry getContextEntry() {
+        return this.contextEntry;
+    }
+
+    public static class CompositeContextEntry
+        implements
+        ContextEntry {
+        public ContextEntry[]        contextEntries;
+
+        private ContextEntry         entry;
+
+        public CompositeContextEntry(Restriction[] restrictions) {
+            ContextEntry[] contextEntries = new ContextEntry[restrictions.length];
+            for(int i = 0; i < restrictions.length; i++) {
+                contextEntries[i] = restrictions[i].getContextEntry();
+            }
+        }
+
+        public ContextEntry getNext() {
+            return this.entry;
+        }
+
+        public void setNext(final ContextEntry entry) {
+            this.entry = entry;
+        }
+
+        public void updateFromFactHandle(InternalWorkingMemory workingMemory,
+                                         InternalFactHandle handle) {
+            for(int i = 0, length = contextEntries.length ; i < length; i++) {
+                contextEntries[i].updateFromFactHandle( workingMemory, handle );
+            }
+        }
+
+        public void updateFromTuple(InternalWorkingMemory workingMemory,
+                                    ReteTuple tuple) {
+            for(int i = 0, length = contextEntries.length ; i < length; i++) {
+                contextEntries[i].updateFromTuple( workingMemory, tuple );
+            }
+        }
+
+    }
+
 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/AndCompositeRestriction.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/AndCompositeRestriction.java	2006-10-23 12:41:02 UTC (rev 7015)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/AndCompositeRestriction.java	2006-10-23 13:14:49 UTC (rev 7016)
@@ -1,8 +1,9 @@
 package org.drools.rule;
 
-import org.drools.WorkingMemory;
+import org.drools.common.InternalWorkingMemory;
+import org.drools.reteoo.ReteTuple;
+import org.drools.spi.Extractor;
 import org.drools.spi.Restriction;
-import org.drools.spi.Tuple;
 
 public class AndCompositeRestriction extends AbstractCompositeRestriction {
 
@@ -12,18 +13,42 @@
         super( restriction );
     }
 
-    public boolean isAllowed(final Object object,
-                             final Tuple tuple,
-                             final WorkingMemory workingMemory) {
+    public boolean isAllowed(Extractor extractor,
+                             Object object,
+                             InternalWorkingMemory workingMemory) {
+        for ( int i = 0, ilength = this.restrictions.length; i < ilength; i++ ) {
+            if ( !this.restrictions[i].isAllowed( extractor,
+                                                  object,
+                                                  workingMemory ) ) {
+                return false;
+            }
+        }
+        return true;
+    }
 
+    public boolean isAllowedCachedLeft(ContextEntry context,
+                                       Object object) {
         for ( int i = 0, ilength = this.restrictions.length; i < ilength; i++ ) {
-            if ( !this.restrictions[i].isAllowed( object,
-                                             tuple,
-                                             workingMemory ) ) {
+            if ( !this.restrictions[i].isAllowedCachedLeft( this.contextEntry.contextEntries[i],
+                                                            object ) ) {
                 return false;
             }
         }
         return true;
+    }
 
+    public boolean isAllowedCachedRight(ReteTuple tuple,
+                                        ContextEntry context) {
+        for ( int i = 0, ilength = this.restrictions.length; i < ilength; i++ ) {
+            if ( !this.restrictions[i].isAllowedCachedRight( tuple,
+                                                             this.contextEntry.contextEntries[i] ) ) {
+                return false;
+            }
+        }
+        return true;
     }
+
+    public ContextEntry getContextEntry() {
+        return this.contextEntry;
+    }
 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/MultiRestrictionFieldConstraint.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/MultiRestrictionFieldConstraint.java	2006-10-23 12:41:02 UTC (rev 7015)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/MultiRestrictionFieldConstraint.java	2006-10-23 13:14:49 UTC (rev 7016)
@@ -1,10 +1,9 @@
 package org.drools.rule;
 
-import org.drools.WorkingMemory;
+import org.drools.common.InternalWorkingMemory;
 import org.drools.spi.AlphaNodeFieldConstraint;
 import org.drools.spi.FieldExtractor;
 import org.drools.spi.Restriction;
-import org.drools.spi.Tuple;
 
 public class MultiRestrictionFieldConstraint
     implements
@@ -33,14 +32,6 @@
         return this.restrictions.getRequiredDeclarations();
     }
 
-    public boolean isAllowed(final Object object,
-                             final Tuple tuple,
-                             final WorkingMemory workingMemory) {
-        return this.restrictions.isAllowed( this.extractor.getValue( object ),
-                                            tuple,
-                                            workingMemory );
-    }
-
     public String toString() {
         return "[MultiRestrictionConstraint fieldExtractor=" + this.extractor + " restrictions =" + this.restrictions + "]";
     }
@@ -65,4 +56,9 @@
         return this.extractor.equals( other.extractor ) && this.restrictions.equals( other.restrictions );
     }
 
+    public boolean isAllowed(Object object,
+                             InternalWorkingMemory workingMemory) {
+        return this.restrictions.isAllowed( extractor, object, workingMemory );
+    }
+
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/OrCompositeRestriction.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/OrCompositeRestriction.java	2006-10-23 12:41:02 UTC (rev 7015)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/OrCompositeRestriction.java	2006-10-23 13:14:49 UTC (rev 7016)
@@ -1,11 +1,9 @@
 package org.drools.rule;
 
-import org.drools.WorkingMemory;
 import org.drools.common.InternalWorkingMemory;
 import org.drools.reteoo.ReteTuple;
 import org.drools.spi.Extractor;
 import org.drools.spi.Restriction;
-import org.drools.spi.Tuple;
 
 public class OrCompositeRestriction extends AbstractCompositeRestriction {
 
@@ -15,37 +13,42 @@
         super( restriction );
     }
 
-    public boolean isAllowed(final Object object,
-                             final Tuple tuple,
-                             final WorkingMemory workingMemory) {
-
+    public boolean isAllowed(Extractor extractor,
+                             Object object,
+                             InternalWorkingMemory workingMemory) {
         for ( int i = 0, ilength = this.restrictions.length; i < ilength; i++ ) {
-            if ( this.restrictions[i].isAllowed( object,
-                                            tuple,
-                                            workingMemory ) ) {
+            if ( this.restrictions[i].isAllowed( extractor,
+                                                 object,
+                                                 workingMemory ) ) {
                 return true;
             }
         }
         return false;
-
     }
 
-    public boolean isAllowed(Extractor extractor,
-                             Object object,
-                             InternalWorkingMemory workingMemoiry) {
-        // TODO Auto-generated method stub
-        return false;
-    }
-
     public boolean isAllowedCachedLeft(ContextEntry context,
                                        Object object) {
-        // TODO Auto-generated method stub
+        for ( int i = 0, ilength = this.restrictions.length; i < ilength; i++ ) {
+            if ( this.restrictions[i].isAllowedCachedLeft( this.contextEntry.contextEntries[i],
+                                                           object ) ) {
+                return true;
+            }
+        }
         return false;
     }
 
     public boolean isAllowedCachedRight(ReteTuple tuple,
                                         ContextEntry context) {
-        // TODO Auto-generated method stub
+        for ( int i = 0, ilength = this.restrictions.length; i < ilength; i++ ) {
+            if ( this.restrictions[i].isAllowedCachedRight( tuple,
+                                                            this.contextEntry.contextEntries[i] ) ) {
+                return true;
+            }
+        }
         return false;
     }
+
+    public ContextEntry getContextEntry() {
+        return this.contextEntry;
+    }
 }




More information about the jboss-svn-commits mailing list