From 8d85818dae317648dc66b6947bd1ccffc55dcfe1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A1=D0=B5=D1=80=D0=B3=D0=B5=D0=B9=20=D0=9F=D0=BE=D0=BB?= =?UTF-8?q?=D0=B5=D0=B2=D0=BE=D0=B9?= Date: Mon, 5 Dec 2022 22:12:14 +0400 Subject: [PATCH] Added exceptions to SetArtilleriesGeneric --- SetArtilleriesGeneric.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/SetArtilleriesGeneric.java b/SetArtilleriesGeneric.java index 0293a7b..24b4ea1 100644 --- a/SetArtilleriesGeneric.java +++ b/SetArtilleriesGeneric.java @@ -20,7 +20,11 @@ public class SetArtilleriesGeneric { } public int insert(T artillery, int position) { - if (position < 0 || position > getCount() || getCount() == _maxCount) { + if (getCount() == _maxCount) { + throw new StorageOverflowException(_maxCount); + } + + if (position < 0 || position > getCount()) { return -1; } @@ -37,6 +41,10 @@ public class SetArtilleriesGeneric { T result = _places.get(position); + if (result == null) { + throw new ArtilleryNotFoundException(position); + } + _places.remove(position); return result;