diff --git a/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs b/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs index ef15c44..3212255 100644 --- a/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs +++ b/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace ProjectPlane { - internal class SetPlanesGeneric where T : class + internal class SetPlanesGeneric where T : class, IEquatable { /// /// Список объектов, которые храним @@ -43,12 +43,11 @@ namespace ProjectPlane /// public int Insert(T plane, int position) { - if (Count == _maxCount) throw new StorageOverflowException(_maxCount); + if (_places.Contains(plane)) return -1; - if (position < 0 || position >= _maxCount) return -1; + if (position < 0 || position >= _maxCount) throw new StorageOverflowException(_maxCount); _places.Insert(position, plane); return position; - } /// /// Удаление объекта из набора с конкретной позиции @@ -102,5 +101,14 @@ namespace ProjectPlane } } } + public void SortSet(IComparer comparer) + { + if (comparer == null) + { + return; + } + _places.Sort(comparer); + } + } }