From 7a2b6d4d45c89a1c5caa44739215c54ed35b5d2b Mon Sep 17 00:00:00 2001 From: Daniya_Youdakova Date: Sun, 25 Dec 2022 17:22:30 +0400 Subject: [PATCH] =?UTF-8?q?=D0=BB=D0=B0=D0=B1-7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SetAircraftCarriersGeneric.cs | 24 ++++++++++--------- .../StorageOverflowException.cs | 22 +++++++++++++++++ 2 files changed, 35 insertions(+), 11 deletions(-) create mode 100644 AircraftCarrier/AircraftCarrier/StorageOverflowException.cs diff --git a/AircraftCarrier/AircraftCarrier/SetAircraftCarriersGeneric.cs b/AircraftCarrier/AircraftCarrier/SetAircraftCarriersGeneric.cs index b454a25..0cf6f06 100644 --- a/AircraftCarrier/AircraftCarrier/SetAircraftCarriersGeneric.cs +++ b/AircraftCarrier/AircraftCarrier/SetAircraftCarriersGeneric.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Numerics; using System.Text; using System.Threading.Tasks; @@ -46,16 +47,16 @@ namespace AircraftCarrier /// public int Insert(T AircraftCarrier, int position) { - // проверка позиции - if (!CorrectPos(position)) + // TODO проверка позиции + if (Count == _maxCount) { - return -1; + throw new StorageOverflowException(_maxCount); } - // вставка по позиции + if (position < 0 || position > _maxCount) return -1; + // TODO вставка по позиции _places.Insert(position, AircraftCarrier); return position; } - /// /// Удаление объекта из набора с конкретной позиции /// @@ -63,13 +64,14 @@ namespace AircraftCarrier /// public T Remove(int position) { - // проверка позиции - if (!CorrectPos(position)) - return null; - // удаление объекта из массива, присовив элементу массива значение null - T temp = _places[position]; + // TODO проверка позиции + if (position >= Count || position < 0) + { + throw new AircraftCarrierNotFoundException(position); + } + T aircraftcarrier = _places[position]; _places.RemoveAt(position); - return temp; + return aircraftcarrier; } /// /// Получение объекта из набора по позиции diff --git a/AircraftCarrier/AircraftCarrier/StorageOverflowException.cs b/AircraftCarrier/AircraftCarrier/StorageOverflowException.cs new file mode 100644 index 0000000..faaf2a0 --- /dev/null +++ b/AircraftCarrier/AircraftCarrier/StorageOverflowException.cs @@ -0,0 +1,22 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Runtime.Serialization; +using System.Text; +using System.Threading.Tasks; + +namespace AircraftCarrier +{ + [Serializable] + internal class StorageOverflowException : ApplicationException + { + public StorageOverflowException(int count) : base($"В наборе превышено допустимое количество: { count}") { } + public StorageOverflowException() : base() { } + public StorageOverflowException(string message) : base(message) { } + public StorageOverflowException(string message, Exception exception) : + base(message, exception) + { } + protected StorageOverflowException(SerializationInfo info, + StreamingContext contex) : base(info, contex) { } + } +} \ No newline at end of file