Add modifier to post replies to mark them known.
[Sone.git] / src / main / java / net / pterodactylus / sone / database / memory / MemoryDatabase.java
index 538d97f..8cff1be 100644 (file)
@@ -46,9 +46,7 @@ import net.pterodactylus.sone.data.Reply;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.database.Database;
 import net.pterodactylus.sone.database.DatabaseException;
-import net.pterodactylus.sone.database.PostBuilder;
 import net.pterodactylus.sone.database.PostDatabase;
-import net.pterodactylus.sone.database.PostReplyBuilder;
 import net.pterodactylus.sone.database.SoneBuilder;
 import net.pterodactylus.util.config.Configuration;
 import net.pterodactylus.util.config.ConfigurationException;
@@ -128,12 +126,6 @@ public class MemoryDatabase extends AbstractService implements Database {
        // DATABASE METHODS
        //
 
-       /**
-        * Saves the database.
-        *
-        * @throws DatabaseException
-        *              if an error occurs while saving
-        */
        @Override
        public void save() throws DatabaseException {
                saveKnownPosts();
@@ -144,7 +136,6 @@ public class MemoryDatabase extends AbstractService implements Database {
        // SERVICE METHODS
        //
 
-       /** {@inheritDocs} */
        @Override
        protected void doStart() {
                loadKnownPosts();
@@ -152,7 +143,6 @@ public class MemoryDatabase extends AbstractService implements Database {
                notifyStarted();
        }
 
-       /** {@inheritDocs} */
        @Override
        protected void doStop() {
                try {
@@ -212,7 +202,6 @@ public class MemoryDatabase extends AbstractService implements Database {
        // POSTPROVIDER METHODS
        //
 
-       /** {@inheritDocs} */
        @Override
        public Optional<Post> getPost(String postId) {
                lock.readLock().lock();
@@ -223,13 +212,11 @@ public class MemoryDatabase extends AbstractService implements Database {
                }
        }
 
-       /** {@inheritDocs} */
        @Override
        public Collection<Post> getPosts(String soneId) {
                return new HashSet<Post>(getPostsFrom(soneId));
        }
 
-       /** {@inheritDocs} */
        @Override
        public Collection<Post> getDirectedPosts(String recipientId) {
                lock.readLock().lock();
@@ -242,20 +229,9 @@ public class MemoryDatabase extends AbstractService implements Database {
        }
 
        //
-       // POSTBUILDERFACTORY METHODS
-       //
-
-       /** {@inheritDocs} */
-       @Override
-       public PostBuilder newPostBuilder() {
-               return new MemoryPostBuilder(this);
-       }
-
-       //
        // POSTSTORE METHODS
        //
 
-       /** {@inheritDocs} */
        @Override
        public void storePost(Post post) {
                checkNotNull(post, "post must not be null");
@@ -271,7 +247,6 @@ public class MemoryDatabase extends AbstractService implements Database {
                }
        }
 
-       /** {@inheritDocs} */
        @Override
        public void removePost(Post post) {
                checkNotNull(post, "post must not be null");
@@ -288,7 +263,6 @@ public class MemoryDatabase extends AbstractService implements Database {
                }
        }
 
-       /** {@inheritDocs} */
        @Override
        public void storePosts(Sone sone, Collection<Post> posts) throws IllegalArgumentException {
                checkNotNull(sone, "sone must not be null");
@@ -323,7 +297,6 @@ public class MemoryDatabase extends AbstractService implements Database {
                }
        }
 
-       /** {@inheritDocs} */
        @Override
        public void removePosts(Sone sone) {
                checkNotNull(sone, "sone must not be null");
@@ -346,7 +319,6 @@ public class MemoryDatabase extends AbstractService implements Database {
        // POSTREPLYPROVIDER METHODS
        //
 
-       /** {@inheritDocs} */
        @Override
        public Optional<PostReply> getPostReply(String id) {
                lock.readLock().lock();
@@ -357,7 +329,6 @@ public class MemoryDatabase extends AbstractService implements Database {
                }
        }
 
-       /** {@inheritDocs} */
        @Override
        public List<PostReply> getReplies(String postId) {
                lock.readLock().lock();
@@ -372,20 +343,36 @@ public class MemoryDatabase extends AbstractService implements Database {
        }
 
        //
-       // POSTREPLYBUILDERFACTORY METHODS
+       // POSTREPLYSTORE METHODS
        //
 
-       /** {@inheritDocs} */
-       @Override
-       public PostReplyBuilder newPostReplyBuilder() {
-               return new MemoryPostReplyBuilder(this, this);
+       /**
+        * Returns whether the given post reply is known.
+        *
+        * @param postReply
+        *              The post reply
+        * @return {@code true} if the given post reply is known, {@code false}
+        *         otherwise
+        */
+       public boolean isPostReplyKnown(PostReply postReply) {
+               lock.readLock().lock();
+               try {
+                       return knownPostReplies.contains(postReply.getId());
+               } finally {
+                       lock.readLock().unlock();
+               }
        }
 
-       //
-       // POSTREPLYSTORE METHODS
-       //
+       @Override
+       public void setPostReplyKnown(PostReply postReply) {
+               lock.writeLock().lock();
+               try {
+                       knownPostReplies.add(postReply.getId());
+               } finally {
+                       lock.writeLock().unlock();
+               }
+       }
 
-       /** {@inheritDocs} */
        @Override
        public void storePostReply(PostReply postReply) {
                lock.writeLock().lock();
@@ -403,7 +390,6 @@ public class MemoryDatabase extends AbstractService implements Database {
                }
        }
 
-       /** {@inheritDocs} */
        @Override
        public void storePostReplies(Sone sone, Collection<PostReply> postReplies) {
                checkNotNull(sone, "sone must not be null");
@@ -436,7 +422,6 @@ public class MemoryDatabase extends AbstractService implements Database {
                }
        }
 
-       /** {@inheritDocs} */
        @Override
        public void removePostReply(PostReply postReply) {
                lock.writeLock().lock();
@@ -453,7 +438,6 @@ public class MemoryDatabase extends AbstractService implements Database {
                }
        }
 
-       /** {@inheritDocs} */
        @Override
        public void removePostReplies(Sone sone) {
                checkNotNull(sone, "sone must not be null");
@@ -492,6 +476,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
        //
@@ -542,6 +558,38 @@ public class MemoryDatabase extends AbstractService implements Database {
                }
        }
 
+       @Override
+       public void moveUp(Image image) {
+               lock.writeLock().lock();
+               try {
+                       List<String> 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<String> 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
        //
@@ -609,104 +657,6 @@ public class MemoryDatabase extends AbstractService implements Database {
                }
        }
 
-       /**
-        * Returns whether the given post reply is known.
-        *
-        * @param postReply
-        *              The post reply
-        * @return {@code true} if the given post reply is known, {@code false}
-        *         otherwise
-        */
-       boolean isPostReplyKnown(PostReply postReply) {
-               lock.readLock().lock();
-               try {
-                       return knownPostReplies.contains(postReply.getId());
-               } finally {
-                       lock.readLock().unlock();
-               }
-       }
-
-       /**
-        * Sets whether the given post reply is known.
-        *
-        * @param postReply
-        *              The post reply
-        * @param known
-        *              {@code true} if the post reply is known, {@code false} otherwise
-        */
-       void setPostReplyKnown(PostReply postReply, boolean known) {
-               lock.writeLock().lock();
-               try {
-                       if (known) {
-                               knownPostReplies.add(postReply.getId());
-                       } else {
-                               knownPostReplies.remove(postReply.getId());
-                       }
-               } finally {
-                       lock.writeLock().unlock();
-               }
-       }
-
-       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();
-               }
-       }
-
-       void moveUp(Image image) {
-               lock.writeLock().lock();
-               try {
-                       List<String> 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<String> 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
        //