using System;
using System.Collections.Generic;
using Fort23.Core;

namespace Core.Utility.Event
{
    public class EventDataBasic<T> : IEventData ,IDisposable where T : class, new()
    {
        private static readonly Queue<T> queue = new Queue<T>();

        public bool isHuiShou;
        
        public void Recycle()
        {
            Dispose();
        }

        public static T Create()
        {
            if (queue.Count <= 0)
            {
                T t = new T();
                return t;
            }

            T VALUE = queue.Dequeue();
            // System.GC.ReRegisterForFinalize(VALUE);
            return VALUE;
        }

        public static void Recycle(T data)
        {
            if (data == null || queue.Contains(data))
            {
                return;
            }

            if (queue.Count > 10)
            {
                return;
            }

            // System.GC.SuppressFinalize(data);
            queue.Enqueue(data);
        }

        protected EventDataBasic()
        {
        }



        public void Dispose()
        {
            Recycle(this as T);
        }
    }
}