using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ProjectElectricLocomotive.CollectionGenericObjects { public class ListGenericObjects : ICollectionGenericObjects where T: class { /// /// Список объектов, которые храним /// private readonly List _collection; /// /// Максимально допустимое число объектов в списке /// private int _maxCount; public int MaxCount { get { return Count; } set { if (value > 0) { _maxCount = value; } } } public int Count => _collection.Count; public CollectionType GetCollectionType => CollectionType.List; /// /// Конструктор /// public ListGenericObjects() { _collection = new(); } public T? Get(int position) { if(position >= 0 && position < Count) { return _collection[position]; } // TODO проверка позиции return null; } public int Insert(T obj) { if(Count <= _maxCount) { _collection.Add(obj); return Count; } // TODO проверка, что не превышено максимальное количество элементов // TODO вставка в конец набора return -1; } public int Insert(T obj, int position) { if(Count <= _maxCount) { _collection.Insert(position, obj); return position; } // TODO проверка, что не превышено максимальное количество элементов // TODO проверка позиции // TODO вставка по позиции return -1; } public T Remove(int position) { if(position >= 0 && position <= _maxCount) { T ret = _collection[position]; _collection.RemoveAt(position); return ret; } // TODO проверка позиции // TODO удаление объекта из списка return null; } public IEnumerable GetItems() { for (int i = 0; i < Count; ++i) { yield return _collection[i]; } } } }