using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HBLConsole.Communication
{
    /// <summary>
    /// 数据仓库
    /// </summary>
    public class DataStorage<T>
    {
        private ConcurrentQueue<T> cache = new ConcurrentQueue<T>();

        public void PutData(T data)
        {
            cache.Enqueue(data);
        }

        public void PutData(T[] data)
        {
            foreach (var item in data)
                cache.Enqueue(item);
        }

        public T GetData()
        {
            if (cache.Count >= 0)
            {
                cache.TryDequeue(out T data);
                return data;
            }
            return default(T);
        }

        public int GetSize()
        {
            return cache.Count;
        }
    }
}
