From: David ‘Bombe’ Roden Date: Tue, 15 Oct 2013 04:42:08 +0000 (+0200) Subject: Expose album moving methods in the album database. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=592b5d6d1ccc49bb4d95d36eb0eca807afcbaa4c;p=Sone.git Expose album moving methods in the album database. --- diff --git a/src/main/java/net/pterodactylus/sone/database/AlbumDatabase.java b/src/main/java/net/pterodactylus/sone/database/AlbumDatabase.java index 446debc..f07523b 100644 --- a/src/main/java/net/pterodactylus/sone/database/AlbumDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/AlbumDatabase.java @@ -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); } diff --git a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java index 9114182..9a2637d 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java @@ -492,6 +492,38 @@ public class MemoryDatabase extends AbstractService implements Database { } } + @Override + public void moveUp(Album album) { + lock.writeLock().lock(); + try { + List 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 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 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 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 //