diff --git a/Bus/Bus/DrawingObjectBus.cs b/Bus/Bus/DrawingObjectBus.cs index ae73512..0cdc7b7 100644 --- a/Bus/Bus/DrawingObjectBus.cs +++ b/Bus/Bus/DrawingObjectBus.cs @@ -47,25 +47,25 @@ namespace Bus return false; } var otherBus = other as DrawingObjectBus; - if (otherBus == null) + 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; } - var bus = _bus.Bus; - var otherBusBus = otherBus._bus.Bus; - if (bus.Speed != otherBusBus.Speed) + + if (entity is EntitySportBus entitySportBus && + otherEntity is EntitySportBus otherEntitySportBus && ( + entitySportBus.Wing != otherEntitySportBus.Wing || + entitySportBus.DopColor != otherEntitySportBus.DopColor || + entitySportBus.Sportline != otherEntitySportBus.Sportline)) { return false; } - if (bus.Weight != otherBusBus.Weight) - { - return false; - } - if (bus.BodyColor != otherBusBus.BodyColor) - { - return false; - } - // TODO доделать проверки в случае продвинутого объекта return true; } } diff --git a/Bus/Bus/MapWithSetDoubleDeckerBusGeneric.cs b/Bus/Bus/MapWithSetDoubleDeckerBusGeneric.cs index 635c3f8..c709b6e 100644 --- a/Bus/Bus/MapWithSetDoubleDeckerBusGeneric.cs +++ b/Bus/Bus/MapWithSetDoubleDeckerBusGeneric.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace Bus { internal class MapWithSetDoubleDeckerBusGeneric - where T : class, IDrawingObject + where T : class, IDrawingObject, IEquatable where U : AbstractMap { private readonly int _pictureWidth; diff --git a/Bus/Bus/SetDoubleDeckerBusGeneric.cs b/Bus/Bus/SetDoubleDeckerBusGeneric.cs index e34e350..dfefa76 100644 --- a/Bus/Bus/SetDoubleDeckerBusGeneric.cs +++ b/Bus/Bus/SetDoubleDeckerBusGeneric.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace Bus { internal class SetDoubleDeckerBusGeneric - where T : class + where T : class, IEquatable { private readonly List _places; public int Count => _places.Count; @@ -33,18 +33,15 @@ namespace Bus public int Insert(T bus, int position) { - if (position > _maxCount && position < 0) + + if (_places.Contains(bus)) + throw new ArgumentException($"Объект {bus} уже есть в наборе"); + if (Count == _maxCount) + throw new StorageOverflowException(_maxCount); + if (!isCorrectPosition(position)) { return -1; } - if (_places.Contains(bus)) - { - throw new ArgumentException($"Объект {bus} уже есть в наборе"); - } - if (Count == _maxCount) - { - throw new StorageOverflowException(_maxCount); - } _places.Insert(position, bus); return position; }