Сравнение объектов

This commit is contained in:
Дамир Нугаев 2022-12-05 23:26:42 +04:00
parent 5327e9044f
commit 7e06625cc9
4 changed files with 29 additions and 4 deletions

View File

@ -39,6 +39,31 @@ namespace Bus
public string GetInfo() => _bus?.GetDataForSave();
public static IDrawingObject Create(string data) => new DrawingObjectBus(data.CreateDrawingBus());
public bool Equals(IDrawingObject? other)
{
if (other is not DrawingObjectBus otherBus)
{
return false;
}
var entity = _bus.Bus;
var otherEntity = otherBus._bus.Bus;
if (entity.GetType() != otherEntity.GetType() ||
entity.Speed != otherEntity.Speed ||
entity.Weight != otherEntity.Weight ||
entity.BodyColor != otherEntity.BodyColor)
{
return false;
}
if (entity is EntitySportBus entitySportBus &&
otherEntity is EntitySportBus otherEntitySportBus && (
entitySportBus.Wing != otherEntitySportBus.Wing ||
entitySportBus.DopColor != otherEntitySportBus.DopColor ||
entitySportBus.Sportline != otherEntitySportBus.Sportline))
{
return false;
}
return true;
}
}
}

View File

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace Bus
{
internal interface IDrawingObject
internal interface IDrawingObject : IEquatable<IDrawingObject>
{
public float Step { get; }
void SetObject(int x, int y, int width, int height);

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace Bus
{
internal class MapWithSetDoubleDeckerBusGeneric<T, U>
where T : class, IDrawingObject
where T : class, IEquatable<T>, IDrawingObject
where U : AbstractMap
{
private readonly int _pictureWidth;

View File

@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace Bus
{
internal class SetDoubleDeckerBusGeneric<T>
where T : class
where T : class, IEquatable<T>
{
private readonly List<T> _places;
public int Count => _places.Count;