<commit_before>package org.drools.reteoo;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
import org.drools.spi.PropagationContext;
import org.drools.util.LinkedList;
import org.drools.util.LinkedListNode;
import org.drools.util.LinkedListObjectWrapper;

public class CompositeTupleSinkAdapter implements TupleSinkPropagator {
    private TupleSinkNodeList sinks;
    
    public CompositeTupleSinkAdapter() {
        this.sinks = new TupleSinkNodeList();
    }
    
    public void addTupleSink(TupleSink sink) {
        this.sinks.add( (TupleSinkNode) sink );
    }

    public void removeTupleSink(TupleSink sink) {
        this.sinks.remove( (TupleSinkNode) sink );
    }        
    
    public void propagateAssertTuple(ReteTuple tuple,
                                     InternalFactHandle handle,
                                     TupleMatch tupleMatch,
                                     PropagationContext context,
                                     InternalWorkingMemory workingMemory) {
        ReteTuple joined = new ReteTuple(tuple, handle, (TupleSink) sinks.getFirst() );
        tupleMatch.addJoinedTuple( joined );
        joined.assertTuple( context, workingMemory );           
        
        for ( TupleSinkNode sink = this.sinks.getFirst(); sink != null; sink = sink.getNextTupleSinkNode() ) {
            ReteTuple cloned = new ReteTuple(tuple, sink);
            tupleMatch.addJoinedTuple( cloned );
            joined.assertTuple( context, workingMemory );                
        }
    }
    
    public void propagateAssertTuple(ReteTuple tuple,
                                     PropagationContext context,
                                     InternalWorkingMemory workingMemory) {        
        for ( TupleSinkNode sink = this.sinks.getFirst(); sink != null; sink = sink.getNextTupleSinkNode() ) {
            final ReteTuple child = new ReteTuple( tuple, sink );
            // no TupleMatch so instead add as a linked tuple
            tuple.addLinkedTuple( new LinkedListObjectWrapper( child ) );
            child.assertTuple( context, workingMemory );            <commit_msg>JBRULES-484 refactor the core reteoo code for sinle and composite propagations -fixed bad iteration<commit_after>package org.drools.reteoo;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.drools.common.InternalFactHandle;
import org.drools.common.InternalWorkingMemory;
import org.drools.spi.PropagationContext;
import org.drools.util.LinkedList;
import org.drools.util.LinkedListNode;
import org.drools.util.LinkedListObjectWrapper;

public class CompositeTupleSinkAdapter implements TupleSinkPropagator {
    private TupleSinkNodeList sinks;
    
    public CompositeTupleSinkAdapter() {
        this.sinks = new TupleSinkNodeList();
    }
    
    public void addTupleSink(TupleSink sink) {
        this.sinks.add( (TupleSinkNode) sink );
    }

    public void removeTupleSink(TupleSink sink) {
        this.sinks.remove( (TupleSinkNode) sink );
    }        
    
    public void propagateAssertTuple(ReteTuple tuple,
                                     InternalFactHandle handle,
                                     TupleMatch tupleMatch,
                                     PropagationContext context,
                                     InternalWorkingMemory workingMemory) {
        TupleSinkNode sink = this.sinks.getFirst();
        ReteTuple joined = new ReteTuple(tuple, handle, (TupleSink) sink );
        tupleMatch.addJoinedTuple( joined );
        joined.assertTuple( context, workingMemory );           
        
        for ( sink = sink.getNextTupleSinkNode();sink != null; sink = sink.getNextTupleSinkNode() ) {
            ReteTuple cloned = new ReteTuple(tuple, sink);
            tupleMatch.addJoinedTuple( cloned );
            joined.assertTuple( context, workingMemory );                
        }
    }
    
    public void propagateAssertTuple(ReteTuple tuple,
                                     PropagationContext context,
                                     InternalWorkingMemory workingMemory) {        
        for ( TupleSinkNode sink = this.sinks.getFirst(); sink != null; sink = sink.getNextTupleSinkNode() ) {
            final ReteTuple child = new ReteTuple( tuple, sink );
            // no TupleMatch so instead add as a linked tuple
            tuple.addLinkedTuple( new LinkedListObjectWrapper( child ) );
            child.assertTuple( context, workingMemory );            
{'fraction_non_alphanumeric': 0.07509118214975327, 'fraction_numerical': 0.0006436387041407423, 'mean_word_length': 2.1714285714285713, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '420724', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1205, 'n_words': 274}