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;