Сравнение объектов
This commit is contained in:
parent
ef6b1d2ccf
commit
11ba50c912
@ -36,5 +36,61 @@ namespace DoubleDeckerBus
|
||||
{
|
||||
return new DrawningObjectBus(data.CreateDrawningBus());
|
||||
}
|
||||
|
||||
public bool Equals(IDrawningObject? other)
|
||||
{
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var otherBus = other as DrawningObjectBus;
|
||||
if (otherBus == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var bus = _bus.Bus;
|
||||
var otherBusBus = otherBus._bus.Bus;
|
||||
if (bus.GetType().Name != otherBusBus.GetType().Name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (bus.Speed != otherBusBus.Speed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (bus.Weight != otherBusBus.Weight)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (bus.BodyColor != otherBusBus.BodyColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (bus is EntityDoubleDeckerBus DoubleDeckerBus && otherBusBus is EntityDoubleDeckerBus otherDoubleDeckerBus)
|
||||
{
|
||||
|
||||
if (DoubleDeckerBus.Stair != otherDoubleDeckerBus.Stair)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (DoubleDeckerBus.SecondFloor != otherDoubleDeckerBus.SecondFloor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (DoubleDeckerBus.BodyKit != otherDoubleDeckerBus.BodyKit)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (DoubleDeckerBus.DopColor != otherDoubleDeckerBus.DopColor)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace DoubleDeckerBus
|
||||
{
|
||||
internal interface IDrawningObject
|
||||
internal interface IDrawningObject : IEquatable<IDrawningObject>
|
||||
{
|
||||
/// <summary>
|
||||
/// Шаг перемещения объекта
|
||||
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
namespace DoubleDeckerBus
|
||||
{
|
||||
internal class MapWithSetBusesGeneric<T,U>
|
||||
where T : class, IDrawningObject
|
||||
where T : class, IDrawningObject, IEquatable<T>
|
||||
where U : AbstractMap
|
||||
{
|
||||
/// <summary>
|
||||
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
||||
namespace DoubleDeckerBus
|
||||
{
|
||||
internal class SetBusesGeneric<T>
|
||||
where T : class
|
||||
where T : class, IEquatable<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Список объектов, которые храним
|
||||
@ -45,11 +45,17 @@ namespace DoubleDeckerBus
|
||||
/// <returns></returns>
|
||||
public int Insert(T bus, int position)
|
||||
{
|
||||
if (_places.Contains(bus))
|
||||
{
|
||||
throw new ArgumentException("Такой автобус уже существует");
|
||||
}
|
||||
|
||||
if (position < 0 || position >= _maxCount)
|
||||
{
|
||||
throw new BusNotFoundException("Место указано неверно");
|
||||
}
|
||||
|
||||
|
||||
BusyPlaces++;
|
||||
_places.Insert(position, bus);
|
||||
return position;
|
||||
|
Loading…
Reference in New Issue
Block a user