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