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;
}
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);
}
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);
}
}
}
Aggregations