Обновлен метод вставки в классе SetGeneric

This commit is contained in:
Никита Потапов 2023-12-16 22:19:33 +04:00
parent 13de54b639
commit adbf68e639

View File

@ -38,9 +38,9 @@ namespace ProjectStormtrooper
/// </summary>
/// <param name="plane"></param>
/// <returns></returns>
public int Insert(T plane)
public int Insert(T plane, IEqualityComparer<T?>? equal = null)
{
return Insert(plane, 0);
return Insert(plane, 0, equal);
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
@ -48,7 +48,7 @@ namespace ProjectStormtrooper
/// <param name="plane"></param>
/// <param name="position"></param>
/// <returns></returns>
public int Insert(T plane, int position)
public int Insert(T plane, int position, IEqualityComparer<T?>? equal = null)
{
if (_places.Count == _maxCount)
{
@ -59,6 +59,16 @@ namespace ProjectStormtrooper
{
return -1;
}
if (equal != null)
{
foreach (var otherPlane in _places)
{
if (equal.Equals(otherPlane, plane))
{
throw new ApplicationException("Такой объект уже есть в коллекции!");
}
}
}
// Вставка по позиции
_places.Insert(position, plane);
return position;