From f2ee03502d5747c03d20dc0747393f49d9d0dd63 Mon Sep 17 00:00:00 2001 From: Yuri Tatishchev Date: Wed, 26 Mar 2025 20:52:50 -0700 Subject: [PATCH] hw3: PhotoAlbumModel: fix out-of-bounds errors on deletePhoto --- hw3/src/model/PhotoAlbumModel.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/hw3/src/model/PhotoAlbumModel.java b/hw3/src/model/PhotoAlbumModel.java index 015b6d4..af147b0 100644 --- a/hw3/src/model/PhotoAlbumModel.java +++ b/hw3/src/model/PhotoAlbumModel.java @@ -59,18 +59,14 @@ public class PhotoAlbumModel { } /** - * Deletes a photo from the album by name. - * If the deleted photo is the current photo or the album is empty, - * the iterator is reset. + * Deletes a photo from the album by name (if it exists). + * Resets the iterator and notifies the listeners. * * @param name the name of the photo to delete */ public void deletePhoto(String name) { - Photo currentPhoto = iterator.current(); photos.removeIf(photo -> photo.name().equals(name)); - if (photos.isEmpty() || (currentPhoto != null && currentPhoto.name().equals(name))) { - iterator = new PhotoIterator(photos); - } + iterator = new PhotoIterator(photos); notifyListeners(); }