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