точно готовая лаба 8 чипи чипи чапа чапа мама я устала
This commit is contained in:
parent
b0b6b3397f
commit
c37d2ef26e
@ -59,13 +59,13 @@ namespace Sailboat.Generics
|
||||
/// <param name="collect"></param>
|
||||
/// <param name="obj"></param>
|
||||
/// <returns></returns>
|
||||
public static bool operator +(BoatsGenericCollection<T, U> collect, T? obj)
|
||||
public static int operator +(BoatsGenericCollection<T, U> collect, T? obj)
|
||||
{
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
return -1;
|
||||
}
|
||||
return (bool)collect?._collection.Insert(obj);
|
||||
return collect._collection.Insert(obj, new DrawingBoatEqutables());
|
||||
}
|
||||
/// <summary>
|
||||
/// Перегрузка оператора вычитания
|
||||
|
@ -156,7 +156,7 @@ namespace Sailboat.Generics
|
||||
DrawingBoat? truck = elem?.CreateDrawingBoat(_separatorForObject, _pictureWidth, _pictureHeight);
|
||||
if (truck != null)
|
||||
{
|
||||
if (!(collection + truck))
|
||||
if (collection + truck == -1)
|
||||
{
|
||||
throw new ApplicationException("Ошибка добавления в коллекцию");
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ namespace Sailboat
|
||||
_logger.LogWarning("Добавление пустого объекта");
|
||||
return;
|
||||
}
|
||||
if (obj + drawingBoat)
|
||||
if (obj + drawingBoat != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBoxCollection.Image = obj.ShowBoats();
|
||||
|
@ -38,14 +38,9 @@ namespace Sailboat.Generics
|
||||
/// </summary>
|
||||
/// <param name="boat">Добавляемая лодка</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T boat, IEqualityComparer<T?>? equal = null)
|
||||
public int Insert(T boat, IEqualityComparer<T?>? equal = null)
|
||||
{
|
||||
if (_places.Count == _maxCount)
|
||||
{
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
}
|
||||
Insert(boat, 0, equal);
|
||||
return true;
|
||||
return Insert(boat, 0, equal);
|
||||
}
|
||||
/// <summary>
|
||||
/// Добавление объекта в набор на конкретную позицию
|
||||
@ -53,22 +48,20 @@ namespace Sailboat.Generics
|
||||
/// <param name="boat">Добавляемая лодка</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns></returns>
|
||||
public bool Insert(T boat, int position, IEqualityComparer<T?>? equal = null)
|
||||
public int Insert(T boat, int position, IEqualityComparer<T?>? equal = null)
|
||||
{
|
||||
if (position < 0 || position >= _maxCount)
|
||||
if (position < 0 || position > Count)
|
||||
throw new BoatNotFoundException(position);
|
||||
|
||||
if (_places.Count >= _maxCount)
|
||||
if (Count >= _maxCount)
|
||||
throw new StorageOverflowException(_maxCount);
|
||||
|
||||
if (equal != null)
|
||||
if (equal != null && _places.Contains(boat, equal))
|
||||
{
|
||||
if (_places.Contains(boat, equal))
|
||||
throw new ArgumentException(nameof(boat));
|
||||
//throw new StorageOverflowException("Данный объект уже есть в коллекции");
|
||||
//MessageBox.Show("Данный объект уже есть в коллекции");
|
||||
return -1;
|
||||
}
|
||||
|
||||
_places.Insert(0, boat);
|
||||
return true;
|
||||
_places.Insert(position, boat);
|
||||
return position;
|
||||
}
|
||||
/// <summary>
|
||||
/// Удаление объекта из набора с конкретной позиции
|
||||
|
Loading…
x
Reference in New Issue
Block a user