use of org.drools.core.util.Entry in project drools by kiegroup.
the class TupleIndexHashTable method toArray.
@Override
public Tuple[] toArray() {
Tuple[] result = new Tuple[this.factSize];
int index = 0;
for (Entry aTable : this.table) {
TupleList bucket = (TupleList) aTable;
while (bucket != null) {
Tuple entry = bucket.getFirst();
while (entry != null) {
result[index++] = entry;
entry = entry.getNext();
}
bucket = bucket.getNext();
}
}
return result;
}
use of org.drools.core.util.Entry in project drools by kiegroup.
the class TupleIndexRBTree method toArray.
public Entry[] toArray() {
FastIterator it = tree.fastIterator();
if (it == null) {
return new Entry[0];
}
List<Comparable> toBeRemoved = new ArrayList<Comparable>();
List<Tuple> result = new ArrayList<Tuple>();
TupleList list = null;
while ((list = (TupleList) it.next(list)) != null) {
Tuple entry = list.getFirst();
while (entry != null) {
result.add(entry);
entry = (Tuple) entry.getNext();
}
}
return result.toArray(new Tuple[result.size()]);
}
use of org.drools.core.util.Entry in project drools by kiegroup.
the class RightTupleIndexHashTableTest method getEntries.
private Entry[] getEntries(final AbstractHashTable map) throws Exception {
final Field field = AbstractHashTable.class.getDeclaredField("table");
field.setAccessible(true);
final List list = new ArrayList();
final 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()]);
}
use of org.drools.core.util.Entry in project drools by kiegroup.
the class RightTupleIndexHashTableTest method testTwoDifferentEntriesSameHashCode.
@Test
public void testTwoDifferentEntriesSameHashCode() throws Exception {
final InternalReadAccessor extractor = store.getReader(TestClass.class, "object");
final Pattern pattern = new Pattern(0, new ClassObjectType(TestClass.class));
final Declaration declaration = new Declaration("theObject", extractor, pattern);
final FieldIndex fieldIndex = new FieldIndex(extractor, declaration);
final TupleIndexHashTable map = new TupleIndexHashTable(new FieldIndex[] { fieldIndex }, false);
final TestClass c1 = new TestClass(0, new TestClass(20, "stilton"));
final InternalFactHandle ch1 = new DefaultFactHandle(1, c1);
map.add(new RightTupleImpl(ch1, null));
final TestClass c2 = new TestClass(0, new TestClass(20, "cheddar"));
final InternalFactHandle ch2 = new DefaultFactHandle(2, c2);
map.add(new RightTupleImpl(ch2, null));
// 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
Entry[] entries = getEntries(map);
assertEquals(1, entries.length);
TupleList list = (TupleList) entries[0];
assertSame(ch2, list.getFirst().getFactHandle());
assertNull(list.getFirst().getNext());
assertSame(ch1, list.getNext().getFirst().getFactHandle());
assertNull(list.getNext().getFirst().getNext());
assertNull(list.getNext().getNext());
}
use of org.drools.core.util.Entry in project drools by kiegroup.
the class BaseTupleIndexHashTableIteratorTest method createTableIndexListForAssertion.
protected List createTableIndexListForAssertion(TupleIndexHashTable hashTable) {
Entry[] table = hashTable.getTable();
List list = new ArrayList();
for (int i = 0; i < table.length; i++) {
if (table[i] != null) {
List entries = new ArrayList();
entries.add(i);
Entry entry = table[i];
while (entry != null) {
entries.add(entry);
entry = entry.getNext();
}
list.add(entries.toArray());
}
}
return list;
}
Aggregations