Compare commits

...

1 Commits

View File

@ -59,18 +59,14 @@ public class PhotoAlbumModel {
} }
/** /**
* Deletes a photo from the album by name. * Deletes a photo from the album by name (if it exists).
* If the deleted photo is the current photo or the album is empty, * Resets the iterator and notifies the listeners.
* the iterator is reset.
* *
* @param name the name of the photo to delete * @param name the name of the photo to delete
*/ */
public void deletePhoto(String name) { public void deletePhoto(String name) {
Photo currentPhoto = iterator.current();
photos.removeIf(photo -> photo.name().equals(name)); 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(); notifyListeners();
} }