using System;

namespace mgaia.Utils
{
    public class GenericReusablePool<T> : AbstractReusablePool where T : class, new()
    {
        private static GenericReusablePool<T> sInstance = null;

        public static GenericReusablePool<T> Instance
        {
            get
            {
                if (sInstance == null)
                {
                    sInstance = new GenericReusablePool<T>(new GenericReusableFactory<T>());
                }
                return sInstance;
            }
        }

        protected GenericReusablePool(AbstractReusableFactory factory) : base(factory) { }

        new public GenericReusable<T> Acquire(object parameter)
        {
            return (GenericReusable<T>)((AbstractReusablePool)this).Acquire(null);
        }

        public GenericReusable<T> Acquire()
        {
            return Acquire(null);
        }

        public GenericReusable<T> Find(T value)
        {
            return (GenericReusable<T>)base.Find(reusable => object.ReferenceEquals(((GenericReusable<T>)reusable).Value, value));
        }

        #region implemented abstract members of AbstractPool
        protected override bool IsMatch(IReusable reusable, object filter)
        {
            return true;
        }
        #endregion
    }
}