<commit_before>using System;
using System.Collections.Generic;
using System.Reflection;

namespace Machine.MassTransitExtensions
{
  public class MessageEndpointLookup : IMessageEndpointLookup 
  {
    private readonly Dictionary<Type, List<EndpointName>> _map = new Dictionary<Type, List<EndpointName>>();
    private readonly List<EndpointName> _catchAlls = new List<EndpointName>();

    public ICollection<EndpointName> LookupEndpointFor(Type messageType)
    {
      List<EndpointName> destinations = new List<EndpointName>(_catchAlls);
      if (_map.ContainsKey(messageType))
      {
        destinations.AddRange(_map[messageType]);
      }
      if (destinations.Count == 0)
      {
        throw new InvalidOperationException("No endpoints for: " + messageType);
      }
      return destinations;
    }

    public void SendMessageTypeTo(Type messageType, EndpointName destination)
    {
      if (!_map.ContainsKey(messageType))
      {
        _map[messageType] = new List<EndpointName>();
      }
      _map[messageType].Add(destination);
    }

    public void SendMessageTypeTo<T>(EndpointName destination)
    {
      SendMessageTypeTo(typeof(T), destination);
    }

    public void SendAllFromAssemblyTo<T>(Assembly assembly, EndpointName destination)
    {
      foreach (Type type in assembly.GetTypes())
      {
        if (typeof(T).IsAssignableFrom(type))
        {
          SendMessageTypeTo(type, destination);
        }
      }
    }
    
    public void SendAllTo(EndpointName destination)
    {
      _catchAlls.Add(destination);
    }
  }
}<commit_msg>Remove duplicates from Endpoint mappings.<commit_after>using System;
using System.Collections.Generic;
using System.Reflection;

namespace Machine.MassTransitExtensions
{
  public class MessageEndpointLookup : IMessageEndpointLookup 
  {
    private readonly Dictionary<Type, List<EndpointName>> _map = new Dictionary<Type, List<EndpointName>>();
    private readonly List<EndpointName> _catchAlls = new List<EndpointName>();

    public ICollection<EndpointName> LookupEndpointFor(Type messageType)
    {
      List<EndpointName> destinations = new List<EndpointName>(_catchAlls);
      if (_map.ContainsKey(messageType))
      {
        foreach (EndpointName endpointName in destinations)
        {
          if (!destinations.Contains(endpointName))
          {
            destinations.Add(endpointName);
          }
        }
      }
      if (destinations.Count == 0)
      {
        throw new InvalidOperationException("No endpoints for: " + messageType);
      }
      return destinations;
    }

    public void SendMessageTypeTo(Type messageType, EndpointName destination)
    {
      if (!_map.ContainsKey(messageType))
      {
        _map[messageType] = new List<EndpointName>();
      }
      if (!_map[messageType].Contains(destination))
      {
        _map[messageType].Add(destination);
      }
    }

    public void SendMessageTypeTo<T>(EndpointName destination)
    {
      SendMessageTypeTo(typeof(T), destination);
    }

    public void SendAllFromAssemblyTo<T>(Assembly assembly, EndpointName destination)
    {
      foreach (Type type in assembly.GetTypes())
      {
        if (typeof(T).IsAssignableFrom(type))
        {
          SendMessageTypeTo(type, destination);
        }
      }
    }
    
    public void SendAllTo(EndpointName destination)
    {
      if (!_catchAlls.Contains(destination))
      {
        _catchAlls.Add(destination);
      }
    }
  }
}
{'fraction_non_alphanumeric': 0.09634742594190394, 'fraction_numerical': 0.0005752085130859936, 'mean_word_length': 2.9794050343249427, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 27, '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': '3752414', 'n_tokens_mistral': 955, 'n_tokens_neox': 931, 'n_words': 187}