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 77ff2f4..fa29e64 100644 (file)
@@ -35,12 +35,11 @@ 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;
 import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.data.impl.AlbumBuilderImpl;
-import net.pterodactylus.sone.database.AlbumBuilder;
 import net.pterodactylus.sone.database.Database;
 import net.pterodactylus.sone.database.DatabaseException;
 import net.pterodactylus.sone.database.PostBuilder;
@@ -104,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.
         *
@@ -432,33 +433,62 @@ public class MemoryDatabase extends AbstractService implements Database {
        }
 
        //
-       // ALBUMBUILDERFACTORY METHODS
+       // ALBUMSTORE METHODS
        //
 
        @Override
-       public AlbumBuilder newAlbumBuilder() {
-               return new AlbumBuilderImpl();
+       public void storeAlbum(Album album) {
+               lock.writeLock().lock();
+               try {
+                       allAlbums.put(album.getId(), album);
+               } finally {
+                       lock.writeLock().unlock();
+               }
+       }
+
+       @Override
+       public void removeAlbum(Album album) {
+               lock.writeLock().lock();
+               try {
+                       allAlbums.remove(album.getId());
+               } finally {
+                       lock.writeLock().unlock();
+               }
        }
 
        //
-       // ALBUMSTORE METHODS
+       // IMAGEPROVIDER METHODS
        //
 
        @Override
-       public void storeAlbum(Album album) {
+       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 {
-                       allAlbums.put(album.getId(), album);
+                       allImages.put(image.getId(), image);
                } finally {
                        lock.writeLock().unlock();
                }
        }
 
        @Override
-       public void removeAlbum(Album album) {
+       public void removeImage(Image image) {
                lock.writeLock().lock();
                try {
-                       allAlbums.remove(album.getId());
+                       allImages.remove(image.getId());
                } finally {
                        lock.writeLock().unlock();
                }