From: David ‘Bombe’ Roden Date: Wed, 21 Sep 2011 05:47:29 +0000 (+0200) Subject: Ensure that an image is always set as album image, unless the album is empty. X-Git-Tag: 0.7^2~2^2~59 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=e71cce762443757a193067b13a82fb7ae92b28b2;p=Sone.git Ensure that an image is always set as album image, unless the album is empty. --- 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(); + } + } } /**