Expose album moving methods in the album database.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 15 Oct 2013 04:42:08 +0000 (06:42 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Feb 2014 21:25:26 +0000 (22:25 +0100)
src/main/java/net/pterodactylus/sone/database/AlbumDatabase.java
src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java

index 446debc..f07523b 100644 (file)
@@ -17,6 +17,8 @@
 
 package net.pterodactylus.sone.database;
 
+import net.pterodactylus.sone.data.Album;
+
 /**
  * Combines an {@link AlbumProvider} and an {@link AlbumStore} into an album
  * database.
@@ -25,6 +27,7 @@ package net.pterodactylus.sone.database;
  */
 public interface AlbumDatabase extends AlbumProvider, AlbumStore {
 
-       /* nothing here. */
+       void moveUp(Album album);
+       void moveDown(Album album);
 
 }
index 9114182..9a2637d 100644 (file)
@@ -492,6 +492,38 @@ public class MemoryDatabase extends AbstractService implements Database {
                }
        }
 
+       @Override
+       public void moveUp(Album album) {
+               lock.writeLock().lock();
+               try {
+                       List<String> albums = albumChildren.get(album.getParent().getId());
+                       int currentIndex = albums.indexOf(album.getId());
+                       if (currentIndex == 0) {
+                               return;
+                       }
+                       albums.remove(album.getId());
+                       albums.add(currentIndex - 1, album.getId());
+               } finally {
+                       lock.writeLock().unlock();
+               }
+       }
+
+       @Override
+       public void moveDown(Album album) {
+               lock.writeLock().lock();
+               try {
+                       List<String> albums = albumChildren.get(album.getParent().getId());
+                       int currentIndex = albums.indexOf(album.getId());
+                       if (currentIndex == (albums.size() - 1)) {
+                               return;
+                       }
+                       albums.remove(album.getId());
+                       albums.add(currentIndex + 1, album.getId());
+               } finally {
+                       lock.writeLock().unlock();
+               }
+       }
+
        //
        // ALBUMSTORE METHODS
        //
@@ -679,36 +711,6 @@ public class MemoryDatabase extends AbstractService implements Database {
                }
        }
 
-       void moveUp(Album album) {
-               lock.writeLock().lock();
-               try {
-                       List<String> albums = albumChildren.get(album.getParent().getId());
-                       int currentIndex = albums.indexOf(album.getId());
-                       if (currentIndex == 0) {
-                               return;
-                       }
-                       albums.remove(album.getId());
-                       albums.add(currentIndex - 1, album.getId());
-               } finally {
-                       lock.writeLock().unlock();
-               }
-       }
-
-       void moveDown(Album album) {
-               lock.writeLock().lock();
-               try {
-                       List<String> albums = albumChildren.get(album.getParent().getId());
-                       int currentIndex = albums.indexOf(album.getId());
-                       if (currentIndex == (albums.size() - 1)) {
-                               return;
-                       }
-                       albums.remove(album.getId());
-                       albums.add(currentIndex + 1, album.getId());
-               } finally {
-                       lock.writeLock().unlock();
-               }
-       }
-
        //
        // PRIVATE METHODS
        //