<commit_before>package teetime.stage;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import teetime.framework.AbstractConsumerStage;
import teetime.framework.OutputPort;

/**
 * @author <NAME>
 */
public final class MultipleInstanceOfFilter<I> extends AbstractConsumerStage<I> {

	private final Map<Class<? extends I>, OutputPort<? super I>> outputPortsMap = new HashMap<Class<? extends I>, OutputPort<? super I>>();

	@SuppressWarnings("unchecked")
	public <T extends I> OutputPort<T> getOutputPortForType(final Class<T> clazz) {
		if (!this.outputPortsMap.containsKey(clazz)) {
			this.outputPortsMap.put(clazz, super.createOutputPort());
		}
		return (OutputPort<T>) this.outputPortsMap.get(clazz);
	}

	@Override
	protected void execute(final I element) {
		for (Entry<Class<? extends I>, OutputPort<? super I>> outputPortMapEntry : outputPortsMap.entrySet()) {
			if (outputPortMapEntry.getKey().isInstance(element)) {
				outputPortMapEntry.getValue().send(element);
			}
		}
	}

}<commit_msg>Modifications for performance reasons<commit_after>package teetime.stage;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import teetime.framework.AbstractConsumerStage;
import teetime.framework.OutputPort;

/**
 * @author <NAME>
 */
public final class MultipleInstanceOfFilter<I> extends AbstractConsumerStage<I> {

	private final Map<Class<? extends I>, OutputPort<? super I>> outputPortsMap = new HashMap<Class<? extends I>, OutputPort<? super I>>();
	private Entry<Class<? extends I>, OutputPort<? super I>>[] cachedOutputPortsMap;

	@SuppressWarnings("unchecked")
	public <T extends I> OutputPort<T> getOutputPortForType(final Class<T> clazz) {
		if (!this.outputPortsMap.containsKey(clazz)) {
			this.outputPortsMap.put(clazz, super.createOutputPort());
		}
		return (OutputPort<T>) this.outputPortsMap.get(clazz);
	}

	@Override
	@SuppressWarnings("unchecked")
	public void onStarting() throws Exception {
		super.onStarting();

		// We cache the map to avoid the creating of iterators during runtime
		cachedOutputPortsMap = (Entry<Class<? extends I>, OutputPort<? super I>>[]) outputPortsMap.entrySet().toArray(new Entry<?, ?>[outputPortsMap.size()]);
	}

	@Override
	protected void execute(final I element) {
		for (Entry<Class<? extends I>, OutputPort<? super I>> outputPortMapEntry : cachedOutputPortsMap) {
			if (outputPortMapEntry.getKey().isInstance(element)) {
				outputPortMapEntry.getValue().send(element);
			}
		}
	}
}
{'fraction_non_alphanumeric': 0.1336, 'fraction_numerical': 0.0, 'mean_word_length': 5.852054794520548, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 42, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '134578', 'n_tokens_mistral': 807, 'n_tokens_neox': 772, 'n_words': 181}