From 9d3c14d143ff559ba08181fbba9007ae3be9c93a Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Wed, 16 Oct 2013 20:16:16 +0200 Subject: [PATCH] Move PostProvider and PostStore into PostDatabase. --- .../java/net/pterodactylus/sone/core/Core.java | 6 +- .../pterodactylus/sone/database/PostDatabase.java | 77 ++++++++++++++++++++-- .../pterodactylus/sone/database/PostProvider.java | 61 ----------------- .../net/pterodactylus/sone/database/PostStore.java | 69 ------------------- .../net/pterodactylus/sone/main/SonePlugin.java | 2 - 5 files changed, 74 insertions(+), 141 deletions(-) delete mode 100644 src/main/java/net/pterodactylus/sone/database/PostProvider.java delete mode 100644 src/main/java/net/pterodactylus/sone/database/PostStore.java diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index ed75f5e..21448b6 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -72,7 +72,6 @@ import net.pterodactylus.sone.database.DatabaseException; import net.pterodactylus.sone.database.ImageBuilder.ImageCreated; import net.pterodactylus.sone.database.PostBuilder; import net.pterodactylus.sone.database.PostBuilder.PostCreated; -import net.pterodactylus.sone.database.PostProvider; import net.pterodactylus.sone.database.PostReplyBuilder; import net.pterodactylus.sone.database.PostReplyBuilder.PostReplyCreated; import net.pterodactylus.sone.database.PostReplyProvider; @@ -115,7 +114,7 @@ import com.google.inject.Inject; * * @author David ‘Bombe’ Roden */ -public class Core extends AbstractService implements SoneProvider, PostProvider, PostReplyProvider { +public class Core extends AbstractService implements SoneProvider, PostReplyProvider { /** The logger. */ private static final Logger logger = Logging.getLogger(Core.class); @@ -437,17 +436,14 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, return trustedIdentities.containsEntry(origin.getIdentity(), target.getIdentity()); } - @Override public Optional getPost(String postId) { return database.getPost(postId); } - @Override public Collection getPosts(String soneId) { return database.getPosts(soneId); } - @Override public Collection getDirectedPosts(final String recipientId) { checkNotNull(recipientId, "recipient must not be null"); return database.getDirectedPosts(recipientId); diff --git a/src/main/java/net/pterodactylus/sone/database/PostDatabase.java b/src/main/java/net/pterodactylus/sone/database/PostDatabase.java index 0832807..7bfa33a 100644 --- a/src/main/java/net/pterodactylus/sone/database/PostDatabase.java +++ b/src/main/java/net/pterodactylus/sone/database/PostDatabase.java @@ -17,14 +17,83 @@ package net.pterodactylus.sone.database; +import java.util.Collection; + +import net.pterodactylus.sone.data.Post; +import net.pterodactylus.sone.data.Sone; + +import com.google.common.base.Optional; + /** - * Combines a {@link PostProvider}, a {@link PostBuilderFactory}, and a - * {@link PostStore} into a complete post database. + * Database for handling {@link Post}s. * * @author David ‘Bombe’ Roden */ -public interface PostDatabase extends PostProvider, PostStore { +public interface PostDatabase { + + /** + * Returns the post with the given ID. + * + * @param postId + * The ID of the post to return + * @return The post with the given ID, or {@code null} + */ + Optional getPost(String postId); + + /** + * Returns all posts from the given Sone. + * + * @param soneId + * The ID of the Sone + * @return All posts from the given Sone + */ + Collection getPosts(String soneId); + + /** + * Returns all posts that have the given Sone as recipient. + * + * @see Post#getRecipient() + * @param recipientId + * The ID of the recipient of the posts + * @return All posts that have the given Sone as recipient + */ + Collection getDirectedPosts(String recipientId); + + /** + * Adds the given post to the store. + * + * @param post + * The post to store + */ + void storePost(Post post); + + /** + * Removes the given post. + * + * @param post + * The post to remove + */ + void removePost(Post post); + + /** + * Stores the given posts as all posts of a single {@link Sone}. This method + * will removed all other posts from the Sone! + * + * @param sone + * The Sone to store the posts for + * @param posts + * The posts to store + * @throws IllegalArgumentException + * if posts do not all belong to the same Sone + */ + void storePosts(Sone sone, Collection posts) throws IllegalArgumentException; - /* nothing here. */ + /** + * Removes all posts of the given {@link Sone} + * + * @param sone + * The Sone to remove all posts for + */ + void removePosts(Sone sone); } diff --git a/src/main/java/net/pterodactylus/sone/database/PostProvider.java b/src/main/java/net/pterodactylus/sone/database/PostProvider.java deleted file mode 100644 index 740373e..0000000 --- a/src/main/java/net/pterodactylus/sone/database/PostProvider.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Sone - PostProvider.java - Copyright © 2011–2013 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.sone.database; - -import java.util.Collection; - -import net.pterodactylus.sone.data.Post; - -import com.google.common.base.Optional; - -/** - * Interface for objects that can provide {@link Post}s by their ID. - * - * @author David ‘Bombe’ Roden - */ -public interface PostProvider { - - /** - * Returns the post with the given ID. - * - * @param postId - * The ID of the post to return - * @return The post with the given ID, or {@code null} - */ - public Optional getPost(String postId); - - /** - * Returns all posts from the given Sone. - * - * @param soneId - * The ID of the Sone - * @return All posts from the given Sone - */ - public Collection getPosts(String soneId); - - /** - * Returns all posts that have the given Sone as recipient. - * - * @see Post#getRecipient() - * @param recipientId - * The ID of the recipient of the posts - * @return All posts that have the given Sone as recipient - */ - public Collection getDirectedPosts(String recipientId); - -} diff --git a/src/main/java/net/pterodactylus/sone/database/PostStore.java b/src/main/java/net/pterodactylus/sone/database/PostStore.java deleted file mode 100644 index 9c2ca42..0000000 --- a/src/main/java/net/pterodactylus/sone/database/PostStore.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Sone - PostStore.java - Copyright © 2013 David Roden - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package net.pterodactylus.sone.database; - -import java.util.Collection; - -import net.pterodactylus.sone.data.Post; -import net.pterodactylus.sone.data.Sone; - -/** - * Interface for a store for posts. - * - * @author David ‘Bombe’ Roden - */ -public interface PostStore { - - /** - * Adds the given post to the store. - * - * @param post - * The post to store - */ - public void storePost(Post post); - - /** - * Removes the given post. - * - * @param post - * The post to remove - */ - public void removePost(Post post); - - /** - * Stores the given posts as all posts of a single {@link Sone}. This method - * will removed all other posts from the Sone! - * - * @param sone - * The Sone to store the posts for - * @param posts - * The posts to store - * @throws IllegalArgumentException - * if posts do not all belong to the same Sone - */ - public void storePosts(Sone sone, Collection posts) throws IllegalArgumentException; - - /** - * Removes all posts of the given {@link Sone} - * - * @param sone - * The Sone to remove all posts for - */ - public void removePosts(Sone sone); - -} diff --git a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java index a3c3d80..94e5030 100644 --- a/src/main/java/net/pterodactylus/sone/main/SonePlugin.java +++ b/src/main/java/net/pterodactylus/sone/main/SonePlugin.java @@ -26,7 +26,6 @@ import net.pterodactylus.sone.core.Core; import net.pterodactylus.sone.core.FreenetInterface; import net.pterodactylus.sone.core.WebOfTrustUpdater; import net.pterodactylus.sone.database.Database; -import net.pterodactylus.sone.database.PostProvider; import net.pterodactylus.sone.database.SoneProvider; import net.pterodactylus.sone.database.memory.MemoryDatabase; import net.pterodactylus.sone.fcp.FcpInterface; @@ -222,7 +221,6 @@ public class SonePlugin implements FredPlugin, FredPluginFCP, FredPluginL10n, Fr bind(FcpInterface.class).in(Singleton.class); bind(Database.class).to(MemoryDatabase.class); bind(SoneProvider.class).to(Core.class).in(Singleton.class); - bind(PostProvider.class).to(MemoryDatabase.class); bindListener(Matchers.any(), new TypeListener() { @Override -- 2.7.4