Add method to delete an album.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 13 Apr 2011 03:54:19 +0000 (05:54 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 13 Apr 2011 04:41:06 +0000 (06:41 +0200)
src/main/java/net/pterodactylus/sone/core/Core.java

index c30aef6..f8cee11 100644 (file)
@@ -1847,6 +1847,29 @@ public class Core implements IdentityListener, UpdateListener, ImageInsertListen
        }
 
        /**
+        * Deletes the given album. The owner of the album has to be a local Sone,
+        * and the album has to be {@link Album#isEmpty() empty} to be deleted.
+        *
+        * @param album
+        *            The album to remove
+        */
+       public void deleteAlbum(Album album) {
+               Validation.begin().isNotNull("Album", album).check().is("Local Sone", isLocalSone(album.getSone())).check();
+               if (!album.isEmpty()) {
+                       return;
+               }
+               if (album.getParent() == null) {
+                       album.getSone().removeAlbum(album);
+               } else {
+                       album.getParent().removeAlbum(album);
+               }
+               synchronized (albums) {
+                       albums.remove(album.getId());
+               }
+               saveSone(album.getSone());
+       }
+
+       /**
         * Creates a new image.
         *
         * @param sone