From ba270a5f7762293fcb07758b16ee30db84a1c766 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 15 Oct 2013 06:19:12 +0200 Subject: [PATCH] Make image moving methods publicly available in the database. --- .../pterodactylus/sone/database/ImageDatabase.java | 5 +- .../sone/database/memory/MemoryDatabase.java | 62 +++++++++++----------- 2 files changed, 36 insertions(+), 31 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/database/ImageDatabase.java b/src/main/java/net/pterodactylus/sone/database/ImageDatabase.java index e1aa28c..ad1518b 100644 --- a/src/main/java/net/pterodactylus/sone/database/ImageDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/ImageDatabase.java @@ -17,6 +17,8 @@ package net.pterodactylus.sone.database; +import net.pterodactylus.sone.data.Image; + /** * Combines an {@link ImageProvider}, an {@link ImageBuilderFactory}, and an * {@link ImageStore} into an image database. @@ -25,6 +27,7 @@ package net.pterodactylus.sone.database; */ public interface ImageDatabase extends ImageProvider, ImageStore { - /* nothing here. */ + void moveUp(Image image); + void moveDown(Image image); } 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 538d97f..9114182 100644 --- a/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java @@ -542,6 +542,38 @@ public class MemoryDatabase extends AbstractService implements Database { } } + @Override + public void moveUp(Image image) { + lock.writeLock().lock(); + try { + List images = albumImages.get(image.getAlbum().getId()); + int currentIndex = images.indexOf(image.getId()); + if (currentIndex == 0) { + return; + } + images.remove(image.getId()); + images.add(currentIndex - 1, image.getId()); + } finally { + lock.writeLock().unlock(); + } + } + + @Override + public void moveDown(Image image) { + lock.writeLock().lock(); + try { + List images = albumChildren.get(image.getAlbum().getId()); + int currentIndex = images.indexOf(image.getId()); + if (currentIndex == (images.size() - 1)) { + return; + } + images.remove(image.getId()); + images.add(currentIndex + 1, image.getId()); + } finally { + lock.writeLock().unlock(); + } + } + // // IMAGESTORE METHODS // @@ -677,36 +709,6 @@ public class MemoryDatabase extends AbstractService implements Database { } } - void moveUp(Image image) { - lock.writeLock().lock(); - try { - List images = albumImages.get(image.getAlbum().getId()); - int currentIndex = images.indexOf(image.getId()); - if (currentIndex == 0) { - return; - } - images.remove(image.getId()); - images.add(currentIndex - 1, image.getId()); - } finally { - lock.writeLock().unlock(); - } - } - - void moveDown(Image image) { - lock.writeLock().lock(); - try { - List images = albumChildren.get(image.getAlbum().getId()); - int currentIndex = images.indexOf(image.getId()); - if (currentIndex == (images.size() - 1)) { - return; - } - images.remove(image.getId()); - images.add(currentIndex + 1, image.getId()); - } finally { - lock.writeLock().unlock(); - } - } - // // PRIVATE METHODS // -- 2.7.4