From e3ab4bf429d0db86d89108ae586189a284d5cdbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D0=B8=D1=80=20=D0=9D=D1=83=D0=B3=D0=B0?= =?UTF-8?q?=D0=B5=D0=B2?= Date: Sat, 3 Dec 2022 20:37:58 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D1=80=D0=B0=D0=B2=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bus/Bus/DrawingObjectBus.cs | 26 ++++++++++----------- Bus/Bus/MapWithSetDoubleDeckerBusGeneric.cs | 2 +- Bus/Bus/SetDoubleDeckerBusGeneric.cs | 17 ++++++-------- 3 files changed, 21 insertions(+), 24 deletions(-) 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; }