Search in sources :

Example 6 with ObjectEntry

use of org.drools.core.util.ObjectHashMap.ObjectEntry in project drools by kiegroup.

the class ObjectHashMapTest method testEmptyIterator.

@Test
public void testEmptyIterator() {
    final ObjectHashMap map = new ObjectHashMap();
    final Iterator it = map.iterator();
    for (ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next()) {
        fail("Map is empty, there should be no iteration");
    }
}
Also used : ObjectEntry(org.drools.core.util.ObjectHashMap.ObjectEntry) Test(org.junit.Test)

Example 7 with ObjectEntry

use of org.drools.core.util.ObjectHashMap.ObjectEntry in project drools by kiegroup.

the class CompositeObjectSinkAdapter method getSinks.

public ObjectSink[] getSinks() {
    if (this.sinks != null) {
        return sinks;
    }
    ObjectSink[] sinks = new ObjectSink[size()];
    int at = 0;
    if (this.hashedFieldIndexes != null) {
        // Iterate the FieldIndexes to see if any are hashed
        for (FieldIndex fieldIndex = this.hashedFieldIndexes.getFirst(); fieldIndex != null; fieldIndex = fieldIndex.getNext()) {
            if (!fieldIndex.isHashed()) {
                continue;
            }
            // this field is hashed so set the existing hashKey and see if there is a sink for it
            final int index = fieldIndex.getIndex();
            final Iterator it = this.hashedSinkMap.newIterator();
            for (ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next()) {
                HashKey hashKey = (HashKey) entry.getKey();
                if (hashKey.getIndex() == index) {
                    sinks[at++] = (ObjectSink) entry.getValue();
                }
            }
        }
    }
    if (this.hashableSinks != null) {
        for (ObjectSinkNode sink = this.hashableSinks.getFirst(); sink != null; sink = sink.getNextObjectSinkNode()) {
            sinks[at++] = sink;
        }
    }
    if (this.otherSinks != null) {
        for (ObjectSinkNode sink = this.otherSinks.getFirst(); sink != null; sink = sink.getNextObjectSinkNode()) {
            sinks[at++] = sink;
        }
    }
    this.sinks = sinks;
    return sinks;
}
Also used : Iterator(org.drools.core.util.Iterator) ObjectEntry(org.drools.core.util.ObjectHashMap.ObjectEntry) AlphaNodeFieldConstraint(org.drools.core.spi.AlphaNodeFieldConstraint) IndexableConstraint(org.drools.core.rule.IndexableConstraint)

Example 8 with ObjectEntry

use of org.drools.core.util.ObjectHashMap.ObjectEntry in project drools by kiegroup.

the class CompositeObjectSinkAdapter method reIndexNodes.

public void reIndexNodes() {
    sinksMap = new HashMap<>();
    if (this.otherSinks != null) {
        for (ObjectSinkNode sink = this.otherSinks.getFirst(); sink != null; sink = sink.getNextObjectSinkNode()) {
            sinksMap.put(sink, sink);
        }
    }
    if (this.hashableSinks != null) {
        for (ObjectSinkNode sink = this.hashableSinks.getFirst(); sink != null; sink = sink.getNextObjectSinkNode()) {
            sinksMap.put(sink, sink);
        }
    }
    if (this.hashedSinkMap != null) {
        final Iterator it = this.hashedSinkMap.newIterator();
        for (ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next()) {
            final ObjectSink sink = (ObjectSink) entry.getValue();
            sinksMap.put(sink, sink);
        }
    }
}
Also used : Iterator(org.drools.core.util.Iterator) ObjectEntry(org.drools.core.util.ObjectHashMap.ObjectEntry)

Example 9 with ObjectEntry

use of org.drools.core.util.ObjectHashMap.ObjectEntry in project drools by kiegroup.

the class JavaIteratorAdapter method setNext.

private void setNext() {
    ObjectEntry entry = null;
    while (entry == null) {
        entry = (ObjectEntry) this.iterator.next();
        if (entry == null) {
            break;
        }
        if (this.filter != null) {
            Object object = ((InternalFactHandle) entry.getKey()).getObject();
            if (this.filter.accept(object) == false) {
                entry = null;
            }
        }
    }
    this.nextEntry = entry;
// this.nextHandle = handle;
// this.nextObject = object;
}
Also used : ObjectEntry(org.drools.core.util.ObjectHashMap.ObjectEntry) InternalFactHandle(org.drools.core.common.InternalFactHandle)

Example 10 with ObjectEntry

use of org.drools.core.util.ObjectHashMap.ObjectEntry in project drools by kiegroup.

the class ObjectHashSet method contains.

public boolean contains(final Object value) {
    final int hashCode = this.comparator.hashCodeOf(value);
    final int index = indexOf(hashCode, this.table.length);
    ObjectEntry current = (ObjectEntry) this.table[index];
    while (current != null) {
        if (hashCode == current.cachedHashCode && this.comparator.equal(value, current.value)) {
            return true;
        }
        current = (ObjectEntry) current.getNext();
    }
    return false;
}
Also used : ObjectEntry(org.drools.core.util.ObjectHashMap.ObjectEntry)

Aggregations

ObjectEntry (org.drools.core.util.ObjectHashMap.ObjectEntry)11 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 EqualityKey (org.drools.core.common.EqualityKey)3 NamedEntryPoint (org.drools.core.common.NamedEntryPoint)3 ObjectHashMap (org.drools.core.util.ObjectHashMap)3 Ignore (org.junit.Ignore)3 KieSession (org.kie.api.runtime.KieSession)3 FactHandle (org.kie.api.runtime.rule.FactHandle)3 Person (org.drools.compiler.Person)2 Iterator (org.drools.core.util.Iterator)2 InternalFactHandle (org.drools.core.common.InternalFactHandle)1 IndexableConstraint (org.drools.core.rule.IndexableConstraint)1 AlphaNodeFieldConstraint (org.drools.core.spi.AlphaNodeFieldConstraint)1 Match (org.kie.api.runtime.rule.Match)1 RuleEventListener (org.kie.internal.event.rule.RuleEventListener)1 RuleEventManager (org.kie.internal.event.rule.RuleEventManager)1