Search in sources :

Example 31 with Iterator

use of org.drools.core.util.Iterator 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 32 with Iterator

use of org.drools.core.util.Iterator in project drools by kiegroup.

the class CompositeObjectSinkAdapter method unHashSinks.

void unHashSinks(final FieldIndex fieldIndex) {
    final int index = fieldIndex.getIndex();
    // this is the list of sinks that need to be removed from the hashedSinkMap
    final List<HashKey> unhashedSinks = new ArrayList<HashKey>();
    final Iterator iter = this.hashedSinkMap.newIterator();
    ObjectHashMap.ObjectEntry entry = (ObjectHashMap.ObjectEntry) iter.next();
    while (entry != null) {
        final AlphaNode alphaNode = (AlphaNode) entry.getValue();
        final IndexableConstraint indexableConstraint = (IndexableConstraint) alphaNode.getConstraint();
        // the right field index
        if (index == indexableConstraint.getFieldExtractor().getIndex()) {
            final FieldValue value = indexableConstraint.getField();
            if (this.hashableSinks == null) {
                this.hashableSinks = new ObjectSinkNodeList();
            }
            this.hashableSinks.add(alphaNode);
            unhashedSinks.add(new HashKey(index, value, fieldIndex.getFieldExtractor()));
        }
        entry = (ObjectHashMap.ObjectEntry) iter.next();
    }
    for (HashKey hashKey : unhashedSinks) {
        this.hashedSinkMap.remove(hashKey);
    }
    if (this.hashedSinkMap.isEmpty()) {
        this.hashedSinkMap = null;
    }
    fieldIndex.setHashed(false);
}
Also used : IndexableConstraint(org.drools.core.rule.IndexableConstraint) ArrayList(java.util.ArrayList) Iterator(org.drools.core.util.Iterator) ObjectHashMap(org.drools.core.util.ObjectHashMap) ObjectEntry(org.drools.core.util.ObjectHashMap.ObjectEntry) FieldValue(org.drools.core.spi.FieldValue) AlphaNodeFieldConstraint(org.drools.core.spi.AlphaNodeFieldConstraint) IndexableConstraint(org.drools.core.rule.IndexableConstraint) ObjectEntry(org.drools.core.util.ObjectHashMap.ObjectEntry)

Example 33 with Iterator

use of org.drools.core.util.Iterator 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)

Aggregations

Iterator (org.drools.core.util.Iterator)33 Test (org.junit.Test)24 KieSession (org.kie.api.runtime.KieSession)23 ArrayList (java.util.ArrayList)19 List (java.util.List)13 AgendaItem (org.drools.core.common.AgendaItem)13 ObjectHashMap (org.drools.core.util.ObjectHashMap)13 KieHelper (org.kie.internal.utils.KieHelper)13 ActivationIterator (org.drools.core.common.ActivationIterator)12 EqualityKey (org.drools.core.common.EqualityKey)10 NamedEntryPoint (org.drools.core.common.NamedEntryPoint)10 TruthMaintenanceSystem (org.drools.core.common.TruthMaintenanceSystem)10 FactType (org.kie.api.definition.type.FactType)10 Tuple (org.drools.core.spi.Tuple)4 FastIterator (org.drools.core.util.FastIterator)4 InternalFactHandle (org.drools.core.common.InternalFactHandle)3 ObjectEntry (org.drools.core.util.ObjectHashMap.ObjectEntry)3 FactHandle (org.kie.api.runtime.rule.FactHandle)3 AccumulateNode (org.drools.core.reteoo.AccumulateNode)2 AccumulateContext (org.drools.core.reteoo.AccumulateNode.AccumulateContext)2