начало работы над лабой 8
This commit is contained in:
parent
3f53baf84e
commit
4bea0dc756
12
Sailboat/Sailboat/BoatCompareByColor.cs
Normal file
12
Sailboat/Sailboat/BoatCompareByColor.cs
Normal 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
|
||||||
|
{
|
||||||
|
}
|
||||||
|
}
|
35
Sailboat/Sailboat/BoatCompareByType.cs
Normal file
35
Sailboat/Sailboat/BoatCompareByType.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
59
Sailboat/Sailboat/DrawingBoatEqutables.cs
Normal file
59
Sailboat/Sailboat/DrawingBoatEqutables.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -88,21 +88,6 @@ namespace Sailboat
|
|||||||
MessageBox.Show("Не удалось добавить объект");
|
MessageBox.Show("Не удалось добавить объект");
|
||||||
_logger.LogInformation($"Не удалось добавить объект");
|
_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)
|
private void buttonRemoveBoat_Click(object sender, EventArgs e)
|
||||||
|
@ -36,13 +36,13 @@ namespace Sailboat.Generics
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="boat">Добавляемая лодка</param>
|
/// <param name="boat">Добавляемая лодка</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool Insert(T boat)
|
public bool Insert(T boat, IEqualityComparer<T?>? equal = null)
|
||||||
{
|
{
|
||||||
if (_places.Count == _maxCount)
|
if (_places.Count == _maxCount)
|
||||||
{
|
{
|
||||||
return false;
|
throw new StorageOverflowException(_maxCount);
|
||||||
}
|
}
|
||||||
Insert(boat, 0);
|
Insert(boat, 0, equal);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -51,13 +51,21 @@ 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)
|
public bool Insert(T boat, int position, IEqualityComparer<T?>? equal = null)
|
||||||
{
|
{
|
||||||
if (position < 0 || position >= _maxCount)
|
if (position < 0 || position >= _maxCount)
|
||||||
throw new BoatNotFoundException(position);
|
throw new BoatNotFoundException(position);
|
||||||
|
|
||||||
if (_places.Count >= _maxCount)
|
if (_places.Count >= _maxCount)
|
||||||
throw new StorageOverflowException(_maxCount);
|
throw new StorageOverflowException(_maxCount);
|
||||||
|
|
||||||
|
//вот это проверить перед отправкой хз что делает
|
||||||
|
if (equal != null)
|
||||||
|
{
|
||||||
|
if (_places.Contains(boat, equal))
|
||||||
|
throw new ArgumentException(nameof(boat));
|
||||||
|
}
|
||||||
|
|
||||||
_places.Insert(0, boat);
|
_places.Insert(0, boat);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user