[jboss-svn-commits] JBL Code SVN: r6256 - in labs/jbossrules/trunk/drools-core/src: main/java/org/drools/reteoo main/java/org/drools/rule main/java/org/drools/spi main/java/org/drools/util test/java/org/drools/base/dataproviders test/java/org/drools/base/resolvers test/java/org/drools/examples/manners test/java/org/drools/reteoo test/java/org/drools/reteoo/beta test/java/org/drools/util

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sun Sep 17 15:23:53 EDT 2006


Author: mark.proctor at jboss.com
Date: 2006-09-17 15:23:21 -0400 (Sun, 17 Sep 2006)
New Revision: 6256

Added:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/BaseEntry.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/DroolsMap.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/Entry.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FactConstraintMap.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FactEntry.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FactIndexKey.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FieldIndexEntry.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FieldIndexMap.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/TupleEntry.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexEntryTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexMapTest.java
Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Accumulate.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/Accumulator.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/dataproviders/MethodDataProviderTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/resolvers/DeclarationVariableTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/resolvers/GlobalVariableTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/resolvers/ListValueTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/resolvers/LiteralValueTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/resolvers/MapValueTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/examples/manners/ReteooMannersTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AccumulateNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/FromNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/InstrumentedReteTuple.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/JoinNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LeftInputAdapterNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/MockAccumulator.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/MockTupleSink.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/NotNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/TupleSourceTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BaseBetaLeftMemoryTestClass.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BaseBetaRightMemoryTestClass.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BetaMemoryFactoryTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BooleanConstrainedLeftMemoryTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BooleanConstrainedRightMemoryTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/DefaultLeftMemoryTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/InstanceEqualConstrRightMemoryTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/ObjectEqualConstrLeftMemoryTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/ObjectEqualConstrRightMemoryTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/ObjectNotEqualConstrLeftMemoryTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/ObjectNotEqualConstrRightMemoryTest.java
Log:
JBRULES-498 Optimised HashMap implementations

Modified: 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-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteTuple.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -38,7 +38,7 @@
 
     private Activation               activation;
 
-    private long                     recency;
+    private long                     recency;    
 
     // ------------------------------------------------------------
     // Constructors
@@ -201,4 +201,22 @@
         this.activation = activation;
     }
         
+    
+    public int hashCode() {
+        return this.handle.hashCode();
+    }
+    
+    public boolean equals(Object object) {
+        if ( object == this ) {
+            return true;
+        }
+        
+        if ( object == null || object.getClass() == getClass() ) {
+            return false;
+        }
+        
+        ReteTuple other = ( ReteTuple ) object;
+        
+        return ( this.handle.getId() == other.handle.getId() );            
+    }
 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Accumulate.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Accumulate.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/Accumulate.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -20,8 +20,8 @@
 
 import org.drools.RuntimeDroolsException;
 import org.drools.WorkingMemory;
-import org.drools.reteoo.ReteTuple;
 import org.drools.spi.Accumulator;
+import org.drools.spi.Tuple;
 
 /**
  * A class to represent a Accumulate CE
@@ -79,7 +79,7 @@
         this.accumulator = accumulator;
     }
 
-    public Object accumulate(final ReteTuple leftTuple,
+    public Object accumulate(final Tuple leftTuple,
                              final List matchingObjects,
                              final WorkingMemory workingMemory) {
         try {

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/Accumulator.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/Accumulator.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/Accumulator.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -19,7 +19,6 @@
 import java.util.List;
 
 import org.drools.WorkingMemory;
-import org.drools.reteoo.ReteTuple;
 import org.drools.rule.Declaration;
 
 /**
@@ -34,7 +33,7 @@
     extends
     Invoker {
 
-    public Object accumulate(ReteTuple leftTuple,
+    public Object accumulate(Tuple leftTuple,
                              List matchingObjects,
                              Declaration[] declarations,
                              Declaration[] innerDeclarations,

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/BaseEntry.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/BaseEntry.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/BaseEntry.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -0,0 +1,18 @@
+/**
+ * 
+ */
+package org.drools.util;
+
+public class BaseEntry
+    implements
+    Entry {
+    private Entry next;
+
+    public void setNext(Entry next) {
+        this.next = next;
+    }
+
+    public Entry getNext() {
+        return this.next;
+    }
+}
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/DroolsMap.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/DroolsMap.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/DroolsMap.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -0,0 +1,139 @@
+/**
+ * 
+ */
+package org.drools.util;
+
+public class DroolsMap {
+    static final int  MAX_CAPACITY = 1 << 30;
+
+    protected int     size;
+    protected int     threshold;
+    protected float   loadFactor;
+    
+    protected boolean checkExists;
+
+    protected Entry[] table;
+
+    public DroolsMap() {
+        this( 16,
+              0.75f );
+    }
+
+    public DroolsMap(int capacity,
+                     float loadFactor) {
+        this.loadFactor = loadFactor;
+        this.threshold = (int) (capacity * loadFactor);
+        this.table = new Entry[capacity];
+    }
+
+    protected void resize(int newCapacity) {
+        Entry[] oldTable = this.table;
+        int oldCapacity = oldTable.length;
+        if ( oldCapacity == MAX_CAPACITY ) {
+            this.threshold = Integer.MAX_VALUE;
+            return;
+        }
+
+        Entry[] newTable = new Entry[newCapacity];
+
+        for ( int i = 0; i < this.table.length; i++ ) {
+            Entry entry = this.table[i];
+            if ( entry == null ) {
+                continue;
+            }
+            this.table[i] = null;
+            Entry next = null;
+            while ( entry != null ) {
+                next = entry.getNext();
+
+                int index = indexOf( entry.hashCode(), newTable.length  );
+                entry.setNext( newTable[index] );
+                newTable[index] = entry;
+
+                entry = next;
+            }
+        }
+
+        this.table = newTable;
+        this.threshold = (int) (newCapacity * this.loadFactor);
+    }
+
+    public void add(Entry entry) {
+        int index = indexOf( entry.hashCode(), table.length  );
+
+        
+        boolean exists = false;
+        
+        // scan the linked entries to see if it exists
+        if ( !checkExists ) {
+            Entry current = this.table[index];
+            int hashCode = entry.hashCode();
+            while ( current != null ) {                
+                if  ( hashCode == current.hashCode() && entry.equals( current ) ) {
+                    exists = true;
+                }
+            }                        
+        }
+        
+        if( exists == false ) {
+            entry.setNext( this.table[index] );
+            this.table[index] = entry;
+    
+            if ( this.size++ >= this.threshold ) {
+                resize( 2 * this.table.length );
+            }
+        }
+
+    }
+
+    public Entry get(Entry entry) {
+        int index = indexOf( entry.hashCode(), table.length  );
+        Entry current = this.table[index];
+        while ( current != null ) {
+            if ( entry.hashCode() == current.hashCode() && entry.equals( current ) ) {
+                return current;
+            }
+            current = current.getNext();
+        }
+        return null;
+    }
+
+    public Entry remove(Entry entry) {
+        int index = indexOf( entry.hashCode(), table.length  );
+        Entry previous = this.table[index];        
+        Entry current = previous;
+        int hashCode = entry.hashCode();
+        while ( current != null ) {
+            Entry next = current.getNext();
+            if ( hashCode == current.hashCode() && entry.equals( current ) ) {
+                if( previous  == current ) {
+                    this.table[index] = next;
+                    previous.setNext( next );
+                }
+                current.setNext( null );
+                this.size--;
+                return current;
+            }
+            previous = current;
+            current = next;
+        }
+        return current;
+    }
+
+    public Entry getBucket(int hashCode) {
+        int index = indexOf( hashCode, table.length );
+        return this.table[index];
+    }
+
+    public int size() {
+        return this.size;
+    }
+    
+    protected int indexOf(int hashCode, int length) {
+        int index = hashCode % length;
+        if ( index < 0 ) {
+            index  = index * -1;
+        }
+        return index;
+    }
+}
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/Entry.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/Entry.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/Entry.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -0,0 +1,10 @@
+/**
+ * 
+ */
+package org.drools.util;
+
+public interface Entry {
+    public void setNext(Entry next);
+
+    public Entry getNext();
+}
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FactConstraintMap.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FactConstraintMap.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FactConstraintMap.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -0,0 +1,147 @@
+package org.drools.util;
+
+import org.drools.common.InternalFactHandle;
+import org.drools.spi.FieldExtractor;
+
+/***********************************/
+    public class FactConstraintMap {
+        static final int       MAX_CAPACITY = 1 << 30;
+
+        private int            size;
+        private int            threshold;
+        private float          loadFactor;
+
+        private Entry[]        table;
+
+        private int            fieldIndex;
+        private FieldExtractor extractor;
+
+        final int              PRIME        = 31;
+
+        private final int      startResult;
+
+        public FactConstraintMap(int fieldIndex,
+                                 FieldExtractor extractor) {
+            this( 16,
+                  0.75f,
+                  fieldIndex,
+                  extractor );
+        }
+
+        public FactConstraintMap(int capacity,
+                                 float loadFactor,
+                                 int fieldIndex,
+                                 FieldExtractor extractor) {
+            this.loadFactor = loadFactor;
+            this.threshold = (int) (capacity * loadFactor);
+            this.table = new TupleEntry[capacity];
+            this.fieldIndex = fieldIndex;
+            this.extractor = extractor;
+
+            this.startResult = PRIME + this.fieldIndex;
+        }
+
+        public void resize(int newCapacity) {
+            Entry[] oldTable = this.table;
+            int oldCapacity = oldTable.length;
+            if ( oldCapacity == MAX_CAPACITY ) {
+                this.threshold = Integer.MAX_VALUE;
+                return;
+            }
+
+            Entry[] newTable = new Entry[newCapacity];
+
+            for ( int i = 0; i < this.table.length; i++ ) {
+                Entry entry = this.table[i];
+                if ( entry == null ) {
+                    continue;
+                }
+                this.table[i] = null;
+                Entry next = null;
+                while ( entry != null ) {
+                    next = entry.getNext();
+
+                    int index = entry.hashCode() % newTable.length;
+                    entry.setNext( newTable[index] );
+                    newTable[index] = entry;
+
+                    entry = next;
+                }
+            }
+
+            this.table = newTable;
+            this.threshold = (int) (newCapacity * this.loadFactor);
+        }
+
+        public void add(InternalFactHandle handle) {
+            Object value = this.extractor.getValue( handle.getObject() );
+            int hashCode = PRIME * startResult + ((value == null) ? 0 : value.hashCode());
+
+//            FactEntry factEntry = new FactEntry( handle );
+//            getOrCreate( hashCode,
+//                         this.fieldIndex,
+//                         value ).add( factEntry );
+        }
+
+        public FieldIndexEntry getOrCreate(int hashCode,
+                                          int fieldIndex,
+                                          Object value) {
+            int index = hashCode % this.table.length;
+            FieldIndexEntry entry = (FieldIndexEntry) this.table[index];
+
+            while ( entry != null ) {
+                if ( hashCode == entry.hashCode() && value.equals( entry.getValue() ) ) {
+                    return entry;
+                }
+                entry = (FieldIndexEntry) entry.getNext();
+            }
+
+            if ( entry == null ) {
+                entry = new FieldIndexEntry( this.extractor,
+                                            fieldIndex,
+                                            hashCode );
+                entry.setNext( this.table[index] );
+                this.table[index] = entry;
+
+                if ( this.size++ >= this.threshold ) {
+                    resize( 2 * this.table.length );
+                }
+            }
+            return entry;
+        }
+
+        public Entry get(Entry entry) {
+            int index = entry.hashCode() % this.table.length;
+            Entry current = this.table[index];
+            while ( current != null ) {
+                if ( entry.hashCode() == current.hashCode() && entry.equals( current ) ) {
+                    return current;
+                }
+                current = current.getNext();
+            }
+            return null;
+        }
+
+        public Entry remove(TupleEntry tuple) {
+            int index = tuple.hashCode() % this.table.length;
+            Entry current = this.table[index];
+            Entry previous = current;
+            if ( current != null ) {
+                if ( tuple.hashCode() == current.hashCode() && tuple.equals( current ) ) {
+                    previous.setNext( current.getNext() );
+                    return current;
+                }
+                previous = current;
+            }
+            return null;
+        }
+
+        public Entry getBucket(int hashCode) {
+            int index = hashCode % this.table.length;
+            return this.table[index];
+        }
+
+        public int size() {
+            return this.size;
+        }
+    }
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FactEntry.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FactEntry.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FactEntry.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -0,0 +1,33 @@
+/**
+ * 
+ */
+package org.drools.util;
+
+import org.drools.common.InternalFactHandle;
+
+public class FactEntry extends BaseEntry {
+    private InternalFactHandle handle;
+
+    public FactEntry(InternalFactHandle handle) {
+        this.handle = handle;
+    }
+
+    public String toString() {
+        return this.handle.getObject().toString();
+    }
+
+    public InternalFactHandle getFactHandle() {
+        return this.handle;
+    }
+
+    public int hashCode() {
+        return this.handle.hashCode();
+    }
+
+    public boolean equals(Object object) {
+        // Inside the rete network we know that it will always be a TupleEntry
+        // We know it will never be null
+        FactEntry other = (FactEntry) object;
+        return (this.handle.getId() == other.handle.getId());
+    }
+}
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FactIndexKey.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FactIndexKey.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FactIndexKey.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -0,0 +1,21 @@
+/**
+ * 
+ */
+package org.drools.util;
+
+public class FactIndexKey {
+    public int    hashCode;
+    public int    fieldIndex;
+    public Object value;
+
+    public int hashCode() {
+        return this.hashCode;
+    }
+
+    public boolean equals(Object object) {
+        // Inside the rete network we know that it will always be a FactIndexEntry
+        // We know it will never be null
+        FieldIndexEntry entry = (FieldIndexEntry) object;
+        return this.fieldIndex == entry.fieldIndex && this.value.equals( entry.getValue() );
+    }
+}
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FieldIndexEntry.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FieldIndexEntry.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FieldIndexEntry.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -0,0 +1,88 @@
+/**
+ * 
+ */
+package org.drools.util;
+
+import org.drools.common.InternalFactHandle;
+import org.drools.spi.FieldExtractor;
+
+public class FieldIndexEntry extends BaseEntry {
+    FactEntry            first;
+
+    private final int            hashCode;
+    final int            fieldIndex;
+    private final FieldExtractor extractor;
+
+    public FieldIndexEntry(FieldExtractor extractor,
+                          int fieldIndex,
+                          int hashCode) {
+        this.extractor = extractor;
+        this.fieldIndex = fieldIndex;
+        this.hashCode = hashCode;
+    }
+    
+    public FactEntry getFirst() {
+        return this.first;
+    }
+
+    public void add(InternalFactHandle handle) {
+        FactEntry entry = new FactEntry( handle );            
+        entry.setNext( this.first );
+        this.first = entry;
+    }
+
+    public FactEntry get(InternalFactHandle handle) {
+        long id = handle.getId();
+        FactEntry current = first;
+        while ( current != null ) {
+            if ( current.getFactHandle().getId() == id ) {
+                return current;
+            }
+            current = ( FactEntry ) current.getNext();
+        }
+        return null;
+    }
+
+    public FactEntry remove(InternalFactHandle handle) {
+        long id = handle.getId();
+        
+        FactEntry previous = this.first; 
+        FactEntry current = previous;
+        while ( current != null ) {
+            FactEntry next = ( FactEntry ) current.getNext();
+            if ( current.getFactHandle().getId() == id ) {
+                this.first = next;
+                previous.setNext( next );
+                current.setNext( null );
+                return current;
+            }
+            previous = current;
+            current = next;
+        }
+        return current;
+    }
+
+    public String toString() {
+        return this.extractor.toString();
+    }
+
+    public int fieldIndex() {
+        return this.fieldIndex;
+    }
+
+    public Object getValue() {
+        if ( this.first == null ) {
+            return null;
+        }
+        return this.extractor.getValue( this.first.getFactHandle().getObject() );
+    }
+
+    public int hashCode() {
+        return this.hashCode;
+    }
+
+    public boolean equals(Object object) {
+        FieldIndexEntry other = ( FieldIndexEntry ) object;
+        return this.hashCode == other.hashCode && this.fieldIndex == other.fieldIndex;
+    }
+}
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FieldIndexMap.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FieldIndexMap.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/FieldIndexMap.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -0,0 +1,121 @@
+/**
+ * 
+ */
+package org.drools.util;
+
+import org.drools.common.InternalFactHandle;
+import org.drools.spi.FieldExtractor;
+
+public class FieldIndexMap extends DroolsMap {
+    private int            fieldIndex;
+    private FieldExtractor extractor;
+
+    private final int      PRIME = 31;
+
+    private final int      startResult;
+
+    public FieldIndexMap(int fieldIndex,
+                         FieldExtractor extractor) {
+        this( 16,
+              0.75f,
+              fieldIndex,
+              extractor );
+    }
+
+    public FieldIndexMap(int capacity,
+                         float loadFactor,
+                         int fieldIndex,
+                         FieldExtractor extractor) {
+        super( capacity,
+               loadFactor );
+        this.fieldIndex = fieldIndex;
+        this.extractor = extractor;
+
+        this.startResult = PRIME + this.fieldIndex;
+    }
+
+    public void add(InternalFactHandle handle) {
+        FieldIndexEntry entry = getOrCreate( this.extractor.getValue( handle.getObject() ) );
+        entry.add( handle );
+    }
+
+    public void remove(InternalFactHandle handle) {
+        Object value = this.extractor.getValue( handle.getObject() );
+        int hashCode = PRIME * startResult + ((value == null) ? 0 : value.hashCode());
+
+        int index = indexOf( hashCode, table.length  );
+        
+        // search the table for  the Entry, we need to track previous  and next, so if the 
+        // Entry is empty after  its had the FactEntry removed, we must remove  it from the table
+        FieldIndexEntry previous = ( FieldIndexEntry ) this.table[index];        
+        FieldIndexEntry current = previous;
+        while ( current != null ) {
+            FieldIndexEntry next = ( FieldIndexEntry ) current.getNext();
+            if ( hashCode == current.hashCode() && value.equals( current.getValue() ) ) {
+                current.remove( handle );
+                // If the FactEntryIndex is empty, then remove it from the hash map
+                if (  current.first ==  null  ) {
+                    if( previous  == current ) {
+                        this.table[index] = next;
+                        previous.setNext( next );
+                    }
+                    current.setNext( null );
+                    this.size--;
+                }
+                return;
+            }
+            previous = current;
+            current = next;
+        }
+    }
+
+    public FieldIndexEntry get(Object value) {
+        int hashCode = PRIME * startResult + ((value == null) ? 0 : value.hashCode());
+
+        int index = indexOf( hashCode, table.length  );
+        FieldIndexEntry entry = (FieldIndexEntry) this.table[index];
+
+        while ( entry != null ) {
+            if ( hashCode == entry.hashCode() && value.equals( entry.getValue() ) ) {
+                return entry;
+            }
+            entry = (FieldIndexEntry) entry.getNext();
+        }
+        
+        return entry;
+    }
+    
+
+    /**
+     * We use this method to aviod to table lookups for the same hashcode; which is what we would have to do if we did
+     * a get and then a create if the value is null.
+     * 
+     * @param value
+     * @return
+     */
+    private FieldIndexEntry getOrCreate(Object value) {
+        int hashCode = PRIME * startResult + ((value == null) ? 0 : value.hashCode());
+        int index = indexOf( hashCode, table.length  );
+        FieldIndexEntry entry = (FieldIndexEntry) this.table[index];
+
+        while ( entry != null ) {
+            if ( hashCode == entry.hashCode() && value.equals( entry.getValue() ) ) {
+                return entry;
+            }
+            entry = (FieldIndexEntry) entry.getNext();
+        }        
+
+        if ( entry == null ) {
+            entry = new FieldIndexEntry( this.extractor,
+                                         fieldIndex,
+                                         hashCode );
+            entry.setNext( this.table[index] );
+            this.table[index] = entry;
+
+            if ( this.size++ >= this.threshold ) {
+                resize( 2 * this.table.length );
+            }
+        }
+        return entry;
+    }
+}
\ No newline at end of file

Added: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/TupleEntry.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/TupleEntry.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/TupleEntry.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -0,0 +1,29 @@
+/**
+ * 
+ */
+package org.drools.util;
+
+import org.drools.common.InternalFactHandle;
+
+public class TupleEntry extends BaseEntry {
+    private InternalFactHandle handle;
+
+    public TupleEntry(InternalFactHandle handle) {
+        this.handle = handle;
+    }
+
+    public String toString() {
+        return this.handle.getObject().toString();
+    }
+
+    public int hashCode() {
+        return this.handle.hashCode();
+    }
+
+    public boolean equals(Object object) {
+        // Inside the rete network we know that it will always be a TupleEntry
+        // We know it will never be null
+        TupleEntry other = (TupleEntry) object;
+        return (this.handle.getId() == other.handle.getId());
+    }
+}
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/dataproviders/MethodDataProviderTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/dataproviders/MethodDataProviderTest.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/dataproviders/MethodDataProviderTest.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -29,6 +29,7 @@
 import org.drools.spi.ColumnExtractor;
 import org.drools.spi.Extractor;
 import org.drools.spi.PropagationContext;
+import org.drools.spi.Tuple;
 
 public class MethodDataProviderTest extends TestCase {
 
@@ -85,7 +86,7 @@
         FactHandle varHandle = workingMemory.assertObject( var );
         FactHandle var2Handle = workingMemory.assertObject( "hola" );
 
-        ReteTuple tuple = new ReteTuple( new ReteTuple( (DefaultFactHandle) varHandle ),
+        Tuple tuple = new ReteTuple( new ReteTuple( (DefaultFactHandle) varHandle ),
                                          (DefaultFactHandle) var2Handle );
 
         Iterator it = prov.getResults( tuple,

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/resolvers/DeclarationVariableTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/resolvers/DeclarationVariableTest.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/resolvers/DeclarationVariableTest.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -12,6 +12,7 @@
 import org.drools.reteoo.ReteTuple;
 import org.drools.rule.Column;
 import org.drools.rule.Package;
+import org.drools.spi.Tuple;
 
 public class DeclarationVariableTest extends TestCase {
     public void testDeclaration() throws Exception {
@@ -29,7 +30,7 @@
                                      20 );
         FactHandle stiltonHandle = wm.assertObject( stilton );
 
-        ReteTuple tuple = new ReteTuple( (DefaultFactHandle) stiltonHandle );
+        Tuple tuple = new ReteTuple( (DefaultFactHandle) stiltonHandle );
         assertEquals( stilton,
                       declaration.getValue( tuple,
                                             wm ) );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/resolvers/GlobalVariableTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/resolvers/GlobalVariableTest.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/resolvers/GlobalVariableTest.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -13,6 +13,7 @@
 import org.drools.common.DefaultFactHandle;
 import org.drools.reteoo.ReteTuple;
 import org.drools.rule.Package;
+import org.drools.spi.Tuple;
 
 public class GlobalVariableTest extends TestCase {
     public void testGlobal() throws Exception {
@@ -29,7 +30,7 @@
                                      20 );
         FactHandle stiltonHandle = wm.assertObject( stilton );
 
-        ReteTuple tuple = new ReteTuple( (DefaultFactHandle) stiltonHandle );
+        Tuple tuple = new ReteTuple( (DefaultFactHandle) stiltonHandle );
 
         List list = new ArrayList();
         wm.setGlobal( "list",

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/resolvers/ListValueTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/resolvers/ListValueTest.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/resolvers/ListValueTest.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -14,6 +14,7 @@
 import org.drools.reteoo.ReteTuple;
 import org.drools.rule.Column;
 import org.drools.rule.Package;
+import org.drools.spi.Tuple;
 
 import junit.framework.TestCase;
 
@@ -58,7 +59,7 @@
                                      20 );
         FactHandle stiltonHandle = wm.assertObject( stilton );
 
-        ReteTuple tuple = new ReteTuple( (DefaultFactHandle) stiltonHandle );
+        Tuple tuple = new ReteTuple( (DefaultFactHandle) stiltonHandle );
         
         List values = ( List ) listValue.getValue( tuple, wm );
         assertEquals( "literal", values.get( 0 ) );
@@ -87,7 +88,7 @@
                                      20 );
         FactHandle stiltonHandle = wm.assertObject( stilton );
 
-        ReteTuple tuple = new ReteTuple( (DefaultFactHandle) stiltonHandle );
+        Tuple tuple = new ReteTuple( (DefaultFactHandle) stiltonHandle );
         
         List list = ( List ) listValue.getValue( tuple, wm );
         assertEquals( 1, list.size() );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/resolvers/LiteralValueTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/resolvers/LiteralValueTest.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/resolvers/LiteralValueTest.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -10,6 +10,7 @@
 import org.drools.common.DefaultFactHandle;
 import org.drools.reteoo.ReteTuple;
 import org.drools.rule.Package;
+import org.drools.spi.Tuple;
 
 public class LiteralValueTest extends TestCase {
     public void testLiteral() throws Exception {
@@ -24,7 +25,7 @@
                                      20 );
         FactHandle stiltonHandle = wm.assertObject( stilton );
 
-        ReteTuple tuple = new ReteTuple( (DefaultFactHandle) stiltonHandle );
+        Tuple tuple = new ReteTuple( (DefaultFactHandle) stiltonHandle );
         assertEquals( "literal",
                       literal.getValue( tuple,
                                         wm ) );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/resolvers/MapValueTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/resolvers/MapValueTest.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/base/resolvers/MapValueTest.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -16,6 +16,7 @@
 import org.drools.reteoo.ReteTuple;
 import org.drools.rule.Column;
 import org.drools.rule.Package;
+import org.drools.spi.Tuple;
 
 public class MapValueTest extends TestCase {
     public void testFlatMap() throws Exception {
@@ -61,7 +62,7 @@
                                      20 );
         FactHandle stiltonHandle = wm.assertObject( stilton );
 
-        ReteTuple tuple = new ReteTuple( (DefaultFactHandle) stiltonHandle );
+        Tuple tuple = new ReteTuple( (DefaultFactHandle) stiltonHandle );
 
         List list = new ArrayList();
         wm.setGlobal( "list",
@@ -104,7 +105,7 @@
                                      20 );
         FactHandle stiltonHandle = wm.assertObject( stilton );
 
-        ReteTuple tuple = new ReteTuple( (DefaultFactHandle) stiltonHandle );
+        Tuple tuple = new ReteTuple( (DefaultFactHandle) stiltonHandle );
 
         Map map = (Map) mapValue.getValue( tuple,
                                            wm );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/examples/manners/ReteooMannersTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/examples/manners/ReteooMannersTest.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/examples/manners/ReteooMannersTest.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -55,7 +55,7 @@
         //           
         //        });
 
-        final InputStream is = getClass().getResourceAsStream( "/manners5.dat" );
+        final InputStream is = getClass().getResourceAsStream( "/manners128.dat" );
         final List list = getInputObjects( is );
         for ( final Iterator it = list.iterator(); it.hasNext(); ) {
             final Object object = it.next();

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AccumulateNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AccumulateNodeTest.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AccumulateNodeTest.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -33,6 +33,7 @@
 import org.drools.spi.MockConstraint;
 import org.drools.spi.ObjectType;
 import org.drools.spi.PropagationContext;
+import org.drools.spi.Tuple;
 
 /**
  * A test case for AccumulateNode
@@ -155,8 +156,8 @@
                              2,
                              this.sink.getAsserted().size() );
 
-        final ReteTuple t1 = (ReteTuple) ((Object[]) this.sink.getAsserted().get( 0 ))[0];
-        final ReteTuple t2 = (ReteTuple) ((Object[]) this.sink.getAsserted().get( 1 ))[0];
+        final Tuple t1 = (Tuple) ((Object[]) this.sink.getAsserted().get( 0 ))[0];
+        final Tuple t2 = (Tuple) ((Object[]) this.sink.getAsserted().get( 1 ))[0];
 
         List propagated = this.node.getPropagatedTuples( workingMemory,
                                                          sink );
@@ -420,7 +421,7 @@
                              2,
                              this.accumulator.getMatchingObjects().size() );
 
-        final ReteTuple tuple = (ReteTuple) this.memory.getLeftTupleMemory().iterator( this.workingMemory,
+        final Tuple tuple = (Tuple) this.memory.getLeftTupleMemory().iterator( this.workingMemory,
                                                                                        f0 ).next();
         assertEquals( tuple0,
                       tuple );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -33,6 +33,7 @@
 import org.drools.spi.MockConstraint;
 import org.drools.spi.ObjectType;
 import org.drools.spi.PropagationContext;
+import org.drools.spi.Tuple;
 
 /**
  * @author etirelli
@@ -141,8 +142,8 @@
                              2,
                              this.sink.getAsserted().size() );
 
-        final ReteTuple t1 = (ReteTuple) ((Object[]) this.sink.getAsserted().get( 0 ))[0];
-        final ReteTuple t2 = (ReteTuple) ((Object[]) this.sink.getAsserted().get( 1 ))[0];
+        final Tuple t1 = (Tuple) ((Object[]) this.sink.getAsserted().get( 0 ))[0];
+        final Tuple t2 = (Tuple) ((Object[]) this.sink.getAsserted().get( 1 ))[0];
 
         List propagated = this.node.getPropagatedTuples( workingMemory,
                                                          sink );
@@ -169,7 +170,7 @@
         assertEquals( 0,
                       this.memory.getRightObjectMemory().size() );
         Assert.assertTrue( "An empty collection should be propagated",
-                           ((Collection) ((DefaultFactHandle)((ReteTuple) ((Object[])this.sink.getAsserted().get( 0 ))[0]).get( 1 )).getObject()).isEmpty() );
+                           ((Collection) ((DefaultFactHandle)((Tuple) ((Object[])this.sink.getAsserted().get( 0 ))[0]).get( 1 )).getObject()).isEmpty() );
 
         // assert tuple, should add left memory 
         final DefaultFactHandle f1 = (DefaultFactHandle) workingMemory.getFactHandleFactory().newFactHandle( "other cheese" );
@@ -181,7 +182,7 @@
         assertEquals( 2,
                       this.memory.getLeftTupleMemory().size() );
         Assert.assertTrue( "An empty collection should be propagated",
-                           ((Collection) ((DefaultFactHandle)((ReteTuple) ((Object[])this.sink.getAsserted().get( 1 ))[0]).get( 1 )).getObject()).isEmpty() );
+                           ((Collection) ((DefaultFactHandle)((Tuple) ((Object[])this.sink.getAsserted().get( 1 ))[0]).get( 1 )).getObject()).isEmpty() );
 
         final ReteTuple tuple = (ReteTuple) this.memory.getLeftTupleMemory().iterator( this.workingMemory,
                                                                                        f0 ).next();
@@ -219,7 +220,7 @@
                       this.memory.getRightObjectMemory().size() );
         Assert.assertEquals( "Wrong number of elements in matching objects list ",
                              2,
-                             ((Collection) ((DefaultFactHandle)((ReteTuple) ((Object[])this.sink.getAsserted().get( 0 ))[0]).get( 1 )).getObject()).size() );
+                             ((Collection) ((DefaultFactHandle)((Tuple) ((Object[])this.sink.getAsserted().get( 0 ))[0]).get( 1 )).getObject()).size() );
 
         // assert tuple, should add left memory 
         final ReteTuple tuple1 = new ReteTuple( f1 );
@@ -230,7 +231,7 @@
                       this.memory.getLeftTupleMemory().size() );
         Assert.assertEquals( "Wrong number of elements in matching objects list ",
                              2,
-                             ((Collection) ((DefaultFactHandle)((ReteTuple) ((Object[])this.sink.getAsserted().get( 1 ))[0]).get( 1 )).getObject()).size() );
+                             ((Collection) ((DefaultFactHandle)((Tuple) ((Object[])this.sink.getAsserted().get( 1 ))[0]).get( 1 )).getObject()).size() );
 
         final ReteTuple tuple = (ReteTuple) this.memory.getLeftTupleMemory().iterator( this.workingMemory,
                                                                                        f0 ).next();
@@ -259,7 +260,7 @@
         assertEquals( 0,
                       this.memory.getRightObjectMemory().size() );
         Assert.assertTrue( "An empty collection should be propagated",
-                           ((Collection) ((DefaultFactHandle)((ReteTuple) ((Object[])this.sink.getAsserted().get( 0 ))[0]).get( 1 )).getObject()).isEmpty() );
+                           ((Collection) ((DefaultFactHandle)((Tuple) ((Object[])this.sink.getAsserted().get( 0 ))[0]).get( 1 )).getObject()).isEmpty() );
 
         this.node.modifyTuple( tuple0,
                                this.context,
@@ -271,7 +272,7 @@
         assertEquals( 2,
                       this.sink.getAsserted().size() );
         Assert.assertTrue( "An empty collection should be propagated",
-                           ((Collection) ((DefaultFactHandle)((ReteTuple) ((Object[])this.sink.getAsserted().get( 1 ))[0]).get( 1 )).getObject()).isEmpty() );
+                           ((Collection) ((DefaultFactHandle)((Tuple) ((Object[])this.sink.getAsserted().get( 1 ))[0]).get( 1 )).getObject()).isEmpty() );
     }
 
     public void testRetractTuple() {
@@ -289,7 +290,7 @@
         assertEquals( 0,
                       this.memory.getRightObjectMemory().size() );
         Assert.assertTrue( "An empty collection should be propagated",
-                           ((Collection) ((DefaultFactHandle)((ReteTuple) ((Object[])this.sink.getAsserted().get( 0 ))[0]).get( 1 )).getObject()).isEmpty() );
+                           ((Collection) ((DefaultFactHandle)((Tuple) ((Object[])this.sink.getAsserted().get( 0 ))[0]).get( 1 )).getObject()).isEmpty() );
 
         this.node.retractTuple( tuple0,
                                 this.context,
@@ -319,7 +320,7 @@
         assertEquals( 1,
                       this.sink.getAsserted().size() );
         Assert.assertTrue( "An empty collection should be propagated",
-                           ((Collection) ((DefaultFactHandle)((ReteTuple) ((Object[])this.sink.getAsserted().get( 0 ))[0]).get( 1 )).getObject()).isEmpty() );
+                           ((Collection) ((DefaultFactHandle)((Tuple) ((Object[])this.sink.getAsserted().get( 0 ))[0]).get( 1 )).getObject()).isEmpty() );
 
         this.node.assertObject( f0,
                                 context,
@@ -330,7 +331,7 @@
                       this.sink.getAsserted().size() );
         Assert.assertEquals( "Wrong number of elements in matching objects list ",
                              1,
-                             ((Collection) ((DefaultFactHandle)((ReteTuple) ((Object[])this.sink.getAsserted().get( 1 ))[0]).get( 1 )).getObject()).size() );
+                             ((Collection) ((DefaultFactHandle)((Tuple) ((Object[])this.sink.getAsserted().get( 1 ))[0]).get( 1 )).getObject()).size() );
 
         this.node.assertObject( f1,
                                 context,
@@ -342,7 +343,7 @@
                       this.sink.getAsserted().size() );
         Assert.assertEquals( "Wrong number of elements in matching objects list ",
                              2,
-                             ((Collection) ((DefaultFactHandle)((ReteTuple) ((Object[])this.sink.getAsserted().get( 2 ))[0]).get( 1 )).getObject()).size() );
+                             ((Collection) ((DefaultFactHandle)((Tuple) ((Object[])this.sink.getAsserted().get( 2 ))[0]).get( 1 )).getObject()).size() );
 
     }
 
@@ -374,7 +375,7 @@
                       this.sink.getRetracted().size() );
         Assert.assertEquals( "Wrong number of elements in matching objects list ",
                              2,
-                             ((Collection) ((DefaultFactHandle)((ReteTuple) ((Object[])this.sink.getAsserted().get( 0 ))[0]).get( 1 )).getObject()).size() );
+                             ((Collection) ((DefaultFactHandle)((Tuple) ((Object[])this.sink.getAsserted().get( 0 ))[0]).get( 1 )).getObject()).size() );
 
         // assert tuple, should add left memory 
         this.node.modifyObject( f0,
@@ -388,9 +389,9 @@
                       this.sink.getRetracted().size() );
         Assert.assertEquals( "Wrong number of elements in matching objects list ",
                              2,
-                             ((Collection) ((DefaultFactHandle)((ReteTuple) ((Object[])this.sink.getAsserted().get( 1 ))[0]).get( 1 )).getObject()).size() );
+                             ((Collection) ((DefaultFactHandle)((Tuple) ((Object[])this.sink.getAsserted().get( 1 ))[0]).get( 1 )).getObject()).size() );
 
-        final ReteTuple tuple = (ReteTuple) this.memory.getLeftTupleMemory().iterator( this.workingMemory,
+        final Tuple tuple = (Tuple) this.memory.getLeftTupleMemory().iterator( this.workingMemory,
                                                                                        f0 ).next();
         assertEquals( tuple0,
                       tuple );
@@ -426,7 +427,7 @@
                       this.sink.getAsserted().size() );
         Assert.assertEquals( "Wrong number of elements in matching objects list ",
                              2,
-                             ((Collection) ((DefaultFactHandle)((ReteTuple) ((Object[])this.sink.getAsserted().get( 0 ))[0]).get( 1 )).getObject()).size() );
+                             ((Collection) ((DefaultFactHandle)((Tuple) ((Object[])this.sink.getAsserted().get( 0 ))[0]).get( 1 )).getObject()).size() );
 
         this.node.retractObject( f1,
                                  context,
@@ -439,7 +440,7 @@
                       this.sink.getAsserted().size() );
         Assert.assertEquals( "Wrong number of elements in matching objects list ",
                              1,
-                             ((Collection) ((DefaultFactHandle)((ReteTuple) ((Object[])this.sink.getAsserted().get( 1 ))[0]).get( 1 )).getObject()).size() );
+                             ((Collection) ((DefaultFactHandle)((Tuple) ((Object[])this.sink.getAsserted().get( 1 ))[0]).get( 1 )).getObject()).size() );
 
         this.node.retractObject( f0,
                                  context,
@@ -452,7 +453,7 @@
                       this.sink.getAsserted().size() );
         Assert.assertEquals( "Wrong number of elements in matching objects list ",
                              0,
-                             ((Collection) ((DefaultFactHandle)((ReteTuple) ((Object[])this.sink.getAsserted().get( 2 ))[0]).get( 1 )).getObject()).size() );
+                             ((Collection) ((DefaultFactHandle)((Tuple) ((Object[])this.sink.getAsserted().get( 2 ))[0]).get( 1 )).getObject()).size() );
 
     }
 

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/FromNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/FromNodeTest.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/FromNodeTest.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -87,7 +87,7 @@
         List asserted = sink.getAsserted();
         assertEquals( 1,
                       asserted.size() );
-        ReteTuple tuple = (ReteTuple) ((Object[]) asserted.get( 0 ))[0];
+        Tuple tuple = (Tuple) ((Object[]) asserted.get( 0 ))[0];
         assertSame( person2,
                     tuple.getFactHandles()[0].getObject() );
         assertSame( cheese1,
@@ -104,12 +104,12 @@
 
         assertEquals( 3,
                       asserted.size() );
-        tuple = (ReteTuple) ((Object[]) asserted.get( 1 ))[0];
+        tuple = (Tuple) ((Object[]) asserted.get( 1 ))[0];
         assertSame( person3,
                     tuple.getFactHandles()[0].getObject() );
         assertSame( cheese1,
                     tuple.getFactHandles()[1].getObject() );
-        tuple = (ReteTuple) ((Object[]) asserted.get( 2 ))[0];
+        tuple = (Tuple) ((Object[]) asserted.get( 2 ))[0];
         assertSame( person3,
                     tuple.getFactHandles()[0].getObject() );
         assertSame( cheese2,
@@ -186,7 +186,7 @@
         List asserted = sink.getAsserted();
         assertEquals( 1,
                       asserted.size() );
-        ReteTuple tuple = (ReteTuple) ((Object[]) asserted.get( 0 ))[0];
+        Tuple tuple = (Tuple) ((Object[]) asserted.get( 0 ))[0];
         assertSame( person2,
                     tuple.getFactHandles()[0].getObject() );
         assertSame( cheese1,
@@ -203,12 +203,12 @@
 
         assertEquals( 3,
                       asserted.size() );
-        tuple = (ReteTuple) ((Object[]) asserted.get( 1 ))[0];
+        tuple = (Tuple) ((Object[]) asserted.get( 1 ))[0];
         assertSame( person3,
                     tuple.getFactHandles()[0].getObject() );
         assertSame( cheese1,
                     tuple.getFactHandles()[1].getObject() );
-        tuple = (ReteTuple) ((Object[]) asserted.get( 2 ))[0];
+        tuple = (Tuple) ((Object[]) asserted.get( 2 ))[0];
         assertSame( person3,
                     tuple.getFactHandles()[0].getObject() );
         assertSame( cheese2,
@@ -342,7 +342,7 @@
         List asserted = sink.getAsserted();
         assertEquals( 1,
                       asserted.size() );
-        ReteTuple tuple = (ReteTuple) ((Object[]) asserted.get( 0 ))[0];
+        Tuple tuple = (Tuple) ((Object[]) asserted.get( 0 ))[0];
         assertSame( person1,
                     tuple.getFactHandles()[0].getObject() );
         assertSame( cheese1,
@@ -359,13 +359,13 @@
         
         assertEquals( 3,
                       asserted.size() );
-        tuple = (ReteTuple) ((Object[]) asserted.get( 1 ))[0];
+        tuple = (Tuple) ((Object[]) asserted.get( 1 ))[0];
         assertSame( person1,
                     tuple.getFactHandles()[0].getObject() );
         assertSame( cheese1,
                     tuple.getFactHandles()[1].getObject() );    
         
-        tuple = (ReteTuple) ((Object[]) asserted.get( 2 ))[0];
+        tuple = (Tuple) ((Object[]) asserted.get( 2 ))[0];
         assertSame( person1,
                     tuple.getFactHandles()[0].getObject() );
         assertSame( cheese2,

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/InstrumentedReteTuple.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/InstrumentedReteTuple.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/InstrumentedReteTuple.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -18,6 +18,7 @@
 
 import org.drools.FactHandle;
 import org.drools.common.DefaultFactHandle;
+import org.drools.spi.Tuple;
 
 public class InstrumentedReteTuple extends ReteTuple {
     /**
@@ -25,7 +26,7 @@
      */
     private static final long serialVersionUID = -5225370016555785111L;
 
-    public InstrumentedReteTuple(final ReteTuple left,
+    public InstrumentedReteTuple(final Tuple left,
                                  final FactHandle handle) {
         super( left,
                (DefaultFactHandle) handle );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/JoinNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/JoinNodeTest.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/JoinNodeTest.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -21,7 +21,7 @@
 
 import org.drools.DroolsTestCase;
 import org.drools.RuleBaseFactory;
-import org.drools.common.BetaNodeBinder;
+import org.drools.common.BetaNodeConstraints;
 import org.drools.common.DefaultFactHandle;
 import org.drools.common.PropagationContextImpl;
 import org.drools.reteoo.beta.BetaRightMemory;
@@ -29,6 +29,7 @@
 import org.drools.spi.FieldConstraint;
 import org.drools.spi.MockConstraint;
 import org.drools.spi.PropagationContext;
+import org.drools.spi.Tuple;
 
 public class JoinNodeTest extends DroolsTestCase {
     Rule                rule;
@@ -60,7 +61,7 @@
         this.node = new JoinNode( 15,
                                   this.tupleSource,
                                   this.objectSource,
-                                  new BetaNodeBinder( new FieldConstraint[]{this.constraint} ) );
+                                  new BetaNodeConstraints( new FieldConstraint[]{this.constraint} ) );
 
         this.node.addTupleSink( this.sink );
 
@@ -303,14 +304,14 @@
                                 this.workingMemory );
         ObjectMatches matches = this.getMatchesFor( tuple2,
                                                     f3 );
-        for ( TupleMatch match = matches.getFirstTupleMatch(); match != null; match = (TupleMatch) match.getNext() ) {
+        for ( CompositeTupleMatch match = matches.getFirstTupleMatch(); match != null; match = (CompositeTupleMatch) match.getNext() ) {
             assertNotSame( tuple2,
                            match.getTuple() );
         }
 
         matches = this.getMatchesFor( tuple2,
                                       f4 );
-        for ( TupleMatch match = matches.getFirstTupleMatch(); match != null; match = (TupleMatch) match.getNext() ) {
+        for ( CompositeTupleMatch match = matches.getFirstTupleMatch(); match != null; match = (CompositeTupleMatch) match.getNext() ) {
             assertNotSame( tuple2,
                            match.getTuple() );
         }
@@ -398,7 +399,7 @@
      * @param f3
      * @return
      */
-    private ObjectMatches getMatchesFor(final ReteTuple tuple1,
+    private ObjectMatches getMatchesFor(final Tuple tuple1,
                                         final DefaultFactHandle f3) {
         ObjectMatches matches = null;
         for ( final Iterator i = this.memory.rightObjectIterator( this.workingMemory,

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LeftInputAdapterNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LeftInputAdapterNodeTest.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LeftInputAdapterNodeTest.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -24,8 +24,9 @@
 import org.drools.common.DefaultFactHandle;
 import org.drools.common.PropagationContextImpl;
 import org.drools.spi.PropagationContext;
+import org.drools.spi.Tuple;
 import org.drools.util.LinkedList;
-import org.drools.util.LinkedListObjectWrapper;
+import org.drools.util.LinkedListEntry;
 
 public class LeftInputAdapterNodeTest extends DroolsTestCase {
 
@@ -98,7 +99,7 @@
         final List asserted = sink.getAsserted();
         assertLength( 1,
                       asserted );
-        final ReteTuple tuple0 = (ReteTuple) ((Object[]) asserted.get( 0 ))[0];
+        final Tuple tuple0 = (Tuple) ((Object[]) asserted.get( 0 ))[0];
         assertSame( string1,
                     workingMemory.getObject( tuple0.get( 0 ) ) );
 
@@ -108,7 +109,7 @@
         assertEquals( 1,
                       list0.size() );
         assertSame( tuple0,
-                    ((LinkedListObjectWrapper) list0.getFirst()).getObject() );
+                    ((LinkedListEntry) list0.getFirst()).getObject() );
 
         // check memory stacks correctly
         final DefaultFactHandle f1 = (DefaultFactHandle) workingMemory.assertObject( "test1" );
@@ -118,13 +119,13 @@
 
         assertLength( 2,
                       asserted );
-        final ReteTuple tuple1 = (ReteTuple) ((Object[]) asserted.get( 1 ))[0];
+        final Tuple tuple1 = (Tuple) ((Object[]) asserted.get( 1 ))[0];
 
         final LinkedList list1 = (LinkedList) map.get( f1 );
         assertEquals( 1,
                       list1.size() );
         assertSame( tuple1,
-                    ((LinkedListObjectWrapper) list1.getFirst()).getObject() );
+                    ((LinkedListEntry) list1.getFirst()).getObject() );
 
         assertNotSame( tuple0,
                        tuple1 );
@@ -160,7 +161,7 @@
                               context,
                               workingMemory );
 
-        final ReteTuple tuple = (ReteTuple) ((Object[]) sink.getAsserted().get( 0 ))[0];
+        final Tuple tuple = (Tuple) ((Object[]) sink.getAsserted().get( 0 ))[0];
 
         liaNode.retractObject( f0,
                                context,

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/MockAccumulator.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/MockAccumulator.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/MockAccumulator.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -21,6 +21,7 @@
 import org.drools.WorkingMemory;
 import org.drools.rule.Declaration;
 import org.drools.spi.Accumulator;
+import org.drools.spi.Tuple;
 
 /**
  * A Mock accumulate object.
@@ -34,14 +35,14 @@
     
     private static final long serialVersionUID = 8959310397185256783L;
     
-    private ReteTuple leftTuple = null;
+    private Tuple leftTuple = null;
     private List      matchingObjects = Collections.EMPTY_LIST;
     private WorkingMemory workingMemory = null;
 
     /* (non-Javadoc)
      * @see org.drools.reteoo.Accumulator#accumulate(org.drools.reteoo.ReteTuple, java.util.List, org.drools.WorkingMemory)
      */
-    public Object accumulate(ReteTuple leftTuple,
+    public Object accumulate(Tuple leftTuple,
                              List matchingObjects,
                              Declaration[] declarations,
                              Declaration[] inner,
@@ -52,7 +53,7 @@
         return matchingObjects;
     }
 
-    public ReteTuple getLeftTuple() {
+    public Tuple getLeftTuple() {
         return leftTuple;
     }
 

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/MockTupleSink.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/MockTupleSink.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/MockTupleSink.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -27,6 +27,7 @@
 import org.drools.common.InternalWorkingMemory;
 import org.drools.common.NodeMemory;
 import org.drools.spi.PropagationContext;
+import org.drools.spi.Tuple;
 
 public class MockTupleSink extends TupleSource
     implements
@@ -48,21 +49,21 @@
         super( id );
     }
 
-    public void assertTuple(final ReteTuple tuple,
+    public void assertTuple(final Tuple tuple,
                             final PropagationContext context,
                             final ReteooWorkingMemory workingMemory) {
         this.asserted.add( new Object[]{tuple, context, workingMemory} );
 
     }
 
-    public void retractTuple(final ReteTuple tuple,
+    public void retractTuple(final Tuple tuple,
                              final PropagationContext context,
                              final ReteooWorkingMemory workingMemory) {
         this.retracted.add( new Object[]{tuple, context, workingMemory} );
 
     }
 
-    public void modifyTuple(final ReteTuple tuple,
+    public void modifyTuple(final Tuple tuple,
                             final PropagationContext context,
                             final ReteooWorkingMemory workingMemory) {
         this.modified.add( new Object[]{tuple, context, workingMemory} );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/NotNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/NotNodeTest.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/NotNodeTest.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -24,7 +24,7 @@
 import org.drools.DroolsTestCase;
 import org.drools.FactException;
 import org.drools.RuleBaseFactory;
-import org.drools.common.BetaNodeBinder;
+import org.drools.common.BetaNodeConstraints;
 import org.drools.common.DefaultFactHandle;
 import org.drools.common.PropagationContextImpl;
 import org.drools.rule.Rule;
@@ -60,7 +60,7 @@
         this.node = new NotNode( 15,
                                  new MockTupleSource( 5 ),
                                  new MockObjectSource( 8 ),
-                                 new BetaNodeBinder( this.constraint ) );
+                                 new BetaNodeConstraints( this.constraint ) );
 
         this.ria = new RightInputAdapterNode( 2,
                                               0,

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/TupleSourceTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/TupleSourceTest.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/TupleSourceTest.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -22,6 +22,7 @@
 import org.drools.common.PropagationContextImpl;
 import org.drools.rule.Rule;
 import org.drools.spi.PropagationContext;
+import org.drools.spi.Tuple;
 
 public class TupleSourceTest extends DroolsTestCase {
 
@@ -67,7 +68,7 @@
         assertLength( 0,
                       sink1.getAsserted() );
 
-        final ReteTuple tuple1 = new ReteTuple( new DefaultFactHandle( 1,
+        final Tuple tuple1 = new ReteTuple( new DefaultFactHandle( 1,
                                                                        "cheese" ) );
 
         source.propagateAssertTuple( tuple1,
@@ -85,7 +86,7 @@
         assertSame( workingMemory,
                     list[2] );
 
-        final ReteTuple tuple2 = new ReteTuple( new DefaultFactHandle( 1,
+        final Tuple tuple2 = new ReteTuple( new DefaultFactHandle( 1,
                                                                        "cheese" ) );
 
         final MockTupleSink sink2 = new MockTupleSink();

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BaseBetaLeftMemoryTestClass.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BaseBetaLeftMemoryTestClass.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BaseBetaLeftMemoryTestClass.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -32,6 +32,7 @@
 import org.drools.reteoo.ReteooRuleBase;
 import org.drools.reteoo.ReteooWorkingMemory;
 import org.drools.spi.FactHandleFactory;
+import org.drools.spi.Tuple;
 import org.drools.util.MultiLinkedListNodeWrapper;
 
 /**
@@ -319,28 +320,28 @@
             final Iterator i = this.memory.iterator();
             Assert.assertTrue( "There should be a next tuple",
                                i.hasNext() );
-            ReteTuple tuple = (ReteTuple) i.next();
+            Tuple tuple = (Tuple) i.next();
             Assert.assertSame( "Wrong returned tuple",
                                this.tuple0,
                                tuple );
 
             Assert.assertTrue( "There should be a next tuple",
                                i.hasNext() );
-            tuple = (ReteTuple) i.next();
+            tuple = (Tuple) i.next();
             Assert.assertSame( "Wrong returned tuple",
                                this.tuple1,
                                tuple );
 
             Assert.assertTrue( "There should be a next tuple",
                                i.hasNext() );
-            tuple = (ReteTuple) i.next();
+            tuple = (Tuple) i.next();
             Assert.assertSame( "Wrong returned tuple",
                                this.tuple2,
                                tuple );
 
             Assert.assertTrue( "There should be a next tuple",
                                i.hasNext() );
-            tuple = (ReteTuple) i.next();
+            tuple = (Tuple) i.next();
             Assert.assertSame( "Wrong returned tuple",
                                tuple3,
                                tuple );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BaseBetaRightMemoryTestClass.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BaseBetaRightMemoryTestClass.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BaseBetaRightMemoryTestClass.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -32,6 +32,7 @@
 import org.drools.reteoo.ReteooRuleBase;
 import org.drools.reteoo.ReteooWorkingMemory;
 import org.drools.spi.FactHandleFactory;
+import org.drools.spi.Tuple;
 import org.drools.util.MultiLinkedListNodeWrapper;
 
 /**
@@ -57,9 +58,9 @@
     protected ObjectMatches       matches0;
     protected ObjectMatches       matches1;
     protected ObjectMatches       matches2;
-    protected ReteTuple           tuple0;
-    protected ReteTuple           tuple1;
-    protected ReteTuple           tuple2;
+    protected Tuple           tuple0;
+    protected Tuple           tuple1;
+    protected Tuple           tuple2;
 
     public BaseBetaRightMemoryTestClass() {
         this.memory = null;
@@ -398,7 +399,7 @@
         }
 
         public Iterator iterator(final WorkingMemory workingMemory,
-                                 final ReteTuple tuple) {
+                                 final Tuple tuple) {
             this.callCounter++;
             return null;
         }
@@ -419,7 +420,7 @@
         }
 
         public void selectPossibleMatches(final WorkingMemory workingMemory,
-                                          final ReteTuple tuple) {
+                                          final Tuple tuple) {
             this.callCounter++;
         }
 

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BetaMemoryFactoryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BetaMemoryFactoryTest.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BetaMemoryFactoryTest.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -20,7 +20,7 @@
 import junit.framework.TestCase;
 
 import org.drools.RuleBaseConfiguration;
-import org.drools.common.BetaNodeBinder;
+import org.drools.common.BetaNodeConstraints;
 import org.drools.spi.FieldConstraint;
 import org.drools.spi.MockConstraint;
 
@@ -34,14 +34,14 @@
  * Created: 28/02/2006
  */
 public class BetaMemoryFactoryTest extends TestCase {
-    BetaNodeBinder        binder = null;
+    BetaNodeConstraints        binder = null;
     RuleBaseConfiguration config;
 
     protected void setUp() throws Exception {
         super.setUp();
         this.config = new RuleBaseConfiguration();
         final FieldConstraint[] constraints = new FieldConstraint[]{new MockConstraint()};
-        this.binder = new BetaNodeBinder( constraints );
+        this.binder = new BetaNodeConstraints( constraints );
     }
 
     protected void tearDown() throws Exception {

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BooleanConstrainedLeftMemoryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BooleanConstrainedLeftMemoryTest.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BooleanConstrainedLeftMemoryTest.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -31,6 +31,7 @@
 import org.drools.rule.Column;
 import org.drools.rule.Declaration;
 import org.drools.spi.Evaluator;
+import org.drools.spi.Tuple;
 import org.drools.util.MultiLinkedListNodeWrapper;
 
 /**
@@ -84,7 +85,7 @@
 
             Assert.assertTrue( "There should be a next element",
                                iterator.hasNext() );
-            final ReteTuple t0 = (ReteTuple) iterator.next();
+            final Tuple t0 = (Tuple) iterator.next();
             Assert.assertSame( "The first object to return should have been tuple0",
                                this.tuple0,
                                t0 );
@@ -96,7 +97,7 @@
 
             Assert.assertTrue( "There should be a next element",
                                iterator.hasNext() );
-            final ReteTuple t1 = (ReteTuple) iterator.next();
+            final Tuple t1 = (Tuple) iterator.next();
             Assert.assertSame( "The second object to return should have been tuple1",
                                this.tuple1,
                                t1 );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BooleanConstrainedRightMemoryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BooleanConstrainedRightMemoryTest.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/BooleanConstrainedRightMemoryTest.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -31,6 +31,7 @@
 import org.drools.rule.Column;
 import org.drools.rule.Declaration;
 import org.drools.spi.Evaluator;
+import org.drools.spi.Tuple;
 import org.drools.util.MultiLinkedListNodeWrapper;
 
 /**
@@ -115,7 +116,7 @@
                                                                 "object3" );
             final DefaultFactHandle f2 = (DefaultFactHandle) this.factory.newFactHandle( obj2 );
 
-            final ReteTuple tuple2 = new ReteTuple( f2 );
+            final Tuple tuple2 = new ReteTuple( f2 );
             iterator = this.memory.iterator( this.workingMemory,
                                              tuple2 );
             Assert.assertFalse( "There should not be a next element",
@@ -163,7 +164,7 @@
                                                             "object3" );
         final DefaultFactHandle f2 = (DefaultFactHandle) this.factory.newFactHandle( obj2 );
 
-        final ReteTuple tuple2 = new ReteTuple( f2 );
+        final Tuple tuple2 = new ReteTuple( f2 );
         this.memory.selectPossibleMatches( this.workingMemory,
                                            tuple2 );
         Assert.assertFalse( "Wrapper0 was not a possible match",

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/DefaultLeftMemoryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/DefaultLeftMemoryTest.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/DefaultLeftMemoryTest.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -23,6 +23,7 @@
 
 import org.drools.common.DefaultFactHandle;
 import org.drools.reteoo.ReteTuple;
+import org.drools.spi.Tuple;
 import org.drools.util.MultiLinkedListNodeWrapper;
 
 public class DefaultLeftMemoryTest extends BaseBetaLeftMemoryTestClass {
@@ -61,7 +62,7 @@
 
             Assert.assertTrue( "There should be a next element",
                                iterator.hasNext() );
-            final ReteTuple t0 = (ReteTuple) iterator.next();
+            final Tuple t0 = (Tuple) iterator.next();
             Assert.assertSame( "The first object to return should have been tuple0",
                                this.tuple0,
                                t0 );
@@ -73,7 +74,7 @@
 
             Assert.assertTrue( "There should be a next element",
                                iterator.hasNext() );
-            final ReteTuple t1 = (ReteTuple) iterator.next();
+            final Tuple t1 = (Tuple) iterator.next();
             Assert.assertSame( "The second object to return should have been tuple1",
                                this.tuple1,
                                t1 );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/InstanceEqualConstrRightMemoryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/InstanceEqualConstrRightMemoryTest.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/InstanceEqualConstrRightMemoryTest.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -31,6 +31,7 @@
 import org.drools.rule.Column;
 import org.drools.rule.Declaration;
 import org.drools.spi.Evaluator;
+import org.drools.spi.Tuple;
 import org.drools.util.MultiLinkedListNodeWrapper;
 
 /**
@@ -115,7 +116,7 @@
                                                                 "object3" );
             final DefaultFactHandle f2 = (DefaultFactHandle) this.factory.newFactHandle( obj2 );
 
-            final ReteTuple tuple2 = new ReteTuple( f2 );
+            final Tuple tuple2 = new ReteTuple( f2 );
             iterator = this.memory.iterator( this.workingMemory,
                                              tuple2 );
             Assert.assertFalse( "There should not be a next element",
@@ -161,7 +162,7 @@
                                                             30,
                                                             "object3" );
         final DefaultFactHandle f2 = (DefaultFactHandle) this.factory.newFactHandle( obj2 );
-        final ReteTuple tuple2 = new ReteTuple( f2 );
+        final Tuple tuple2 = new ReteTuple( f2 );
 
         this.memory.selectPossibleMatches( this.workingMemory,
                                            tuple2 );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/ObjectEqualConstrLeftMemoryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/ObjectEqualConstrLeftMemoryTest.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/ObjectEqualConstrLeftMemoryTest.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -30,6 +30,7 @@
 import org.drools.rule.Column;
 import org.drools.rule.Declaration;
 import org.drools.spi.Evaluator;
+import org.drools.spi.Tuple;
 import org.drools.util.MultiLinkedListNodeWrapper;
 
 /**
@@ -82,7 +83,7 @@
 
             Assert.assertTrue( "There should be a next element",
                                iterator.hasNext() );
-            final ReteTuple t0 = (ReteTuple) iterator.next();
+            final Tuple t0 = (Tuple) iterator.next();
             Assert.assertSame( "The first object to return should have been tuple0",
                                this.tuple0,
                                t0 );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/ObjectEqualConstrRightMemoryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/ObjectEqualConstrRightMemoryTest.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/ObjectEqualConstrRightMemoryTest.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -31,6 +31,7 @@
 import org.drools.rule.Column;
 import org.drools.rule.Declaration;
 import org.drools.spi.Evaluator;
+import org.drools.spi.Tuple;
 import org.drools.util.MultiLinkedListNodeWrapper;
 
 /**
@@ -115,7 +116,7 @@
                                                                 "object3" );
             final DefaultFactHandle f2 = (DefaultFactHandle) this.factory.newFactHandle( obj2 );
 
-            final ReteTuple tuple2 = new ReteTuple( f2 );
+            final Tuple tuple2 = new ReteTuple( f2 );
             iterator = this.memory.iterator( this.workingMemory,
                                              tuple2 );
             Assert.assertFalse( "There should not be a next element",
@@ -161,7 +162,7 @@
                                                             30,
                                                             "object3" );
         final DefaultFactHandle f2 = (DefaultFactHandle) this.factory.newFactHandle( obj2 );
-        final ReteTuple tuple2 = new ReteTuple( f2 );
+        final Tuple tuple2 = new ReteTuple( f2 );
 
         this.memory.selectPossibleMatches( this.workingMemory,
                                            tuple2 );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/ObjectNotEqualConstrLeftMemoryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/ObjectNotEqualConstrLeftMemoryTest.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/ObjectNotEqualConstrLeftMemoryTest.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -30,6 +30,7 @@
 import org.drools.rule.Column;
 import org.drools.rule.Declaration;
 import org.drools.spi.Evaluator;
+import org.drools.spi.Tuple;
 import org.drools.util.MultiLinkedListNodeWrapper;
 
 /**
@@ -83,7 +84,7 @@
 
             Assert.assertTrue( "There should be a next element",
                                iterator.hasNext() );
-            final ReteTuple t1 = (ReteTuple) iterator.next();
+            final Tuple t1 = (Tuple) iterator.next();
             Assert.assertSame( "The first object to return should have been tuple1",
                                this.tuple1,
                                t1 );
@@ -114,7 +115,7 @@
             Assert.assertTrue( "There should be a next element",
                                iterator.hasNext() );
 
-            final ReteTuple t0 = (ReteTuple) iterator.next();
+            final Tuple t0 = (Tuple) iterator.next();
             Assert.assertSame( "The first object to return should have been tuple0",
                                this.tuple0,
                                t0 );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/ObjectNotEqualConstrRightMemoryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/ObjectNotEqualConstrRightMemoryTest.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/beta/ObjectNotEqualConstrRightMemoryTest.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -31,6 +31,7 @@
 import org.drools.rule.Column;
 import org.drools.rule.Declaration;
 import org.drools.spi.Evaluator;
+import org.drools.spi.Tuple;
 import org.drools.util.MultiLinkedListNodeWrapper;
 
 /**
@@ -115,7 +116,7 @@
                                                                 30,
                                                                 "object3" );
             final DefaultFactHandle f2 = (DefaultFactHandle) this.factory.newFactHandle( obj2 );
-            final ReteTuple tuple2 = new ReteTuple( f2 );
+            final Tuple tuple2 = new ReteTuple( f2 );
 
             iterator = this.memory.iterator( this.workingMemory,
                                              tuple2 );
@@ -175,7 +176,7 @@
                                                             30,
                                                             "object3" );
         final DefaultFactHandle f2 = (DefaultFactHandle) this.factory.newFactHandle( obj2 );
-        final ReteTuple tuple2 = new ReteTuple( f2 );
+        final Tuple tuple2 = new ReteTuple( f2 );
 
         this.memory.selectPossibleMatches( this.workingMemory,
                                            tuple2 );

Added: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexEntryTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexEntryTest.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexEntryTest.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -0,0 +1,123 @@
+package org.drools.util;
+
+import org.drools.Cheese;
+import org.drools.base.ClassFieldExtractor;
+import org.drools.common.DefaultFactHandle;
+import org.drools.common.InternalFactHandle;
+
+import junit.framework.TestCase;
+
+public class FieldIndexEntryTest extends TestCase {
+    
+    public void testSingleEntry() {                       
+        ClassFieldExtractor extractor = new ClassFieldExtractor(Cheese.class, "type");
+        
+        FieldIndexEntry index = new FieldIndexEntry( extractor, extractor.getIndex(), "stilton".hashCode() );
+        
+        // Test initial construction
+        assertNull( index.getValue() );        
+        assertNull( index.getFirst() );
+        assertEquals( "stilton".hashCode(), index.hashCode() );
+        
+        Cheese stilton1 = new Cheese("stilton", 35);
+        InternalFactHandle h1 = new DefaultFactHandle( 1, stilton1 );       
+        
+        // test add
+        index.add( h1 );        
+        assertEquals( "stilton", index.getValue() );
+        FactEntry entry1 = index.getFirst();
+        assertSame( h1, entry1.getFactHandle() );       
+        assertNull( entry1.getNext() );        
+        assertSame( entry1, index.get( h1 ) );
+        
+        // test get
+        FactEntry entry2 = ( FactEntry ) index.get( h1 );
+        assertSame( entry1, entry2 );        
+        
+        // test remove
+        index.remove( h1 );        
+        assertNull( index.getFirst() );
+        assertNull( index.getValue() );                 
+    }
+
+    
+    public void testTwoEntries() {                       
+        ClassFieldExtractor extractor = new ClassFieldExtractor(Cheese.class, "type");
+        FieldIndexEntry index = new FieldIndexEntry( extractor, extractor.getIndex(), "stilton".hashCode() );
+
+        Cheese stilton1 = new Cheese("stilton", 35);
+        InternalFactHandle h1 = new DefaultFactHandle( 1, stilton1 );               
+        Cheese stilton2 = new Cheese("stilton", 59);
+        InternalFactHandle h2 = new DefaultFactHandle( 2, stilton2 );
+        
+        // test add
+        index.add( h1 );
+        index.add( h2 );        
+        assertEquals( h2, index.getFirst().getFactHandle() );
+        assertEquals( h1, ( ( FactEntry ) index.getFirst().getNext() ).getFactHandle() );
+        
+        // test get
+        assertEquals( h1, index.get( h1 ).getFactHandle() );
+        assertEquals( h2, index.get( h2 ).getFactHandle() );
+
+        // test removal for combinations
+        // remove first
+        index.remove( h2 );
+        assertEquals( h1, index.getFirst().getFactHandle() );
+        
+        // remove second
+        index.add( h2 );
+        index.remove( h1 );
+        assertEquals( h2, index.getFirst().getFactHandle() );    
+        
+        // check index type does not change, as this fact is removed
+        stilton1.setType( "cheddar" );
+        assertEquals( "stilton", index.getValue() );
+    }       
+    
+    public void testThreeEntries() {                       
+        ClassFieldExtractor extractor = new ClassFieldExtractor(Cheese.class, "type");
+        FieldIndexEntry index = new FieldIndexEntry( extractor, extractor.getIndex(), "stilton".hashCode() );
+
+        Cheese stilton1 = new Cheese("stilton", 35);
+        InternalFactHandle h1 = new DefaultFactHandle( 1, stilton1 );               
+        Cheese stilton2 = new Cheese("stilton", 59);
+        InternalFactHandle h2 = new DefaultFactHandle( 2, stilton2 );
+        Cheese stilton3 = new Cheese("stilton", 59);
+        InternalFactHandle h3 = new DefaultFactHandle( 3, stilton3 );
+        
+        // test add
+        index.add( h1 );
+        index.add( h2 );
+        index.add( h3 );        
+        assertEquals( h3, index.getFirst().getFactHandle() );
+        assertEquals( h2, ( ( FactEntry ) index.getFirst().getNext() ).getFactHandle() );
+        assertEquals( h1, ( ( FactEntry ) index.getFirst().getNext().getNext() ).getFactHandle() );
+        
+        // test get
+        assertEquals( h1, index.get( h1 ).getFactHandle() );
+        assertEquals( h2, index.get( h2 ).getFactHandle() );
+        assertEquals( h3, index.get( h3 ).getFactHandle() );
+
+        // test removal for combinations
+        //remove first
+        index.remove( h3 );
+        assertEquals( h2, index.getFirst().getFactHandle() );
+        assertEquals( h1, ( ( FactEntry ) index.getFirst().getNext() ).getFactHandle() );
+        
+        index.add( h3 );
+        index.remove( h2 );
+        assertEquals( h3, index.getFirst().getFactHandle() );
+        assertEquals( h1, ( ( FactEntry ) index.getFirst().getNext() ).getFactHandle() );
+        
+        index.add( h2 );
+        index.remove( h1 );
+        assertEquals( h2, index.getFirst().getFactHandle() );
+        assertEquals( h3, ( ( FactEntry ) index.getFirst().getNext() ).getFactHandle() );        
+
+        index.remove( index.getFirst().getFactHandle() );
+        // check index type does not change, as this fact is removed
+        stilton2.setType( "cheddar" );
+        assertEquals( "stilton", index.getValue() );
+    }       
+}

Added: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexMapTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexMapTest.java	2006-09-17 13:14:00 UTC (rev 6255)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/util/FieldIndexMapTest.java	2006-09-17 19:23:21 UTC (rev 6256)
@@ -0,0 +1,313 @@
+package org.drools.util;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.drools.Cheese;
+import org.drools.base.ClassFieldExtractor;
+import org.drools.common.DefaultFactHandle;
+import org.drools.common.InternalFactHandle;
+
+public class FieldIndexMapTest extends TestCase {
+    
+    public void testSingleEntry() throws Exception {
+        ClassFieldExtractor extractor = new ClassFieldExtractor(Cheese.class, "type");
+        
+        FieldIndexMap map = new FieldIndexMap( extractor.getIndex(), extractor );
+        
+        assertEquals(0, map.size() );
+        
+        assertNull( map.get( "cheddar" ) );
+        
+        Cheese stilton1 = new Cheese("stilton", 35);
+        InternalFactHandle stiltonHandle1 = new DefaultFactHandle( 1, stilton1 );   
+        map.add( stiltonHandle1 );
+        
+        assertEquals(1, map.size() );        
+        assertEquals( 1, tablePopulationSize( map ) );
+        
+        FieldIndexEntry stiltonEntry = map.get( "stilton" );
+        assertSame( stiltonHandle1, stiltonEntry.getFirst().getFactHandle() );
+        assertNull( stiltonEntry.getFirst().getNext() );               
+    }
+    
+    public void testTwoDifferentEntries() throws Exception {
+        ClassFieldExtractor extractor = new ClassFieldExtractor(Cheese.class, "type");
+        
+        FieldIndexMap map = new FieldIndexMap( extractor.getIndex(), extractor );
+        
+        assertEquals(0, map.size() );
+        
+        Cheese stilton1 = new Cheese("stilton", 35);
+        InternalFactHandle stiltonHandle1 = new DefaultFactHandle( 1, stilton1 );   
+        map.add( stiltonHandle1 );                
+        
+        Cheese cheddar1 = new Cheese("cheddar", 35);
+        InternalFactHandle cheddarHandle1 = new DefaultFactHandle( 2, cheddar1 );   
+        map.add( cheddarHandle1 );        
+        
+        assertEquals(2, map.size() );      
+        assertEquals( 2, tablePopulationSize( map ) );
+        
+        FieldIndexEntry stiltonEntry = map.get( "stilton" );
+        assertSame( stiltonHandle1, stiltonEntry.getFirst().getFactHandle() );
+        assertNull( stiltonEntry.getFirst().getNext() );         
+        
+        FieldIndexEntry cheddarEntry = map.get( "cheddar" );
+        assertSame( cheddarHandle1, cheddarEntry.getFirst().getFactHandle() );
+        assertNull( cheddarEntry.getFirst().getNext() );                
+    }    
+    
+    public void testTwoEqualEntries() throws  Exception {
+        ClassFieldExtractor extractor = new ClassFieldExtractor(Cheese.class, "type");
+        
+        FieldIndexMap map = new FieldIndexMap( extractor.getIndex(), extractor );
+        
+        assertEquals(0, map.size() );
+        
+        Cheese stilton1 = new Cheese("stilton", 35);
+        InternalFactHandle stiltonHandle1 = new DefaultFactHandle( 1, stilton1 );   
+        map.add( stiltonHandle1 );                
+        
+        Cheese cheddar1 = new Cheese("cheddar", 35);
+        InternalFactHandle cheddarHandle1 = new DefaultFactHandle( 2, cheddar1 );   
+        map.add( cheddarHandle1 );           
+        
+        Cheese stilton2 = new Cheese("stilton", 81);
+        InternalFactHandle stiltonHandle2 = new DefaultFactHandle( 3, stilton2 );   
+        map.add( stiltonHandle2 );
+        
+        // Two siltons are in the same index bucket, so it won't increase the map size
+        assertEquals(2, map.size() );
+        assertEquals( 2, tablePopulationSize( map ) );
+        
+        // Check they are correctly chained to the same FieldIndexEntry
+        FieldIndexEntry stiltonEntry = map.get( "stilton" );
+        assertSame( stiltonHandle2, stiltonEntry.getFirst().getFactHandle() );
+        assertSame( stiltonHandle1, ((FactEntry)stiltonEntry.getFirst().getNext()).getFactHandle() );             
+    }      
+    
+    public void testTwoDifferentEntriesSameHashCode() throws Exception  {
+        ClassFieldExtractor extractor = new ClassFieldExtractor(TestClass.class, "object");
+        
+        FieldIndexMap map = new FieldIndexMap( extractor.getIndex(), extractor );
+        
+        TestClass c1 = new TestClass( 0, new TestClass( 20, "stilton" ) );
+        InternalFactHandle ch1 = new DefaultFactHandle( 1, c1 );
+        
+        map.add( ch1 );
+        
+        TestClass c2 = new TestClass( 0, new TestClass( 20, "cheddar" ) );
+        InternalFactHandle ch2 = new DefaultFactHandle( 2, c2 );
+        map.add( ch2 );
+        
+        // same hashcode, but different values, so it should result in  a size of 2
+        assertEquals(2, map.size() );
+        
+        // however both are in the same table bucket
+        assertEquals( 1, tablePopulationSize( map ) );
+        
+        
+        // this table bucket will have two FieldIndexEntries, as they are actually two different values
+        FieldIndexEntry entry = (FieldIndexEntry) getEntries( map )[0];
+        
+        assertEquals( c2.getObject(), entry.getValue());
+        assertEquals( c1.getObject(), ((FieldIndexEntry) entry.getNext()).getValue());                    
+    }   
+    
+    public void testRemove() throws Exception {
+        ClassFieldExtractor extractor = new ClassFieldExtractor(Cheese.class, "type");
+        
+        FieldIndexMap map = new FieldIndexMap( extractor.getIndex(), extractor );
+        
+        assertEquals(0, map.size() );
+        
+        Cheese stilton1 = new Cheese("stilton", 35);
+        InternalFactHandle stiltonHandle1 = new DefaultFactHandle( 1, stilton1 );   
+        map.add( stiltonHandle1 );                
+        
+        Cheese cheddar1 = new Cheese("cheddar", 35);
+        InternalFactHandle cheddarHandle1 = new DefaultFactHandle( 2, cheddar1 );   
+        map.add( cheddarHandle1 );           
+        
+        Cheese stilton2 = new Cheese("stilton", 81);
+        InternalFactHandle stiltonHandle2 = new DefaultFactHandle( 3, stilton2 );   
+        map.add( stiltonHandle2 );
+        
+        // Two siltons are in the same index bucket, so it won't increase the map size
+        assertEquals(2, map.size() );
+        assertEquals( 2, tablePopulationSize( map ) ); 
+        
+        // cheddar is in its own buccket, which should be removed once empty. We cannot have
+        // empty FieldIndexEntries in the Map, as they get their value  from the first FactEntry.
+        map.remove( cheddarHandle1 );
+        assertEquals( 1, map.size() );      
+        assertEquals( 1, tablePopulationSize( map ) );     
+        
+        // We remove t he stiltonHandle2, but there is still  one more stilton, so size  should be the same
+        map.remove( stiltonHandle2 );
+        assertEquals( 1, map.size() );      
+        assertEquals( 1, tablePopulationSize( map ) );   
+        
+        //  No more stiltons, so the table should be empty
+        map.remove( stiltonHandle1 );
+        assertEquals( 0, map.size() );      
+        assertEquals( 0, tablePopulationSize( map ) );           
+    }
+    
+    public void  testResize() throws Exception {
+        // use this  to access  the  map table
+        Field field = DroolsMap.class.getDeclaredField( "table" );
+        field.setAccessible( true );
+        
+        // This should  only resize when we have more than X different types of cheeses, not before.
+        ClassFieldExtractor extractor = new ClassFieldExtractor(Cheese.class, "type");
+        
+        FieldIndexMap map = new FieldIndexMap( extractor.getIndex(), extractor );
+        
+        assertEquals(0, map.size() );
+        
+        Cheese stilton1 = new Cheese("stilton", 35);   
+        map.add( new DefaultFactHandle( 1, stilton1 ) );                
+
+        Cheese stilton2 = new Cheese("stilton", 81);   
+        map.add( new DefaultFactHandle( 2, stilton2 ) );
+        
+        Cheese cheddar1 = new Cheese("cheddar", 35);   
+        map.add( new DefaultFactHandle( 3, cheddar1 ) );           
+        
+        Cheese cheddar2 = new Cheese("cheddar", 38);   
+        map.add( new DefaultFactHandle( 4, cheddar2 ) );
+        
+        Cheese brie = new Cheese("brie", 293);   
+        map.add( new DefaultFactHandle( 5, brie ) );        
+
+        Cheese mozerella = new Cheese("mozerella", 15);   
+        map.add( new DefaultFactHandle( 6, mozerella ) );
+        
+        Cheese dolcelatte = new Cheese("dolcelatte", 284);   
+        map.add( new DefaultFactHandle( 7, dolcelatte ) );
+        
+        Cheese camembert1 = new Cheese("camembert", 924);   
+        map.add( new DefaultFactHandle( 8, camembert1 ) );        
+
+        Cheese camembert2 = new Cheese("camembert", 765);   
+        map.add( new DefaultFactHandle( 9, camembert2 ) );
+        
+        Cheese redLeicestor = new Cheese("red leicestor", 23);   
+        map.add( new DefaultFactHandle( 10, redLeicestor ) );                
+        
+        Cheese wensleydale = new Cheese("wensleydale", 20);   
+        map.add( new DefaultFactHandle( 11, wensleydale ) );        
+
+        Cheese edam = new Cheese("edam", 12);   
+        map.add( new DefaultFactHandle( 12, edam ) );
+        
+        Cheese goude1 = new Cheese("goude", 93);   
+        map.add( new DefaultFactHandle( 13, goude1 ) );                  
+
+        Cheese goude2 = new Cheese("goude", 88);   
+        map.add( new DefaultFactHandle( 14, goude2 ) );            
+        
+        Cheese gruyere = new Cheese("gruyere", 82);   
+        map.add( new DefaultFactHandle( 15, gruyere ) );                  
+        
+        Cheese emmental = new Cheese("emmental", 98);   
+        map.add( new DefaultFactHandle( 16, emmental ) );           
+        
+        // At this point we have 16 facts but only 12 different types of cheeses
+        // so no table resize and thus its size is 16
+        
+        assertEquals( 12, map.size() );
+        
+        Entry[] table = (Entry[]) field.get( map );
+        assertEquals( 16, table.length);           
+        
+        Cheese feta = new Cheese("feta", 48);   
+        map.add( new DefaultFactHandle( 2, feta ) );
+        
+        // This adds our 13th type of cheese. The map is set with an initial capacity of 16 and
+        // a threshold of 75%, that after 12 it should resize the map to 32.
+        assertEquals( 13, map.size() );
+        
+        table = (Entry[]) field.get( map );
+        assertEquals( 32, table.length);  
+        
+        Cheese haloumi = new Cheese("haloumi", 48);   
+        map.add( new DefaultFactHandle( 2, haloumi ) );
+        
+        Cheese chevre = new Cheese("chevre", 48);   
+        map.add( new DefaultFactHandle( 2, chevre ) );    
+                                                
+    }
+    
+    public static class TestClass {
+        private int hashCode;
+        private Object object;
+        
+        public TestClass(){
+            
+        }
+        
+        public TestClass(int hashCode,
+                         Object object) {
+            this.hashCode = hashCode;
+            this.object = object;
+        }
+        
+        public Object getObject() {
+            return this.object;
+        }
+        public void setObject(Object object) {
+            this.object = object;
+        }
+        public void setHashCode(int hashCode) {
+            this.hashCode = hashCode;
+        }
+        public int hashCode() {
+            return this.hashCode;
+        }
+        public boolean equals(Object obj) {
+            if ( this == obj ) return true;
+            if ( obj == null ) return false;
+            if ( getClass() != obj.getClass() ) return false;
+            final TestClass other = (TestClass) obj;
+
+            if ( this.object == null ) {
+                if ( other.object != null ) return false;
+            } else if ( !this.object.equals( other.object ) ) return false;
+            return true;
+        }                        
+    }
+    
+    private int tablePopulationSize(DroolsMap map) throws Exception {
+        Field field = DroolsMap.class.getDeclaredField( "table" );
+        field.setAccessible( true );
+        Entry[] array = (Entry[]) field.get( map );
+        int size = 0;
+        for ( int i = 0, length = array.length; i  < length; i++  ) {
+            if  ( array[i]  != null ) {
+                size++;
+            }
+        }
+        return size;
+    }
+    
+    private Entry[] getEntries(DroolsMap map) throws Exception {
+        Field field = DroolsMap.class.getDeclaredField( "table" );
+        field.setAccessible( true );
+        List list = new ArrayList();
+        
+        Entry[] array = (Entry[]) field.get( map );
+        for ( int i = 0, length = array.length; i  < length; i++  ) {
+            if ( array[i] != null ) {
+                list.add( array[i]);
+            }
+        }
+        return ( Entry[] ) list.toArray( new Entry[ list.size() ] );
+    }    
+    
+}




More information about the jboss-svn-commits mailing list