Ensure that an image is always set as album image, unless the album is empty.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 21 Sep 2011 05:47:29 +0000 (07:47 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 21 Sep 2011 05:47:29 +0000 (07:47 +0200)
src/main/java/net/pterodactylus/sone/data/Album.java

index 5e5d08a..89823a8 100644 (file)
@@ -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();
+                       }
+               }
        }
 
        /**