Search in sources :

Example 6 with SingleIndex

use of org.drools.core.util.AbstractHashTable.SingleIndex in project drools by kiegroup.

the class FieldIndexEntryTest method testSingleEntry.

@Test
public void testSingleEntry() {
    final ClassFieldReader extractor = store.getReader(Cheese.class, "type");
    final FieldIndex fieldIndex = new FieldIndex(extractor, new Declaration("id", extractor, null));
    final SingleIndex singleIndex = new SingleIndex(new FieldIndex[] { fieldIndex }, 1);
    Tuple tuple = new RightTupleImpl(new DefaultFactHandle(1, new Cheese("stilton", 10)));
    final TupleList index = new AbstractHashTable.IndexTupleList(singleIndex, new AbstractHashTable.SingleHashEntry("stilton".hashCode(), "stilton"));
    // Test initial construction
    assertNull(index.getFirst());
    final Cheese stilton1 = new Cheese("stilton", 35);
    final InternalFactHandle h1 = new DefaultFactHandle(1, stilton1);
    // test add
    RightTuple h1RightTuple = new RightTupleImpl(h1, null);
    index.add(h1RightTuple);
    final Tuple entry1 = index.getFirst();
    assertSame(h1, entry1.getFactHandle());
    assertNull(entry1.getNext());
    assertSame(entry1, index.get(h1));
    // test get
    final Tuple entry2 = index.get(new RightTupleImpl(h1, null));
    assertSame(entry1, entry2);
    // test remove
    index.remove(h1RightTuple);
    assertNull(index.getFirst());
}
Also used : FieldIndex(org.drools.core.util.AbstractHashTable.FieldIndex) Cheese(org.drools.core.test.model.Cheese) RightTupleImpl(org.drools.core.reteoo.RightTupleImpl) RightTuple(org.drools.core.reteoo.RightTuple) TupleList(org.drools.core.util.index.TupleList) SingleIndex(org.drools.core.util.AbstractHashTable.SingleIndex) DefaultFactHandle(org.drools.core.common.DefaultFactHandle) AbstractHashTable(org.drools.core.util.AbstractHashTable) ClassFieldReader(org.drools.mvel.accessors.ClassFieldReader) Declaration(org.drools.core.rule.Declaration) InternalFactHandle(org.drools.core.common.InternalFactHandle) RightTuple(org.drools.core.reteoo.RightTuple) Tuple(org.drools.core.spi.Tuple) Test(org.junit.Test)

Aggregations

DefaultFactHandle (org.drools.core.common.DefaultFactHandle)6 InternalFactHandle (org.drools.core.common.InternalFactHandle)6 RightTuple (org.drools.core.reteoo.RightTuple)6 RightTupleImpl (org.drools.core.reteoo.RightTupleImpl)6 Tuple (org.drools.core.spi.Tuple)6 Cheese (org.drools.core.test.model.Cheese)6 FieldIndex (org.drools.core.util.AbstractHashTable.FieldIndex)6 SingleIndex (org.drools.core.util.AbstractHashTable.SingleIndex)6 TupleList (org.drools.core.util.index.TupleList)6 Test (org.junit.Test)6 ClassFieldReader (org.drools.core.base.ClassFieldReader)3 Declaration (org.drools.core.rule.Declaration)3 AbstractHashTable (org.drools.core.util.AbstractHashTable)3 ClassFieldReader (org.drools.mvel.accessors.ClassFieldReader)3