Merge branch 'partial-rewrite' into less-critical
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 26 Jan 2013 11:35:09 +0000 (12:35 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 26 Jan 2013 11:35:09 +0000 (12:35 +0100)
Conflicts:
src/main/java/net/pterodactylus/sone/data/impl/DefaultPostBuilderFactory.java
src/main/java/net/pterodactylus/sone/text/SoneTextParser.java

46 files changed:
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/core/PostProvider.java [deleted file]
src/main/java/net/pterodactylus/sone/core/PostReplyProvider.java [deleted file]
src/main/java/net/pterodactylus/sone/core/SoneDownloader.java
src/main/java/net/pterodactylus/sone/core/SoneProvider.java [deleted file]
src/main/java/net/pterodactylus/sone/data/PostBuilder.java [deleted file]
src/main/java/net/pterodactylus/sone/data/PostBuilderFactory.java [deleted file]
src/main/java/net/pterodactylus/sone/data/PostReplyBuilder.java [deleted file]
src/main/java/net/pterodactylus/sone/data/PostReplyBuilderFactory.java [deleted file]
src/main/java/net/pterodactylus/sone/data/ReplyBuilder.java [deleted file]
src/main/java/net/pterodactylus/sone/data/impl/AbstractReplyBuilder.java
src/main/java/net/pterodactylus/sone/data/impl/DefaultPostBuilderFactory.java
src/main/java/net/pterodactylus/sone/data/impl/DefaultPostReplyBuilderFactory.java
src/main/java/net/pterodactylus/sone/data/impl/PostBuilderImpl.java
src/main/java/net/pterodactylus/sone/data/impl/PostImpl.java
src/main/java/net/pterodactylus/sone/data/impl/PostReplyBuilderImpl.java
src/main/java/net/pterodactylus/sone/data/impl/PostReplyImpl.java
src/main/java/net/pterodactylus/sone/data/impl/ReplyImpl.java
src/main/java/net/pterodactylus/sone/database/PostBuilder.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/database/PostBuilderFactory.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/database/PostProvider.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/database/PostReplyBuilder.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/database/PostReplyBuilderFactory.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/database/PostReplyProvider.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/database/ReplyBuilder.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/database/SoneProvider.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/fcp/AbstractSoneCommand.java
src/main/java/net/pterodactylus/sone/fcp/GetPostFeedCommand.java
src/main/java/net/pterodactylus/sone/main/SonePlugin.java
src/main/java/net/pterodactylus/sone/template/ParserFilter.java
src/main/java/net/pterodactylus/sone/text/SoneTextParser.java
src/main/java/net/pterodactylus/sone/web/CreatePostPage.java
src/main/java/net/pterodactylus/sone/web/DistrustPage.java
src/main/java/net/pterodactylus/sone/web/ImageBrowserPage.java
src/main/java/net/pterodactylus/sone/web/MarkAsKnownPage.java
src/main/java/net/pterodactylus/sone/web/SearchPage.java
src/main/java/net/pterodactylus/sone/web/TrustPage.java
src/main/java/net/pterodactylus/sone/web/UntrustPage.java
src/main/java/net/pterodactylus/sone/web/ViewSonePage.java
src/main/java/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/DistrustAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/GetStatusAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/MarkAsKnownAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/TrustAjaxPage.java
src/main/java/net/pterodactylus/sone/web/ajax/UntrustAjaxPage.java
src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java

index e46eceb..fa98bbb 100644 (file)
@@ -56,17 +56,20 @@ import net.pterodactylus.sone.data.Album;
 import net.pterodactylus.sone.data.Client;
 import net.pterodactylus.sone.data.Image;
 import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.sone.data.PostBuilder;
-import net.pterodactylus.sone.data.PostBuilderFactory;
 import net.pterodactylus.sone.data.PostReply;
-import net.pterodactylus.sone.data.PostReplyBuilder;
-import net.pterodactylus.sone.data.PostReplyBuilderFactory;
 import net.pterodactylus.sone.data.Profile;
 import net.pterodactylus.sone.data.Profile.Field;
 import net.pterodactylus.sone.data.Reply;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.data.Sone.ShowCustomAvatars;
 import net.pterodactylus.sone.data.Sone.SoneStatus;
+import net.pterodactylus.sone.database.PostBuilder;
+import net.pterodactylus.sone.database.PostBuilderFactory;
+import net.pterodactylus.sone.database.PostProvider;
+import net.pterodactylus.sone.database.PostReplyBuilder;
+import net.pterodactylus.sone.database.PostReplyBuilderFactory;
+import net.pterodactylus.sone.database.PostReplyProvider;
+import net.pterodactylus.sone.database.SoneProvider;
 import net.pterodactylus.sone.data.TemporaryImage;
 import net.pterodactylus.sone.fcp.FcpInterface;
 import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired;
@@ -361,30 +364,9 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
         * @return The Sone with the given ID, or {@code null} if there is no such
         *         Sone
         */
-       public Sone getSone(String id) {
-               return getSone(id, true);
-       }
-
-       /**
-        * Returns the Sone with the given ID, regardless whether it’s local or
-        * remote.
-        *
-        * @param id
-        *            The ID of the Sone to get
-        * @param create
-        *            {@code true} to create a new Sone if none exists,
-        *            {@code false} to return {@code null} if a Sone with the given
-        *            ID does not exist
-        * @return The Sone with the given ID, or {@code null} if there is no such
-        *         Sone
-        */
        @Override
-       public Sone getSone(String id, boolean create) {
+       public Sone getSone(String id) {
                synchronized (sones) {
-                       if (!sones.containsKey(id) && create) {
-                               Sone sone = new Sone(id, false);
-                               sones.put(id, sone);
-                       }
                        return sones.get(id);
                }
        }
@@ -545,26 +527,21 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
        }
 
        /**
-        * Returns all posts that have the given Sone as recipient.
-        *
-        * @see Post#getRecipient()
-        * @param recipient
-        *            The recipient of the posts
-        * @return All posts that have the given Sone as recipient
+        * {@inheritDoc}
         */
-       public Set<Post> getDirectedPosts(Sone recipient) {
-               checkNotNull(recipient, "recipient must not be null");
-               Set<Post> directedPosts = new HashSet<Post>();
+       @Override
+       public Collection<Post> getDirectedPosts(final String recipientId) {
+               checkNotNull(recipientId, "recipient must not be null");
                synchronized (posts) {
-                       for (Post post : posts.values()) {
-                               if (recipient.equals(post.getRecipient())) {
-                                       directedPosts.add(post);
+                       return Collections2.filter(posts.values(), new Predicate<Post>() {
+
+                               @Override
+                               public boolean apply(Post post) {
+                                       return (post.getRecipient() != null) && (post.getRecipient().getId().equals(recipientId));
                                }
-                       }
+                       });
                }
-               return directedPosts;
        }
-
        /**
         * Returns a post reply builder.
         *
@@ -2333,7 +2310,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider,
                        /* some local identity still trusts this identity, don’t remove. */
                        return;
                }
-               Sone sone = getSone(identity.getId(), false);
+               Sone sone = getSone(identity.getId());
                if (sone == null) {
                        /* TODO - we don’t have the Sone anymore. should this happen? */
                        return;
diff --git a/src/main/java/net/pterodactylus/sone/core/PostProvider.java b/src/main/java/net/pterodactylus/sone/core/PostProvider.java
deleted file mode 100644 (file)
index 19a0e5d..0000000
+++ /dev/null
@@ -1,40 +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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.core;
-
-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 <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-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<Post> getPost(String postId);
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/core/PostReplyProvider.java b/src/main/java/net/pterodactylus/sone/core/PostReplyProvider.java
deleted file mode 100644 (file)
index 5decdc7..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Sone - PostReplyProvider.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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.core;
-
-import java.util.List;
-
-import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.sone.data.PostReply;
-
-import com.google.common.base.Optional;
-
-/**
- * Interface for objects that can provide {@link PostReply}s.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public interface PostReplyProvider {
-
-       /**
-        * Returns the reply with the given ID.
-        *
-        * @param id
-        *            The ID of the reply to get
-        * @return The reply, or {@code null} if there is no such reply
-        */
-       public Optional<PostReply> getPostReply(String id);
-
-       /**
-        * Returns all replies for the given post, order ascending by time.
-        *
-        * @param post
-        *            The post to get all replies for
-        * @return All replies for the given post
-        */
-       public List<PostReply> getReplies(Post post);
-
-}
index abdea0d..f493fdc 100644 (file)
@@ -31,12 +31,12 @@ import net.pterodactylus.sone.data.Album;
 import net.pterodactylus.sone.data.Client;
 import net.pterodactylus.sone.data.Image;
 import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.sone.data.PostBuilder;
 import net.pterodactylus.sone.data.PostReply;
-import net.pterodactylus.sone.data.PostReplyBuilder;
 import net.pterodactylus.sone.data.Profile;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.data.Sone.SoneStatus;
+import net.pterodactylus.sone.database.PostBuilder;
+import net.pterodactylus.sone.database.PostReplyBuilder;
 import net.pterodactylus.util.io.Closer;
 import net.pterodactylus.util.logging.Logging;
 import net.pterodactylus.util.number.Numbers;
diff --git a/src/main/java/net/pterodactylus/sone/core/SoneProvider.java b/src/main/java/net/pterodactylus/sone/core/SoneProvider.java
deleted file mode 100644 (file)
index 73edd0b..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Sone - SoneProvider.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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.core;
-
-import net.pterodactylus.sone.data.Sone;
-
-/**
- * Interface for objects that can provide {@link Sone}s by their ID.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public interface SoneProvider {
-
-       /**
-        * Returns the Sone with the given ID, if it exists. If it does not exist
-        * and {@code create} is {@code false}, {@code null} is returned; otherwise,
-        * a new Sone with the given ID is created and returned.
-        *
-        * @param soneId
-        *            The ID of the Sone to return
-        * @param create
-        *            {@code true} to create a new Sone if no Sone with the given ID
-        *            exists, {@code false} to return {@code null} instead
-        * @return The Sone with the given ID, or {@code null}
-        */
-       public Sone getSone(String soneId, boolean create);
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/data/PostBuilder.java b/src/main/java/net/pterodactylus/sone/data/PostBuilder.java
deleted file mode 100644 (file)
index 87d02ee..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Sone - PostBuilder.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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.data;
-
-/**
- * Builder for {@link Post} objects.
- * <p>
- * A {@link Post} consists of the following elements:
- * <ul>
- * <li>an ID,</li>
- * <li>a {@link Sone sender},</li>
- * <li>an optional {@link Sone recipient},</li>
- * <li>a time,</li>
- * <li>and a text.</li>
- * </ul>
- * Except for the recipient, all this elements have to be configured on this
- * builder. For the ID you have the possibility to configure either a random ID
- * (which should be used for new posts) or a custom ID you specify (for creating
- * an existing post). For the time you can use the current time (again, for
- * creating new posts) or the given time (for loading posts). It is an error to
- * specify both ways for either the ID or the time.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public interface PostBuilder {
-
-       /**
-        * Copies all attributes of the given post to this post builder.
-        *
-        * @param post
-        *            The post whose attributes to copy into this builder
-        * @return This builder
-        * @throws NullPointerException
-        *             if {@code post} is {@code null}
-        */
-       public PostBuilder copyPost(Post post) throws NullPointerException;
-
-       /**
-        * Configures this builder to use the given Sone as sender of the new post.
-        *
-        * @param senderId
-        *            The ID of the sender of the post
-        * @return This post builder
-        */
-       public PostBuilder from(String senderId);
-
-       /**
-        * Configures this builder to use a random ID for the new post. If this
-        * method is used, {@link #withId(String)} must not be used.
-        *
-        * @return This post builder
-        */
-       public PostBuilder randomId();
-
-       /**
-        * Configures this builder to use the given ID as ID for the new post. If
-        * this method is used, {@link #randomId()} must not be used.
-        *
-        * @param id
-        *            The ID to use for the post
-        * @return This post builder
-        */
-       public PostBuilder withId(String id);
-
-       /**
-        * Configures this builder to use the current time when creating the post.
-        * If this method is used, {@link #withTime(long)} must not be used.
-        *
-        * @return This post builder
-        */
-       public PostBuilder currentTime();
-
-       /**
-        * Configures the builder to use the given time as time for the new post. If
-        * this method is used, {@link #currentTime()} must not be used.
-        *
-        * @param time
-        *            The time to use for the post
-        * @return This post builder
-        */
-       public PostBuilder withTime(long time);
-
-       /**
-        * Configures the builder to use the given text for the new post.
-        *
-        * @param text
-        *            The text to use for the post
-        * @return This post builder
-        */
-       public PostBuilder withText(String text);
-
-       /**
-        * Configures the builder to use the given {@link Sone} as recipient for the
-        * post.
-        *
-        * @param recipientId
-        *            The ID of the recipient of the post
-        * @return This post builder
-        */
-       public PostBuilder to(String recipientId);
-
-       /**
-        * Verifies this builder’s configuration and creates a new post.
-        * <p>
-        * The following conditions must be met in order for this builder to be
-        * configured correctly:
-        * <ul>
-        * <li>Exactly one of {@link #randomId()} or {@link #withId(String)} must
-        * have been called.</li>
-        * <li>The {@link #from(String) sender} must not be {@code null}.</li>
-        * <li>Exactly one of {@link #currentTime()} or {@link #withTime(long)} must
-        * have been called.</li>
-        * <li>The {@link #withText(String) text} must not be {@code null} and must
-        * contain something other than whitespace.</li>
-        * <li>The {@link #to(String) recipient} must either not have been set, or
-        * it must have been set to a {@link Sone} other than {@link #from(String)
-        * the sender}.</li>
-        * </ul>
-        *
-        * @return A new post
-        * @throws IllegalStateException
-        *             if this builder’s configuration is not valid
-        */
-       public Post build() throws IllegalStateException;
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/data/PostBuilderFactory.java b/src/main/java/net/pterodactylus/sone/data/PostBuilderFactory.java
deleted file mode 100644 (file)
index 845cdf6..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Sone - PostBuilderFactory.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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.data;
-
-/**
- * Factory for {@link PostBuilder}s.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public interface PostBuilderFactory {
-
-       /**
-        * Creates a new post builder.
-        *
-        * @return A new post builder
-        */
-       public PostBuilder newPostBuilder();
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/data/PostReplyBuilder.java b/src/main/java/net/pterodactylus/sone/data/PostReplyBuilder.java
deleted file mode 100644 (file)
index 09eb98a..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Sone - PostReplyBuilder.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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.data;
-
-/**
- * Builder for a {@link PostReply} object.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public interface PostReplyBuilder extends ReplyBuilder<PostReplyBuilder> {
-
-       /**
-        * Configures this builder to set the given post as post the created reply
-        * refers to.
-        *
-        * @param postId
-        *            The ID of the post the reply refers to
-        * @return This builder
-        */
-       public PostReplyBuilder to(String postId);
-
-       /**
-        * Verifies the configuration of this builder and creates a new post reply.
-        * <p>
-        * The following conditions must be met in order for the configuration to be
-        * considered valid:
-        * <ul>
-        * <li>Exactly one of {@link #randomId()} or {@link #withId(String)} must
-        * have been called.</li>
-        * <li>The {@link #from(String) sender} must not be {@code null}.</li>
-        * <li>Exactly one of {@link #currentTime()} or {@link #withTime(long)} must
-        * have been called.</li>
-        * <li>The {@link #withText(String) text} must not be {@code null} and must
-        * contain something other than whitespace.</li>
-        * <li>The {@link #to(String) post} have been set.</li>
-        * </ul>
-        *
-        * @return The created post reply
-        * @throws IllegalStateException
-        *             if this builder’s configuration is not valid
-        */
-       public PostReply build() throws IllegalStateException;
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/data/PostReplyBuilderFactory.java b/src/main/java/net/pterodactylus/sone/data/PostReplyBuilderFactory.java
deleted file mode 100644 (file)
index 17a92f3..0000000
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Sone - PostReplyBuilderFactory.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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.data;
-
-/**
- * Factory for {@link PostReplyBuilder}s.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public interface PostReplyBuilderFactory {
-
-       /**
-        * Creates a new post reply builder.
-        *
-        * @return A new post reply builder
-        */
-       public PostReplyBuilder newPostReplyBuilder();
-
-}
diff --git a/src/main/java/net/pterodactylus/sone/data/ReplyBuilder.java b/src/main/java/net/pterodactylus/sone/data/ReplyBuilder.java
deleted file mode 100644 (file)
index fa0aac8..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Sone - ReplyBuilder.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 <http://www.gnu.org/licenses/>.
- */
-
-package net.pterodactylus.sone.data;
-
-/**
- * Methods that all reply builders need to implement in order to be able to
- * create any kind of {@link Reply}.
- *
- * @param <B>
- *            The type of the builder
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
-public interface ReplyBuilder<B extends ReplyBuilder<B>> {
-
-       /**
-        * Configures this builder to use a random ID when creating the reply. If
-        * this method is used, {@link #withId(String)} must not be used.
-        *
-        * @return This builder
-        */
-       public B randomId();
-
-       /**
-        * Configures this builder to use the given ID when creating the reply. If
-        * this method is used, {@link #randomId()} must not be used.
-        *
-        * @param id
-        *            The ID of the reply
-        * @return This builder
-        */
-       public B withId(String id);
-
-       /**
-        * Configures this builder to use the ID of the given {@link Sone} as sender
-        * of the reply.
-        *
-        * @param senderId
-        *            The ID of the sender of the reply
-        * @return This builder
-        */
-       public B from(String senderId);
-
-       /**
-        * Configures this builder to use the current time when creating the reply.
-        * If this method is used, {@link #withTime(long)} must not be used.
-        *
-        * @return This builder
-        */
-       public B currentTime();
-
-       /**
-        * Configures this builder to use the given time when creating the reply. If
-        * this method is used, {@link #currentTime()} must not be used.
-        *
-        * @param time
-        *            The time of the reply
-        * @return This builder
-        */
-       public B withTime(long time);
-
-       /**
-        * Configures this builder to use the given text when creating the reply.
-        *
-        * @param text
-        *            The text of the reply
-        * @return This builder
-        */
-       public B withText(String text);
-
-}
index 25dd1e1..2a68a13 100644 (file)
@@ -17,7 +17,7 @@
 
 package net.pterodactylus.sone.data.impl;
 
-import net.pterodactylus.sone.data.ReplyBuilder;
+import net.pterodactylus.sone.database.ReplyBuilder;
 
 /**
  * Abstract implementation of a {@link ReplyBuilder}.
index cf32640..4df8897 100644 (file)
 
 package net.pterodactylus.sone.data.impl;
 
-import com.google.inject.Inject;
+import net.pterodactylus.sone.database.PostBuilder;
+import net.pterodactylus.sone.database.PostBuilderFactory;
+import net.pterodactylus.sone.database.SoneProvider;
 
-import net.pterodactylus.sone.core.SoneProvider;
-import net.pterodactylus.sone.data.PostBuilder;
-import net.pterodactylus.sone.data.PostBuilderFactory;
+import com.google.inject.Inject;
 
 /**
  * {@link PostBuilderFactory} implementation that creates
index 5005e5e..e326304 100644 (file)
 
 package net.pterodactylus.sone.data.impl;
 
-import net.pterodactylus.sone.core.PostProvider;
-import net.pterodactylus.sone.core.SoneProvider;
-import net.pterodactylus.sone.data.PostReplyBuilder;
-import net.pterodactylus.sone.data.PostReplyBuilderFactory;
+import net.pterodactylus.sone.database.PostProvider;
+import net.pterodactylus.sone.database.PostReplyBuilder;
+import net.pterodactylus.sone.database.PostReplyBuilderFactory;
+import net.pterodactylus.sone.database.SoneProvider;
 
 import com.google.inject.Inject;
 
index 929f315..6713827 100644 (file)
@@ -21,9 +21,9 @@ import static com.google.common.base.Preconditions.checkState;
 
 import java.util.UUID;
 
-import net.pterodactylus.sone.core.SoneProvider;
 import net.pterodactylus.sone.data.Post;
-import net.pterodactylus.sone.data.PostBuilder;
+import net.pterodactylus.sone.database.PostBuilder;
+import net.pterodactylus.sone.database.SoneProvider;
 
 import org.apache.commons.lang.StringUtils;
 
index bb8a4df..d008463 100644 (file)
@@ -19,9 +19,9 @@ package net.pterodactylus.sone.data.impl;
 
 import java.util.UUID;
 
-import net.pterodactylus.sone.core.SoneProvider;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.database.SoneProvider;
 
 /**
  * A post is a short message that a user writes in his Sone to let other users
@@ -94,7 +94,7 @@ public class PostImpl implements Post {
         */
        @Override
        public Sone getSone() {
-               return soneProvider.getSone(soneId, false);
+               return soneProvider.getSone(soneId);
        }
 
        /**
@@ -102,7 +102,7 @@ public class PostImpl implements Post {
         */
        @Override
        public Sone getRecipient() {
-               return soneProvider.getSone(recipientId, false);
+               return soneProvider.getSone(recipientId);
        }
 
        /**
index 1709b6e..da18f96 100644 (file)
@@ -21,10 +21,10 @@ import static com.google.common.base.Preconditions.checkState;
 
 import java.util.UUID;
 
-import net.pterodactylus.sone.core.PostProvider;
-import net.pterodactylus.sone.core.SoneProvider;
 import net.pterodactylus.sone.data.PostReply;
-import net.pterodactylus.sone.data.PostReplyBuilder;
+import net.pterodactylus.sone.database.PostProvider;
+import net.pterodactylus.sone.database.PostReplyBuilder;
+import net.pterodactylus.sone.database.SoneProvider;
 
 import org.apache.commons.lang.StringUtils;
 
index 065ce2f..30badf7 100644 (file)
 
 package net.pterodactylus.sone.data.impl;
 
-import net.pterodactylus.sone.core.PostProvider;
-import net.pterodactylus.sone.core.SoneProvider;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.PostReply;
+import net.pterodactylus.sone.database.PostProvider;
+import net.pterodactylus.sone.database.SoneProvider;
 
 import com.google.common.base.Optional;
 
index 5590c7e..5f7dac0 100644 (file)
@@ -17,9 +17,9 @@
 
 package net.pterodactylus.sone.data.impl;
 
-import net.pterodactylus.sone.core.SoneProvider;
 import net.pterodactylus.sone.data.Reply;
 import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.database.SoneProvider;
 
 /**
  * Abstract base class for all replies.
@@ -83,7 +83,7 @@ public abstract class ReplyImpl<T extends Reply<T>> implements Reply<T> {
         */
        @Override
        public Sone getSone() {
-               return soneProvider.getSone(soneId, false);
+               return soneProvider.getSone(soneId);
        }
 
        /**
diff --git a/src/main/java/net/pterodactylus/sone/database/PostBuilder.java b/src/main/java/net/pterodactylus/sone/database/PostBuilder.java
new file mode 100644 (file)
index 0000000..449147a
--- /dev/null
@@ -0,0 +1,144 @@
+/*
+ * Sone - PostBuilder.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 <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.database;
+
+import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.data.Sone;
+
+/**
+ * Builder for {@link Post} objects.
+ * <p>
+ * A {@link Post} consists of the following elements:
+ * <ul>
+ * <li>an ID,</li>
+ * <li>a {@link Sone sender},</li>
+ * <li>an optional {@link Sone recipient},</li>
+ * <li>a time,</li>
+ * <li>and a text.</li>
+ * </ul>
+ * Except for the recipient, all this elements have to be configured on this
+ * builder. For the ID you have the possibility to configure either a random ID
+ * (which should be used for new posts) or a custom ID you specify (for creating
+ * an existing post). For the time you can use the current time (again, for
+ * creating new posts) or the given time (for loading posts). It is an error to
+ * specify both ways for either the ID or the time.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public interface PostBuilder {
+
+       /**
+        * Copies all attributes of the given post to this post builder.
+        *
+        * @param post
+        *            The post whose attributes to copy into this builder
+        * @return This builder
+        * @throws NullPointerException
+        *             if {@code post} is {@code null}
+        */
+       public PostBuilder copyPost(Post post) throws NullPointerException;
+
+       /**
+        * Configures this builder to use the given Sone as sender of the new post.
+        *
+        * @param senderId
+        *            The ID of the sender of the post
+        * @return This post builder
+        */
+       public PostBuilder from(String senderId);
+
+       /**
+        * Configures this builder to use a random ID for the new post. If this
+        * method is used, {@link #withId(String)} must not be used.
+        *
+        * @return This post builder
+        */
+       public PostBuilder randomId();
+
+       /**
+        * Configures this builder to use the given ID as ID for the new post. If
+        * this method is used, {@link #randomId()} must not be used.
+        *
+        * @param id
+        *            The ID to use for the post
+        * @return This post builder
+        */
+       public PostBuilder withId(String id);
+
+       /**
+        * Configures this builder to use the current time when creating the post.
+        * If this method is used, {@link #withTime(long)} must not be used.
+        *
+        * @return This post builder
+        */
+       public PostBuilder currentTime();
+
+       /**
+        * Configures the builder to use the given time as time for the new post. If
+        * this method is used, {@link #currentTime()} must not be used.
+        *
+        * @param time
+        *            The time to use for the post
+        * @return This post builder
+        */
+       public PostBuilder withTime(long time);
+
+       /**
+        * Configures the builder to use the given text for the new post.
+        *
+        * @param text
+        *            The text to use for the post
+        * @return This post builder
+        */
+       public PostBuilder withText(String text);
+
+       /**
+        * Configures the builder to use the given {@link Sone} as recipient for the
+        * post.
+        *
+        * @param recipientId
+        *            The ID of the recipient of the post
+        * @return This post builder
+        */
+       public PostBuilder to(String recipientId);
+
+       /**
+        * Verifies this builder’s configuration and creates a new post.
+        * <p>
+        * The following conditions must be met in order for this builder to be
+        * configured correctly:
+        * <ul>
+        * <li>Exactly one of {@link #randomId()} or {@link #withId(String)} must
+        * have been called.</li>
+        * <li>The {@link #from(String) sender} must not be {@code null}.</li>
+        * <li>Exactly one of {@link #currentTime()} or {@link #withTime(long)} must
+        * have been called.</li>
+        * <li>The {@link #withText(String) text} must not be {@code null} and must
+        * contain something other than whitespace.</li>
+        * <li>The {@link #to(String) recipient} must either not have been set, or
+        * it must have been set to a {@link Sone} other than {@link #from(String)
+        * the sender}.</li>
+        * </ul>
+        *
+        * @return A new post
+        * @throws IllegalStateException
+        *             if this builder’s configuration is not valid
+        */
+       public Post build() throws IllegalStateException;
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/database/PostBuilderFactory.java b/src/main/java/net/pterodactylus/sone/database/PostBuilderFactory.java
new file mode 100644 (file)
index 0000000..b89ae28
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Sone - PostBuilderFactory.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 <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.database;
+
+/**
+ * Factory for {@link PostBuilder}s.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public interface PostBuilderFactory {
+
+       /**
+        * Creates a new post builder.
+        *
+        * @return A new post builder
+        */
+       public PostBuilder newPostBuilder();
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/database/PostProvider.java b/src/main/java/net/pterodactylus/sone/database/PostProvider.java
new file mode 100644 (file)
index 0000000..13845da
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+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 <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+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<Post> getPost(String postId);
+
+       /**
+        * 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<Post> getDirectedPosts(String recipientId);
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/database/PostReplyBuilder.java b/src/main/java/net/pterodactylus/sone/database/PostReplyBuilder.java
new file mode 100644 (file)
index 0000000..c031443
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Sone - PostReplyBuilder.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 <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.database;
+
+import net.pterodactylus.sone.data.PostReply;
+
+/**
+ * Builder for a {@link PostReply} object.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public interface PostReplyBuilder extends ReplyBuilder<PostReplyBuilder> {
+
+       /**
+        * Configures this builder to set the given post as post the created reply
+        * refers to.
+        *
+        * @param postId
+        *            The ID of the post the reply refers to
+        * @return This builder
+        */
+       public PostReplyBuilder to(String postId);
+
+       /**
+        * Verifies the configuration of this builder and creates a new post reply.
+        * <p>
+        * The following conditions must be met in order for the configuration to be
+        * considered valid:
+        * <ul>
+        * <li>Exactly one of {@link #randomId()} or {@link #withId(String)} must
+        * have been called.</li>
+        * <li>The {@link #from(String) sender} must not be {@code null}.</li>
+        * <li>Exactly one of {@link #currentTime()} or {@link #withTime(long)} must
+        * have been called.</li>
+        * <li>The {@link #withText(String) text} must not be {@code null} and must
+        * contain something other than whitespace.</li>
+        * <li>The {@link #to(String) post} have been set.</li>
+        * </ul>
+        *
+        * @return The created post reply
+        * @throws IllegalStateException
+        *             if this builder’s configuration is not valid
+        */
+       public PostReply build() throws IllegalStateException;
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/database/PostReplyBuilderFactory.java b/src/main/java/net/pterodactylus/sone/database/PostReplyBuilderFactory.java
new file mode 100644 (file)
index 0000000..7fd4ae1
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Sone - PostReplyBuilderFactory.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 <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.database;
+
+/**
+ * Factory for {@link PostReplyBuilder}s.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public interface PostReplyBuilderFactory {
+
+       /**
+        * Creates a new post reply builder.
+        *
+        * @return A new post reply builder
+        */
+       public PostReplyBuilder newPostReplyBuilder();
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/database/PostReplyProvider.java b/src/main/java/net/pterodactylus/sone/database/PostReplyProvider.java
new file mode 100644 (file)
index 0000000..8098f1d
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Sone - PostReplyProvider.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 <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.database;
+
+import java.util.List;
+
+import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.data.PostReply;
+
+import com.google.common.base.Optional;
+
+/**
+ * Interface for objects that can provide {@link PostReply}s.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public interface PostReplyProvider {
+
+       /**
+        * Returns the reply with the given ID.
+        *
+        * @param id
+        *            The ID of the reply to get
+        * @return The reply, or {@code null} if there is no such reply
+        */
+       public Optional<PostReply> getPostReply(String id);
+
+       /**
+        * Returns all replies for the given post, order ascending by time.
+        *
+        * @param post
+        *            The post to get all replies for
+        * @return All replies for the given post
+        */
+       public List<PostReply> getReplies(Post post);
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/database/ReplyBuilder.java b/src/main/java/net/pterodactylus/sone/database/ReplyBuilder.java
new file mode 100644 (file)
index 0000000..d83e7ce
--- /dev/null
@@ -0,0 +1,88 @@
+/*
+ * Sone - ReplyBuilder.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 <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.database;
+
+import net.pterodactylus.sone.data.Reply;
+import net.pterodactylus.sone.data.Sone;
+
+/**
+ * Methods that all reply builders need to implement in order to be able to
+ * create any kind of {@link Reply}.
+ *
+ * @param <B>
+ *            The type of the builder
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public interface ReplyBuilder<B extends ReplyBuilder<B>> {
+
+       /**
+        * Configures this builder to use a random ID when creating the reply. If
+        * this method is used, {@link #withId(String)} must not be used.
+        *
+        * @return This builder
+        */
+       public B randomId();
+
+       /**
+        * Configures this builder to use the given ID when creating the reply. If
+        * this method is used, {@link #randomId()} must not be used.
+        *
+        * @param id
+        *            The ID of the reply
+        * @return This builder
+        */
+       public B withId(String id);
+
+       /**
+        * Configures this builder to use the ID of the given {@link Sone} as sender
+        * of the reply.
+        *
+        * @param senderId
+        *            The ID of the sender of the reply
+        * @return This builder
+        */
+       public B from(String senderId);
+
+       /**
+        * Configures this builder to use the current time when creating the reply.
+        * If this method is used, {@link #withTime(long)} must not be used.
+        *
+        * @return This builder
+        */
+       public B currentTime();
+
+       /**
+        * Configures this builder to use the given time when creating the reply. If
+        * this method is used, {@link #currentTime()} must not be used.
+        *
+        * @param time
+        *            The time of the reply
+        * @return This builder
+        */
+       public B withTime(long time);
+
+       /**
+        * Configures this builder to use the given text when creating the reply.
+        *
+        * @param text
+        *            The text of the reply
+        * @return This builder
+        */
+       public B withText(String text);
+
+}
diff --git a/src/main/java/net/pterodactylus/sone/database/SoneProvider.java b/src/main/java/net/pterodactylus/sone/database/SoneProvider.java
new file mode 100644 (file)
index 0000000..b1b1eb4
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Sone - SoneProvider.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 <http://www.gnu.org/licenses/>.
+ */
+
+package net.pterodactylus.sone.database;
+
+import net.pterodactylus.sone.data.Sone;
+
+/**
+ * Interface for objects that can provide {@link Sone}s by their ID.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public interface SoneProvider {
+
+       /**
+        * Returns the Sone with the given ID, if it exists.
+        *
+        * @param soneId
+        *            The ID of the Sone to return
+        * @return The Sone with the given ID, or {@code null}
+        */
+       public Sone getSone(String soneId);
+
+}
index 368f49a..8afe7c4 100644 (file)
@@ -163,7 +163,7 @@ public abstract class AbstractSoneCommand extends AbstractCommand {
                if (mandatory && (soneId == null)) {
                        throw new FcpException("Could not load Sone ID from “" + parameterName + "”.");
                }
-               Sone sone = localOnly ? core.getLocalSone(soneId, false) : core.getSone(soneId, false);
+               Sone sone = localOnly ? core.getLocalSone(soneId, false) : core.getSone(soneId);
                if (mandatory && (sone == null)) {
                        throw new FcpException("Could not load Sone from “" + soneId + "”.");
                }
index 5f2fd14..0fc7eda 100644 (file)
@@ -66,9 +66,9 @@ public class GetPostFeedCommand extends AbstractSoneCommand {
                        if (!getCore().hasSone(friendSoneId)) {
                                continue;
                        }
-                       allPosts.addAll(getCore().getSone(friendSoneId, false).getPosts());
+                       allPosts.addAll(getCore().getSone(friendSoneId).getPosts());
                }
-               allPosts.addAll(getCore().getDirectedPosts(sone));
+               allPosts.addAll(getCore().getDirectedPosts(sone.getId()));
                allPosts = Collections2.filter(allPosts, Post.FUTURE_POSTS_FILTER);
 
                List<Post> sortedPosts = new ArrayList<Post>(allPosts);
index 4b0f3eb..26ccf09 100644 (file)
@@ -24,13 +24,13 @@ import java.util.logging.Logger;
 
 import net.pterodactylus.sone.core.Core;
 import net.pterodactylus.sone.core.FreenetInterface;
-import net.pterodactylus.sone.core.PostProvider;
-import net.pterodactylus.sone.core.SoneProvider;
 import net.pterodactylus.sone.core.WebOfTrustUpdater;
-import net.pterodactylus.sone.data.PostBuilderFactory;
-import net.pterodactylus.sone.data.PostReplyBuilderFactory;
 import net.pterodactylus.sone.data.impl.DefaultPostBuilderFactory;
 import net.pterodactylus.sone.data.impl.DefaultPostReplyBuilderFactory;
+import net.pterodactylus.sone.database.PostBuilderFactory;
+import net.pterodactylus.sone.database.PostProvider;
+import net.pterodactylus.sone.database.PostReplyBuilderFactory;
+import net.pterodactylus.sone.database.SoneProvider;
 import net.pterodactylus.sone.fcp.FcpInterface;
 import net.pterodactylus.sone.freenet.PluginStoreConfigurationBackend;
 import net.pterodactylus.sone.freenet.plugin.PluginConnector;
index d2f2619..8833a2d 100644 (file)
@@ -94,7 +94,7 @@ public class ParserFilter implements Filter {
                int cutOffLength = Numbers.safeParseInteger(parameters.get("cut-off-length"), Numbers.safeParseInteger(templateContext.get(String.valueOf(parameters.get("cut-off-length"))), length));
                Object sone = parameters.get("sone");
                if (sone instanceof String) {
-                       sone = core.getSone((String) sone, false);
+                       sone = core.getSone((String) sone);
                }
                FreenetRequest request = (FreenetRequest) templateContext.get("request");
                SoneTextParserContext context = new SoneTextParserContext(request, (Sone) sone);
index 6e84c70..f2ca0c5 100644 (file)
@@ -26,14 +26,15 @@ import java.util.logging.Logger;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 
-import com.google.common.base.Optional;
-
-import net.pterodactylus.sone.core.PostProvider;
-import net.pterodactylus.sone.core.SoneProvider;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.database.PostProvider;
+import net.pterodactylus.sone.database.SoneProvider;
 import net.pterodactylus.util.io.Closer;
 import net.pterodactylus.util.logging.Logging;
+
+import com.google.common.base.Optional;
+
 import freenet.keys.FreenetURI;
 
 /**
@@ -241,7 +242,7 @@ public class SoneTextParser implements Parser<SoneTextParserContext> {
                                        if (linkType == LinkType.SONE) {
                                                if (line.length() >= (7 + 43)) {
                                                        String soneId = line.substring(7, 50);
-                                                       Sone sone = soneProvider.getSone(soneId, false);
+                                                       Sone sone = soneProvider.getSone(soneId);
                                                        if (sone == null) {
                                                                /*
                                                                 * don’t use create=true above, we don’t want
index 087a5ad..e77e55a 100644 (file)
@@ -65,7 +65,7 @@ public class CreatePostPage extends SoneTemplatePage {
                                if (sender == null) {
                                        sender = currentSone;
                                }
-                               Sone recipient = webInterface.getCore().getSone(recipientId, false);
+                               Sone recipient = webInterface.getCore().getSone(recipientId);
                                text = TextFilter.filter(request.getHttpRequest().getHeader("host"), text);
                                webInterface.getCore().createPost(sender, recipient, System.currentTimeMillis(), text);
                                throw new RedirectException(returnPage);
index 60c174d..262d602 100644 (file)
@@ -59,7 +59,7 @@ public class DistrustPage extends SoneTemplatePage {
                        String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
                        String identity = request.getHttpRequest().getPartAsStringFailsafe("sone", 44);
                        Sone currentSone = getCurrentSone(request.getToadletContext());
-                       Sone sone = webInterface.getCore().getSone(identity, false);
+                       Sone sone = webInterface.getCore().getSone(identity);
                        if (sone != null) {
                                webInterface.getCore().distrustSone(currentSone, sone);
                        }
index 4a9548e..d0a446f 100644 (file)
@@ -77,7 +77,7 @@ public class ImageBrowserPage extends SoneTemplatePage {
                }
                String soneId = request.getHttpRequest().getParam("sone", null);
                if (soneId != null) {
-                       Sone sone = webInterface.getCore().getSone(soneId, false);
+                       Sone sone = webInterface.getCore().getSone(soneId);
                        templateContext.set("soneRequested", true);
                        templateContext.set("sone", sone);
                        return;
index f183ff4..88f1026 100644 (file)
@@ -79,7 +79,7 @@ public class MarkAsKnownPage extends SoneTemplatePage {
                                }
                                webInterface.getCore().markReplyKnown(reply.get());
                        } else if (type.equals("sone")) {
-                               Sone sone = webInterface.getCore().getSone(id, false);
+                               Sone sone = webInterface.getCore().getSone(id);
                                if (sone == null) {
                                        continue;
                                }
index e979a49..6cbb11f 100644 (file)
@@ -310,7 +310,7 @@ public class SearchPage extends SoneTemplatePage {
         */
        private String getSoneId(String phrase) {
                String soneId = phrase.startsWith("sone://") ? phrase.substring(7) : phrase;
-               return (webInterface.getCore().getSone(soneId, false) != null) ? soneId : null;
+               return (webInterface.getCore().getSone(soneId) != null) ? soneId : null;
        }
 
        /**
index ef5463b..5d62399 100644 (file)
@@ -59,7 +59,7 @@ public class TrustPage extends SoneTemplatePage {
                        String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
                        String identity = request.getHttpRequest().getPartAsStringFailsafe("sone", 44);
                        Sone currentSone = getCurrentSone(request.getToadletContext());
-                       Sone sone = webInterface.getCore().getSone(identity, false);
+                       Sone sone = webInterface.getCore().getSone(identity);
                        if (sone != null) {
                                webInterface.getCore().trustSone(currentSone, sone);
                        }
index e43740e..1ee4f8e 100644 (file)
@@ -59,7 +59,7 @@ public class UntrustPage extends SoneTemplatePage {
                        String returnPage = request.getHttpRequest().getPartAsStringFailsafe("returnPage", 256);
                        String identity = request.getHttpRequest().getPartAsStringFailsafe("sone", 44);
                        Sone currentSone = getCurrentSone(request.getToadletContext());
-                       Sone sone = webInterface.getCore().getSone(identity, false);
+                       Sone sone = webInterface.getCore().getSone(identity);
                        if (sone != null) {
                                webInterface.getCore().untrustSone(currentSone, sone);
                        }
index 5572bca..592404f 100644 (file)
@@ -67,7 +67,7 @@ public class ViewSonePage extends SoneTemplatePage {
        @Override
        protected String getPageTitle(FreenetRequest request) {
                String soneId = request.getHttpRequest().getParam("sone");
-               Sone sone = webInterface.getCore().getSone(soneId, false);
+               Sone sone = webInterface.getCore().getSone(soneId);
                if ((sone != null) && (sone.getTime() > 0)) {
                        String soneName = SoneAccessor.getNiceName(sone);
                        return soneName + " - " + webInterface.getL10n().getString("Page.ViewSone.Title");
@@ -82,14 +82,14 @@ public class ViewSonePage extends SoneTemplatePage {
        protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException {
                super.processTemplate(request, templateContext);
                String soneId = request.getHttpRequest().getParam("sone");
-               Sone sone = webInterface.getCore().getSone(soneId, false);
+               Sone sone = webInterface.getCore().getSone(soneId);
                templateContext.set("sone", sone);
                templateContext.set("soneId", soneId);
                if (sone == null) {
                        return;
                }
                List<Post> sonePosts = sone.getPosts();
-               sonePosts.addAll(webInterface.getCore().getDirectedPosts(sone));
+               sonePosts.addAll(webInterface.getCore().getDirectedPosts(sone.getId()));
                Collections.sort(sonePosts, Post.TIME_COMPARATOR);
                Pagination<Post> postPagination = new Pagination<Post>(sonePosts, webInterface.getCore().getPreferences().getPostsPerPage()).setPage(Numbers.safeParseInteger(request.getHttpRequest().getParam("postPage"), 0));
                templateContext.set("postPagination", postPagination);
index 4750794..32ebfc9 100644 (file)
@@ -51,7 +51,7 @@ public class CreatePostAjaxPage extends JsonPage {
                        return createErrorJsonObject("auth-required");
                }
                String recipientId = request.getHttpRequest().getParam("recipient");
-               Sone recipient = webInterface.getCore().getSone(recipientId, false);
+               Sone recipient = webInterface.getCore().getSone(recipientId);
                String senderId = request.getHttpRequest().getParam("sender");
                Sone sender = webInterface.getCore().getLocalSone(senderId, false);
                if (sender == null) {
index 25de182..b86055d 100644 (file)
@@ -51,7 +51,7 @@ public class DistrustAjaxPage extends JsonPage {
                        return createErrorJsonObject("auth-required");
                }
                String soneId = request.getHttpRequest().getParam("sone");
-               Sone sone = webInterface.getCore().getSone(soneId, false);
+               Sone sone = webInterface.getCore().getSone(soneId);
                if (sone == null) {
                        return createErrorJsonObject("invalid-sone-id");
                }
index 6caa2fd..f107b71 100644 (file)
@@ -74,7 +74,7 @@ public class GetStatusAjaxPage extends JsonPage {
                        String[] soneIds = loadSoneIds.split(",");
                        for (String soneId : soneIds) {
                                /* just add it, we skip null further down. */
-                               sones.add(webInterface.getCore().getSone(soneId, false));
+                               sones.add(webInterface.getCore().getSone(soneId));
                        }
                }
                JsonArray jsonSones = new JsonArray();
index 997c9dc..4701118 100644 (file)
@@ -71,7 +71,7 @@ public class MarkAsKnownAjaxPage extends JsonPage {
                                }
                                core.markReplyKnown(reply.get());
                        } else if (type.equals("sone")) {
-                               Sone sone = core.getSone(id, false);
+                               Sone sone = core.getSone(id);
                                if (sone == null) {
                                        continue;
                                }
index 756cee7..9329c1b 100644 (file)
@@ -51,7 +51,7 @@ public class TrustAjaxPage extends JsonPage {
                        return createErrorJsonObject("auth-required");
                }
                String soneId = request.getHttpRequest().getParam("sone");
-               Sone sone = webInterface.getCore().getSone(soneId, false);
+               Sone sone = webInterface.getCore().getSone(soneId);
                if (sone == null) {
                        return createErrorJsonObject("invalid-sone-id");
                }
index 227b580..70e1448 100644 (file)
@@ -51,7 +51,7 @@ public class UntrustAjaxPage extends JsonPage {
                        return createErrorJsonObject("auth-required");
                }
                String soneId = request.getHttpRequest().getParam("sone");
-               Sone sone = webInterface.getCore().getSone(soneId, false);
+               Sone sone = webInterface.getCore().getSone(soneId);
                if (sone == null) {
                        return createErrorJsonObject("invalid-sone-id");
                }
index cd05acb..76f3755 100644 (file)
@@ -22,8 +22,8 @@ import java.io.StringReader;
 import java.util.Arrays;
 
 import junit.framework.TestCase;
-import net.pterodactylus.sone.core.SoneProvider;
 import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.database.SoneProvider;
 
 /**
  * JUnit test case for {@link SoneTextParser}.
@@ -181,7 +181,7 @@ public class SoneTextParserTest extends TestCase {
                 * {@inheritDoc}
                 */
                @Override
-               public Sone getSone(final String soneId, boolean create) {
+               public Sone getSone(final String soneId) {
                        return new Sone(soneId, false) {
 
                                /**