laba8: fix

This commit is contained in:
bulatova_karina 2023-12-23 18:33:54 +03:00
parent 8244d20cd2
commit e420c875db
4 changed files with 18 additions and 21 deletions

View File

@ -180,7 +180,7 @@ namespace WarmlyShip
}
try
{
if (obj + drawingWarmlyShip != -1)
if (obj + drawingWarmlyShip)
{
MessageBox.Show("Объект добавлен");
pictureBoxCollection.Image = obj.ShowShips();
@ -192,7 +192,10 @@ namespace WarmlyShip
MessageBox.Show(ex.Message);
_logger.LogWarning($"{ex.Message} в наборе {listBoxStorages.SelectedItem.ToString()}");
}
catch (ArgumentException ex)
{
MessageBox.Show(ex.Message);
}
}
/// <summary>
/// Удаление объекта из набора

View File

@ -38,28 +38,23 @@ namespace WarmlyShip.Generics
/// </summary>
/// <param name="warmlyship">Добавляемый теплоход</param>
/// <returns></returns>
public int Insert(T warmlyship, IEqualityComparer<T?>? equal = null)
public bool Insert(T warmlyship, IEqualityComparer<T?>? equal = null)
{
return Insert(warmlyship, 0, equal);
}
/// <summary>
/// Добавление объекта в набор на конкретную позицию
/// </summary>
/// <param name="warmlyship">Добавляемый теплоход</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public int Insert(T warmlyship, int position, IEqualityComparer<T?>? equal = null)
public bool Insert(T warmlyship, int position, IEqualityComparer<T?>? equal = null)
{
if (position < 0 || position > Count)
if (position < 0 || position >= _maxCount)
throw new ShipNotFoundException(position);
if (Count >= _maxCount)
throw new StorageOverflowException(_maxCount);
if (equal != null && _places.Contains(warmlyship, equal))
{
return -1;
}
_places.Insert(position, warmlyship);
return position;
throw new ArgumentException("Данный объект уже есть в коллекции");
_places.Insert(0, warmlyship);
return true;
}
/// <summary>
/// Удаление объекта из набора с конкретной позиции

View File

@ -67,14 +67,13 @@ namespace WarmlyShip.Generics
/// <param name="collect"></param>
/// <param name="obj"></param>
/// <returns></returns>
public static int operator +(ShipsGenericCollection<T, U> collect, T?
obj)
public static bool operator +(ShipsGenericCollection<T, U> collect, T? obj)
{
if (obj == null)
{
return -1;
return false;
}
return collect._collection.Insert(obj, new DrawingShipEqutables());
return (bool)collect?._collection.Insert(obj, new DrawingShipEqutables());
}
/// <summary>
/// Перегрузка оператора вычитания

View File

@ -172,7 +172,7 @@ namespace WarmlyShip.Generics
elem?.CreateDrawingShip(_separatorForObject, _pictureWidth, _pictureHeight);
if (ship != null)
{
if (collection + ship != -1)
if (!(collection + ship))
{
throw new Exception("Ошибка добавления в коллекцию");
}