diff --git a/WarmlyShip/WarmlyShip/FormShipCollection.cs b/WarmlyShip/WarmlyShip/FormShipCollection.cs
index b8089df..5ba9bec 100644
--- a/WarmlyShip/WarmlyShip/FormShipCollection.cs
+++ b/WarmlyShip/WarmlyShip/FormShipCollection.cs
@@ -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);
+ }
}
///
/// Удаление объекта из набора
diff --git a/WarmlyShip/WarmlyShip/SetGeneric.cs b/WarmlyShip/WarmlyShip/SetGeneric.cs
index 41707bc..9779d44 100644
--- a/WarmlyShip/WarmlyShip/SetGeneric.cs
+++ b/WarmlyShip/WarmlyShip/SetGeneric.cs
@@ -38,28 +38,23 @@ namespace WarmlyShip.Generics
///
/// Добавляемый теплоход
///
- public int Insert(T warmlyship, IEqualityComparer? equal = null)
+ public bool Insert(T warmlyship, IEqualityComparer? equal = null)
{
return Insert(warmlyship, 0, equal);
}
- ///
- /// Добавление объекта в набор на конкретную позицию
- ///
- /// Добавляемый теплоход
- /// Позиция
- ///
- public int Insert(T warmlyship, int position, IEqualityComparer? equal = null)
+
+ public bool Insert(T warmlyship, int position, IEqualityComparer? 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;
}
///
/// Удаление объекта из набора с конкретной позиции
diff --git a/WarmlyShip/WarmlyShip/ShipsGenericCollection.cs b/WarmlyShip/WarmlyShip/ShipsGenericCollection.cs
index 8cc5d14..308ac0f 100644
--- a/WarmlyShip/WarmlyShip/ShipsGenericCollection.cs
+++ b/WarmlyShip/WarmlyShip/ShipsGenericCollection.cs
@@ -67,14 +67,13 @@ namespace WarmlyShip.Generics
///
///
///
- public static int operator +(ShipsGenericCollection collect, T?
- obj)
+ public static bool operator +(ShipsGenericCollection 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());
}
///
/// Перегрузка оператора вычитания
diff --git a/WarmlyShip/WarmlyShip/ShipsGenericStorage.cs b/WarmlyShip/WarmlyShip/ShipsGenericStorage.cs
index 3c5a826..96c3ae5 100644
--- a/WarmlyShip/WarmlyShip/ShipsGenericStorage.cs
+++ b/WarmlyShip/WarmlyShip/ShipsGenericStorage.cs
@@ -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("Ошибка добавления в коллекцию");
}