From 447415895fa48f6c18c9128fdbe47cb572d508b7 Mon Sep 17 00:00:00 2001 From: "Nikolaeva_Y.A" Date: Tue, 6 Dec 2022 10:07:25 +0400 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=8B=D0=B7=D0=BE=D0=B2=20=D0=BD=D0=B5?= =?UTF-8?q?=D0=BE=D0=B1=D1=85=D0=BE=D0=B4=D0=B8=D0=BC=D1=8B=D1=85=20=D0=BD?= =?UTF-8?q?=D0=B0=D1=81=D0=BB=D0=B5=D0=B4=D0=BD=D0=B8=D0=BA=D0=BE=D0=B2=20?= =?UTF-8?q?=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20Exception.=20=D0=9F?= =?UTF-8?q?=D1=80=D0=BE=D1=87=D0=B8=D0=B5=20=D0=BF=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Airbus/Airbus/MapsCollection.cs | 4 ++-- Airbus/Airbus/PlaneNotFoundException.cs | 1 + Airbus/Airbus/SetPlanesGeneric.cs | 11 ++++++++++- Airbus/Airbus/StorageOverflowException.cs | 1 + 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Airbus/Airbus/MapsCollection.cs b/Airbus/Airbus/MapsCollection.cs index 8d3cf91..2c3f85a 100644 --- a/Airbus/Airbus/MapsCollection.cs +++ b/Airbus/Airbus/MapsCollection.cs @@ -78,7 +78,7 @@ namespace Airbus { if (!File.Exists(filename)) { - throw new Exception("Файл не найден"); + throw new FileNotFoundException("Файл не найден"); } using (StreamReader sr = new(filename)) @@ -88,7 +88,7 @@ namespace Airbus //если не содержит такую запись или пустой файл if ((str = sr.ReadLine()) == null || !str.Contains("MapsCollection")) { - throw new Exception("Формат данных в файле неправильный"); + throw new FileFormatException("Формат данных в файле неправильный"); } _mapStorage.Clear(); diff --git a/Airbus/Airbus/PlaneNotFoundException.cs b/Airbus/Airbus/PlaneNotFoundException.cs index 8b90594..e48a609 100644 --- a/Airbus/Airbus/PlaneNotFoundException.cs +++ b/Airbus/Airbus/PlaneNotFoundException.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks; diff --git a/Airbus/Airbus/SetPlanesGeneric.cs b/Airbus/Airbus/SetPlanesGeneric.cs index b75ddf8..4ef839c 100644 --- a/Airbus/Airbus/SetPlanesGeneric.cs +++ b/Airbus/Airbus/SetPlanesGeneric.cs @@ -36,10 +36,19 @@ namespace Airbus //добавление объекта в набор на конкретную позицию public int Insert(T plane, int position) { - if (position >= _maxCount && position < 0) + if (position > _maxCount && position < 0) { return -1; } + if (_places.Contains(plane)) + { + throw new ArgumentException($"Объект {plane} уже есть в наборе"); + } + + if (Count == _maxCount) + { + throw new StorageOverflowException(_maxCount); + } _places.Insert(position, plane); return position; diff --git a/Airbus/Airbus/StorageOverflowException.cs b/Airbus/Airbus/StorageOverflowException.cs index 7ddeb57..3a95d3c 100644 --- a/Airbus/Airbus/StorageOverflowException.cs +++ b/Airbus/Airbus/StorageOverflowException.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Serialization; using System.Text; using System.Threading.Tasks;