<commit_before>﻿using System;
using System.Collections.Generic;
using UnityEngine;

namespace Archon.SwissArmyLib.Events
{
    public static class EventSystem
    {
        private static readonly Dictionary<int, List<IEventListener>> EventListeners = new Dictionary<int, List<IEventListener>>();

        public static void Invoke(int eventId)
        {
            List<IEventListener> listeners;
            if (EventListeners.TryGetValue(eventId, out listeners))
            {
                for (var i = 0; i < listeners.Count; i++)
                {
                    // gotta wrap it up so one guy doesn't spoil it for everyone
                    try
                    {
                        listeners[i].OnEvent(eventId);
                    }
                    catch (Exception e)
                    {
                        Debug.LogError(e.Message);
                    }
                }
            }
        }

        public static void AddListener(int eventId, IEventListener listener)
        {
            List<IEventListener> listeners;
            if (!EventListeners.TryGetValue(eventId, out listeners))
                EventListeners[eventId] = listeners = new List<IEventListener>();

            listeners.Add(listener);
        }

        public static void RemoveListener(int eventId, IEventListener listener)
        {
            List<IEventListener> listeners;
            if (EventListeners.TryGetValue(eventId, out listeners))
                listeners.Remove(listener);
        }
    }

    public static class EventSystem<T>
    {
        private static readonly Dictionary<int, List<IEventListener<T>>> EventListeners = new Dictionary<int, List<IEventListener<T>>>();

        public static void Invoke(int eventId, T args)
        {
            List<IEventListener<T>> listeners;
            if (EventListeners.TryGetValue(eventId, out listeners))
            {
                for (var i = 0; i < listeners.Count; i++)
                {
                    // gotta wrap it up so one guy doesn't spoil it for everyone
                    try
                    {
                        listeners[i].OnEvent(eventId, args);
                    }
                    catch (Exception e)
                    {
                        Debug.LogError(e.Message);
                    }
                }
            }
        }

        public static void AddListener(int eventId, IEventListener<T> listener)
        {
            List<IEventListener<T>> listeners;
            if (!EventListeners.TryGetValue(eventId, out listeners))
                EventListeners[eventId] = listeners = new List<IEventListener<T>>();

            listeners.Add(listener);
        }

        public static void RemoveListener(int eventId, IEventListener<T> listener)
        {
            List<IEventListener<T>> listeners;
            if (EventListeners.TryGetValue(eventId, out listeners))
                listeners.Remove(listener);
        }
    }

    public interface IEventListener
    {
        void OnEvent(int eventId);
    }

    public interface IEventListener<in TArgs>
    {
        void OnEvent(int eventId, TArgs args);
    }
}<commit_msg>Added a way to clear event listeners<commit_after>﻿using System;
using System.Collections.Generic;
using UnityEngine;

namespace Archon.SwissArmyLib.Events
{
    public static class EventSystem
    {
        private static readonly Dictionary<int, List<IEventListener>> EventListeners = new Dictionary<int, List<IEventListener>>();

        public static void Invoke(int eventId)
        {
            List<IEventListener> listeners;
            if (EventListeners.TryGetValue(eventId, out listeners))
            {
                for (var i = 0; i < listeners.Count; i++)
                {
                    // gotta wrap it up so one guy doesn't spoil it for everyone
                    try
                    {
                        listeners[i].OnEvent(eventId);
                    }
                    catch (Exception e)
                    {
                        Debug.LogError(e.Message);
                    }
                }
            }
        }

        public static void AddListener(int eventId, IEventListener listener)
        {
            List<IEventListener> listeners;
            if (!EventListeners.TryGetValue(eventId, out listeners))
                EventListeners[eventId] = listeners = new List<IEventListener>();

            listeners.Add(listener);
        }

        public static void RemoveListener(int eventId, IEventListener listener)
        {
            List<IEventListener> listeners;
            if (EventListeners.TryGetValue(eventId, out listeners))
                listeners.Remove(listener);
        }

        public static void Clear()
        {
            foreach (var listenerList in EventListeners.Values)
                listenerList.Clear();
        }

        public static void Clear(int eventId)
        {
            List<IEventListener> listeners;
            if (EventListeners.TryGetValue(eventId, out listeners))
                listeners.Clear();
        }
    }

    public static class EventSystem<T>
    {
        private static readonly Dictionary<int, List<IEventListener<T>>> EventListeners = new Dictionary<int, List<IEventListener<T>>>();

        public static void Invoke(int eventId, T args)
        {
            List<IEventListener<T>> listeners;
            if (EventListeners.TryGetValue(eventId, out listeners))
            {
                for (var i = 0; i < listeners.Count; i++)
                {
                    // gotta wrap it up so one guy doesn't spoil it for everyone
                    try
                    {
                        listeners[i].OnEvent(eventId, args);
                    }
                    catch (Exception e)
                    {
                        Debug.LogError(e.Message);
                    }
                }
            }
        }

        public static void AddListener(int eventId, IEventListener<T> listener)
        {
            List<IEventListener<T>> listeners;
            if (!EventListeners.TryGetValue(eventId, out listeners))
                EventListeners[eventId] = listeners = new List<IEventListener<T>>();

            listeners.Add(listener);
        }

        public static void RemoveListener(int eventId, IEventListener<T> listener)
        {
            List<IEventListener<T>> listeners;
            if (EventListeners.TryGetValue(eventId, out listeners))
                listeners.Remove(listener);
        }

        public static void Clear()
        {
            foreach (var listenerList in EventListeners.Values)
                listenerList.Clear();
        }

        public static void Clear(int eventId)
        {
            List<IEventListener<T>> listeners;
            if (EventListeners.TryGetValue(eventId, out listeners))
                listeners.Clear();
        }
    }

    public interface IEventListener
    {
        void OnEvent(int eventId);
    }

    public interface IEventListener<in TArgs>
    {
        void OnEvent(int eventId, TArgs args);
    }
}
{'fraction_non_alphanumeric': 0.08148977877345281, 'fraction_numerical': 0.0005600672080649678, 'mean_word_length': 1.546524064171123, 'pattern_counts': {'":': 0, '<': 62, '<?xml version=': 0, '>': 58, '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': '660558', 'n_tokens_mistral': 1729, 'n_tokens_neox': 1669, 'n_words': 430}