<commit_before>package com.atlassian.jira.plugins.dvcs.spi.github.service.impl;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.atlassian.jira.plugins.dvcs.spi.github.service.GitHubEventContext;
import org.eclipse.egit.github.core.event.Event;
import org.eclipse.egit.github.core.event.EventPayload;

import com.atlassian.jira.plugins.dvcs.model.Repository;
import com.atlassian.jira.plugins.dvcs.spi.github.service.GitHubEventProcessor;
import com.atlassian.jira.plugins.dvcs.spi.github.service.GitHubEventProcessorAggregator;

/**
 * Aggregator over all {@link GitHubEventProcessor}s.
 * 
 * @author <NAME>
 * 
 */
public class GitHubEventProcessorAggregatorImpl implements GitHubEventProcessorAggregator<EventPayload>
{
    /**
     * Cache of the already resolved processors. The synchronization is done via direct object locking.
     */
    private final Map<Class<? extends EventPayload>, GitHubEventProcessor<? extends EventPayload>> resolvedProcessorCache = new ConcurrentHashMap<Class<? extends EventPayload>, GitHubEventProcessor<? extends EventPayload>>();

    /**
     * Constructor.
     * 
     * @param eventProcessors
     *            available event processor
     */
    public GitHubEventProcessorAggregatorImpl(GitHubEventProcessor<? extends EventPayload>... eventProcessors)
    {
        for (GitHubEventProcessor<? extends EventPayload> eventProcessor : eventProcessors)
        {
            resolvedProcessorCache.put(eventProcessor.getEventPayloadType(), eventProcessor);
        }
    }

    /**
     * Resolves the most concrete {@link Event} processor for the provider type of the {@link EventPayload} type.
     * 
     * @param eventPayloadType
     * @return
     */
    @SuppressWarnings("unchecked")
    private <T_EventPayload extends EventPayload> GitHubEventProcessor<T_EventPayload> resolveEventProcessor(
            Class<? extends T_EventPayload> eventPayloadType)
    {
        // try resolve the event processor from cache
        GitHubEventProcessor<T_EventPayload> result = (GitHubEventProcessor<T_EventPayload>) resolvedProcessorCache.get(eventPayloadType);
        if (result != null)
        {
            return result;
        }

        // if no handler was found for this type, check super EventType
        if (EventPayload.class.isAssignableFrom(eventPayloadType.getSuperclass()))
        {
            result = resolveEventProcessor((Class<? extends T_EventPayload>) eventPayloadType.getSuperclass());
            resolvedProcessorCache.put(eventPayloadType, result);
            return result;
        }

        // by default there is no event processor - it means null
        return null;
    }<commit_msg>BBC-768 Reflecting pull request comments<commit_after>package com.atlassian.jira.plugins.dvcs.spi.github.service.impl;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import com.atlassian.jira.plugins.dvcs.spi.github.service.GitHubEventContext;
import org.eclipse.egit.github.core.event.Event;
import org.eclipse.egit.github.core.event.EventPayload;

import com.atlassian.jira.plugins.dvcs.model.Repository;
import com.atlassian.jira.plugins.dvcs.spi.github.service.GitHubEventProcessor;
import com.atlassian.jira.plugins.dvcs.spi.github.service.GitHubEventProcessorAggregator;

/**
 * Aggregator over all {@link GitHubEventProcessor}s.
 * 
 * @author <NAME>
 * 
 */
public class GitHubEventProcessorAggregatorImpl implements GitHubEventProcessorAggregator<EventPayload>
{
    /**
     * Cache of the already resolved processors. The synchronization is done via direct object locking.
     */
    private final Map<Class<? extends EventPayload>, GitHubEventProcessor<? extends EventPayload>> eventProcessorsMapping = new ConcurrentHashMap<Class<? extends EventPayload>, GitHubEventProcessor<? extends EventPayload>>();

    /**
     * Constructor.
     * 
     * @param eventProcessors
     *            available event processor
     */
    public GitHubEventProcessorAggregatorImpl(GitHubEventProcessor<? extends EventPayload>... eventProcessors)
    {
        for (GitHubEventProcessor<? extends EventPayload> eventProcessor : eventProcessors)
        {
            eventProcessorsMapping.put(eventProcessor.getEventPayloadType(), eventProcessor);
        }
    }

    /**
     * Resolves the most concrete {@link Event} processor for the provider type of the {@link EventPayload} type.
     * 
     * @param eventPayloadType
     * @return
     */
    @SuppressWarnings("unchecked")
    private <T_EventPayload extends EventPayload> GitHubEventProcessor<T_EventPayload> resolveEventProcessor(
            Class<? extends T_EventPayload> eventPayloadType)
    {
        // try resolve the event processor from cache
        GitHubEventProcessor<T_EventPayload> result = (GitHubEventProcessor<T_EventPayload>) eventProcessorsMapping.get(eventPayloadType);
        if (result != null)
        {
            return result;
        }

        // if no handler was found for this type, check super EventType
        if (EventPayload.class.isAssignableFrom(eventPayloadType.getSuperclass()))
        {
            result = resolveEventProcessor((Class<? extends T_EventPayload>) eventPayloadType.getSuperclass());
            eventProcessorsMapping.put(eventPayloadType, result);
            return result;
        }

        // by default there is no event processor - it means null
        return null;
    }
{'fraction_non_alphanumeric': 0.08963740106755015, 'fraction_numerical': 0.0005521811154058532, 'mean_word_length': 3.498344370860927, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 35, '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': '2899582', 'n_tokens_mistral': 1444, 'n_tokens_neox': 1407, 'n_words': 322}