From e71cce762443757a193067b13a82fb7ae92b28b2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 21 Sep 2011 07:47:29 +0200 Subject: [PATCH] Ensure that an image is always set as album image, unless the album is empty. --- src/main/java/net/pterodactylus/sone/data/Album.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/data/Album.java b/src/main/java/net/pterodactylus/sone/data/Album.java index 5e5d08a..89823a8 100644 --- a/src/main/java/net/pterodactylus/sone/data/Album.java +++ b/src/main/java/net/pterodactylus/sone/data/Album.java @@ -166,6 +166,9 @@ public class Album implements Fingerprintable { image.getAlbum().removeImage(image); } image.setAlbum(this); + if (images.isEmpty()) { + albumImage = image.getId(); + } if (!images.containsKey(image.getId())) { images.put(image.getId(), image); } @@ -180,6 +183,13 @@ public class Album implements Fingerprintable { public void removeImage(Image image) { Validation.begin().isNotNull("Image", image).check().isEqual("Image Owner", image.getSone(), sone).check(); images.remove(image); + if (image.getId().equals(albumImage)) { + if (images.isEmpty()) { + albumImage = null; + } else { + albumImage = images.values().iterator().next().getId(); + } + } } /** -- 2.7.4