From 4c180b71cb40e6bb0ef92430a9cfc540e1a5bfdb Mon Sep 17 00:00:00 2001 From: tellsense Date: Mon, 11 Dec 2023 00:17:08 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LocomotivesGenericCollection.cs | 2 +- ElectricLocomotive/ElectricLocomotive/SetGeneric.cs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs index 4ff16df..611b823 100644 --- a/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs +++ b/ElectricLocomotive/ElectricLocomotive/LocomotivesGenericCollection.cs @@ -15,7 +15,7 @@ namespace ProjectElectricLocomotive.Generics private readonly int _pictureWidth; private readonly int _pictureHeight; private readonly int _placeSizeWidth = 200; - private readonly int _placeSizeHeight = 120; + private readonly int _placeSizeHeight = 130; private readonly SetGeneric _collection; public LocomotivesGenericCollection(int picWidth, int picHeight) { diff --git a/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs b/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs index 7b52791..e5b63dd 100644 --- a/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs +++ b/ElectricLocomotive/ElectricLocomotive/SetGeneric.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using ProjectElectricLocomotive.Exceptions; namespace ProjectElectricLocomotive.Generics { @@ -29,7 +30,13 @@ namespace ProjectElectricLocomotive.Generics public int Insert(T loco, int position) { - if (position < 0 || position >= _maxCount) return -1; + if (_places.Count >= _maxCount) + throw new StorageOverflowException(_maxCount); + + if (position < 0 || position >= _maxCount) + { + return -1; + } _places.Insert(position, loco); return position; } @@ -40,6 +47,8 @@ namespace ProjectElectricLocomotive.Generics return null; T? tmp = _places[position]; + if (tmp == null) + throw new LocomotiveNotFoundException(position); _places[position] = null; return tmp; }