Set Sone of an album in the album builder, use album builder to add albums.
[Sone.git] / src / main / java / net / pterodactylus / sone / database / memory / MemoryDatabase.java
index bc96715..fa29e64 100644 (file)
@@ -35,6 +35,7 @@ import java.util.concurrent.locks.ReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
 import net.pterodactylus.sone.data.Album;
+import net.pterodactylus.sone.data.Image;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.PostReply;
 import net.pterodactylus.sone.data.Reply;
@@ -102,6 +103,8 @@ public class MemoryDatabase extends AbstractService implements Database {
 
        private final Map<String, Album> allAlbums = new HashMap<String, Album>();
 
+       private final Map<String, Image> allImages = new HashMap<String, Image>();
+
        /**
         * Creates a new memory database.
         *
@@ -454,6 +457,44 @@ public class MemoryDatabase extends AbstractService implements Database {
        }
 
        //
+       // IMAGEPROVIDER METHODS
+       //
+
+       @Override
+       public Optional<Image> getImage(String imageId) {
+               lock.readLock().lock();
+               try {
+                       return fromNullable(allImages.get(imageId));
+               } finally {
+                       lock.readLock().unlock();
+               }
+       }
+
+       //
+       // IMAGESTORE METHODS
+       //
+
+       @Override
+       public void storeImage(Image image) {
+               lock.writeLock().lock();
+               try {
+                       allImages.put(image.getId(), image);
+               } finally {
+                       lock.writeLock().unlock();
+               }
+       }
+
+       @Override
+       public void removeImage(Image image) {
+               lock.writeLock().lock();
+               try {
+                       allImages.remove(image.getId());
+               } finally {
+                       lock.writeLock().unlock();
+               }
+       }
+
+       //
        // PACKAGE-PRIVATE METHODS
        //