using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Hydroplane.Generics { internal class SetGeneric where T : class { private readonly List _places; public int Count => _places.Count; private readonly int _maxCount; public SetGeneric(int count) { _maxCount = count; _places = new List(_maxCount); } public bool Insert(T plane) { return Insert(plane, 0); } public bool Insert(T plane, int position) { if (position < 0 || position >= _maxCount) return false; if (Count >= _maxCount) return false; _places.Insert(0, plane); return true; } public bool Remove(int position) { if (position < 0 || position > _maxCount) return false; if (position >= Count) return false; _places.RemoveAt(position); return true; } public T? this[int position] { get { if (position < 0 || position > _maxCount) return null; return _places[position]; } set { if (position < 0 || position > _maxCount) return; _places[position] = value; } } public IEnumerable GetPlanes(int? maxPlanes = null) { for (int i = 0; i < _places.Count; ++i) { yield return _places[i]; if (maxPlanes.HasValue && i == maxPlanes.Value) { yield break; } } } } }