начало работы над лабой 8

This commit is contained in:
Полина Чубыкина 2023-12-19 22:11:09 +04:00
parent 3f53baf84e
commit 4bea0dc756
5 changed files with 119 additions and 20 deletions

View File

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sailboat
{
internal class BoatCompareByColor
{
}
}

View File

@ -0,0 +1,35 @@
using Sailboat.DrawingObjects;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Sailboat
{
internal class BoatCompareByType : IComparer<DrawingBoat?>
{
public int Compare(DrawingBoat? x, DrawingBoat? y)
{
if (x == null || x.EntityBoat == null)
{
throw new ArgumentNullException(nameof(x));
}
if (y == null || y.EntityBoat == null)
{
throw new ArgumentNullException(nameof(y));
}
if (x.GetType().Name != y.GetType().Name)
{
return x.GetType().Name.CompareTo(y.GetType().Name);
}
var speedCompare =
x.EntityBoat.Speed.CompareTo(y.EntityBoat.Speed);
if (speedCompare != 0)
{
return speedCompare;
}
return x.EntityBoat.Weight.CompareTo(y.EntityBoat.Weight);
}
}
}

View File

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sailboat.DrawingObjects;
using Sailboat.Entities;
namespace Sailboat.Generics
{
internal class DrawingBoatEqutables : IEqualityComparer<DrawingBoat?>
{
public bool Equals(DrawingBoat? x, DrawingBoat? y)
{
if (x == null || x.EntityBoat == null)
{
throw new ArgumentNullException(nameof(x));
}
if (y == null || y.EntityBoat == null)
{
throw new ArgumentNullException(nameof(y));
}
if (x.GetType().Name != y.GetType().Name)
{
return false;
}
if (x.EntityBoat.Speed != y.EntityBoat.Speed)
{
return false;
}
if (x.EntityBoat.Weight != y.EntityBoat.Weight)
{
return false;
}
if (x.EntityBoat.BodyColor != y.EntityBoat.BodyColor)
{
return false;
}
if (x is DrawingSailboat && y is DrawingSailboat)
{
EntitySailboat EntityX = (EntitySailboat)x.EntityBoat;
EntitySailboat EntityY = (EntitySailboat)y.EntityBoat;
if (EntityX.Sail != EntityY.Sail)
return false;
if (EntityX.Hull != EntityY.Hull)
return false;
if (EntityX.AdditionalColor != EntityY.AdditionalColor)
return false;
}
return true;
}
public int GetHashCode([DisallowNull] DrawingBoat obj)
{
return obj.GetHashCode();
}
}
}

View File

@ -88,21 +88,6 @@ namespace Sailboat
MessageBox.Show("Не удалось добавить объект");
_logger.LogInformation($"Не удалось добавить объект");
}
//try
//{
// if (obj + drawingBoat)
// {
// MessageBox.Show("Объект добавлен");
// pictureBoxCollection.Image = obj.ShowBoats();
// _logger.LogInformation($"Объект {obj.GetType()} добавлен");
// }
//}
//catch (StorageOverflowException ex)
//{
// MessageBox.Show(ex.Message);
// MessageBox.Show("Не удалось добавить объект");
// _logger.LogWarning($"{ex.Message} в наборе {listBoxStorages.SelectedItem.ToString()}");
//}
}
private void buttonRemoveBoat_Click(object sender, EventArgs e)

View File

@ -36,13 +36,13 @@ namespace Sailboat.Generics
/// </summary>
/// <param name="boat">Добавляемая лодка</param>
/// <returns></returns>
public bool Insert(T boat)
public bool Insert(T boat, IEqualityComparer<T?>? equal = null)
{
if (_places.Count == _maxCount)
{
return false;
{
throw new StorageOverflowException(_maxCount);
}
Insert(boat, 0);
Insert(boat, 0, equal);
return true;
}
/// <summary>
@ -51,13 +51,21 @@ namespace Sailboat.Generics
/// <param name="boat">Добавляемая лодка</param>
/// <param name="position">Позиция</param>
/// <returns></returns>
public bool Insert(T boat, int position)
public bool Insert(T boat, int position, IEqualityComparer<T?>? equal = null)
{
if (position < 0 || position >= _maxCount)
throw new BoatNotFoundException(position);
if (_places.Count >= _maxCount)
throw new StorageOverflowException(_maxCount);
//вот это проверить перед отправкой хз что делает
if (equal != null)
{
if (_places.Contains(boat, equal))
throw new ArgumentException(nameof(boat));
}
_places.Insert(0, boat);
return true;
}