This commit is contained in:
Вячеслав Иванов 2023-12-27 22:07:50 +04:00
parent 2655e17c9b
commit 8799024689

View File

@ -39,18 +39,24 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics
_places = new List<T?>(count);
}
/// <summary>
/// Сортировка набора объектов
/// </summary>
/// <param name="comparer"></param>
public void SortSet(IComparer<T?> comparer) => _places.Sort(comparer);
/// <summary>
/// Добавление объекта в набор
/// </summary>
/// <param name="bus">Добавляемый автобус</param>
/// <returns></returns>
public void Insert(T bus)
public void Insert(T bus, IEqualityComparer<T>? equal = null)
{
if (_places.Count == _maxCount)
{
throw new StorageOverflowException(_maxCount);
}
Insert(bus, 0);
Insert(bus, 0, equal);
}
/// <summary>
@ -59,7 +65,7 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics
/// <param name="bus">Добавляемый автобус</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public void Insert(T bus, int position)
public void Insert(T bus, int position, IEqualityComparer<T>? equal = null)
{
if (_places.Count == _maxCount)
{
@ -69,6 +75,13 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics
{
throw new Exception("Неверная позиция для вставки");
}
if (equal != null)
{
if (_places.Contains(bus, equal))
{
throw new ArgumentException(nameof(bus));
}
}
_places.Insert(position, bus);
}
@ -79,7 +92,7 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics
/// <returns></returns>
public void Remove(int position)
{
if (position < 0 || position >= Count)
if (!(position >= 0 && position < Count))
{
throw new BusNotFoundException(position);
}
@ -96,7 +109,7 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics
{
get
{
if (position < 0 || position >= _maxCount)
if (!(position >= 0 && position < Count))
{
return null;
}
@ -109,9 +122,7 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics
{
return;
}
_places.Insert(position, value);
return;
}
}