Use a special Sone implementation that only stores the Sone ID.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 27 Sep 2014 18:16:19 +0000 (20:16 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 27 Sep 2014 18:16:19 +0000 (20:16 +0200)
src/main/java/net/pterodactylus/sone/data/impl/IdOnlySone.java [new file with mode: 0644]
src/main/java/net/pterodactylus/sone/text/SoneTextParser.java
src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java

diff --git a/src/main/java/net/pterodactylus/sone/data/impl/IdOnlySone.java b/src/main/java/net/pterodactylus/sone/data/impl/IdOnlySone.java
new file mode 100644 (file)
index 0000000..1cc1801
--- /dev/null
@@ -0,0 +1,258 @@
+package net.pterodactylus.sone.data.impl;
+
+import static java.util.Collections.emptyList;
+import static java.util.Collections.emptySet;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+import net.pterodactylus.sone.data.Album;
+import net.pterodactylus.sone.data.Client;
+import net.pterodactylus.sone.data.Post;
+import net.pterodactylus.sone.data.PostReply;
+import net.pterodactylus.sone.data.Profile;
+import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.data.SoneOptions;
+import net.pterodactylus.sone.freenet.wot.Identity;
+
+import freenet.keys.FreenetURI;
+
+/**
+ * {@link Sone} implementation that only stores the ID of a Sone and returns
+ * {@code null}, {@code 0}, or empty collections where appropriate.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
+ */
+public class IdOnlySone implements Sone {
+
+       private final String id;
+
+       public IdOnlySone(String id) {
+               this.id = id;
+       }
+
+       @Override
+       public Identity getIdentity() {
+               return null;
+       }
+
+       @Override
+       public String getName() {
+               return id;
+       }
+
+       @Override
+       public boolean isLocal() {
+               return false;
+       }
+
+       @Override
+       public FreenetURI getRequestUri() {
+               return null;
+       }
+
+       @Override
+       public Sone setRequestUri(FreenetURI requestUri) {
+               return null;
+       }
+
+       @Override
+       public FreenetURI getInsertUri() {
+               return null;
+       }
+
+       @Override
+       public long getLatestEdition() {
+               return 0;
+       }
+
+       @Override
+       public void setLatestEdition(long latestEdition) {
+       }
+
+       @Override
+       public long getTime() {
+               return 0;
+       }
+
+       @Override
+       public Sone setTime(long time) {
+               return null;
+       }
+
+       @Override
+       public SoneStatus getStatus() {
+               return null;
+       }
+
+       @Override
+       public Sone setStatus(SoneStatus status) {
+               return null;
+       }
+
+       @Override
+       public Profile getProfile() {
+               return new Profile(this);
+       }
+
+       @Override
+       public void setProfile(Profile profile) {
+       }
+
+       @Override
+       public Client getClient() {
+               return null;
+       }
+
+       @Override
+       public Sone setClient(Client client) {
+               return null;
+       }
+
+       @Override
+       public boolean isKnown() {
+               return false;
+       }
+
+       @Override
+       public Sone setKnown(boolean known) {
+               return null;
+       }
+
+       @Override
+       public List<String> getFriends() {
+               return emptyList();
+       }
+
+       @Override
+       public boolean hasFriend(String friendSoneId) {
+               return false;
+       }
+
+       @Override
+       public Sone addFriend(String friendSone) {
+               return this;
+       }
+
+       @Override
+       public Sone removeFriend(String friendSoneId) {
+               return this;
+       }
+
+       @Override
+       public List<Post> getPosts() {
+               return emptyList();
+       }
+
+       @Override
+       public Sone setPosts(Collection<Post> posts) {
+               return this;
+       }
+
+       @Override
+       public void addPost(Post post) {
+       }
+
+       @Override
+       public void removePost(Post post) {
+       }
+
+       @Override
+       public Set<PostReply> getReplies() {
+               return emptySet();
+       }
+
+       @Override
+       public Sone setReplies(Collection<PostReply> replies) {
+               return this;
+       }
+
+       @Override
+       public void addReply(PostReply reply) {
+       }
+
+       @Override
+       public void removeReply(PostReply reply) {
+       }
+
+       @Override
+       public Set<String> getLikedPostIds() {
+               return emptySet();
+       }
+
+       @Override
+       public Sone setLikePostIds(Set<String> likedPostIds) {
+               return this;
+       }
+
+       @Override
+       public boolean isLikedPostId(String postId) {
+               return false;
+       }
+
+       @Override
+       public Sone addLikedPostId(String postId) {
+               return this;
+       }
+
+       @Override
+       public Sone removeLikedPostId(String postId) {
+               return this;
+       }
+
+       @Override
+       public Set<String> getLikedReplyIds() {
+               return emptySet();
+       }
+
+       @Override
+       public Sone setLikeReplyIds(Set<String> likedReplyIds) {
+               return this;
+       }
+
+       @Override
+       public boolean isLikedReplyId(String replyId) {
+               return false;
+       }
+
+       @Override
+       public Sone addLikedReplyId(String replyId) {
+               return this;
+       }
+
+       @Override
+       public Sone removeLikedReplyId(String replyId) {
+               return this;
+       }
+
+       @Override
+       public Album getRootAlbum() {
+               return null;
+       }
+
+       @Override
+       public SoneOptions getOptions() {
+               return null;
+       }
+
+       @Override
+       public void setOptions(SoneOptions options) {
+       }
+
+       @Override
+       public int compareTo(Sone o) {
+               return 0;
+       }
+
+       @Override
+       public String getFingerprint() {
+               return null;
+       }
+
+       @Override
+       public String getId() {
+               return id;
+       }
+
+}
index 0b1585a..ab62fad 100644 (file)
@@ -29,6 +29,7 @@ import java.util.regex.Pattern;
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.data.SoneImpl;
+import net.pterodactylus.sone.data.impl.IdOnlySone;
 import net.pterodactylus.sone.database.PostProvider;
 import net.pterodactylus.sone.database.SoneProvider;
 import net.pterodactylus.util.io.Closer;
@@ -249,7 +250,7 @@ public class SoneTextParser implements Parser<SoneTextParserContext> {
                                                                 * don’t use create=true above, we don’t want
                                                                 * the empty shell.
                                                                 */
-                                                               sone = Optional.<Sone>of(new SoneImpl(soneId, false));
+                                                               sone = Optional.<Sone>of(new IdOnlySone(soneId));
                                                        }
                                                        parts.add(new SonePart(sone.get()));
                                                        line = line.substring(50);
index 2c04b23..c805998 100644 (file)
@@ -26,7 +26,7 @@ import com.google.common.base.Optional;
 
 import junit.framework.TestCase;
 import net.pterodactylus.sone.data.Sone;
-import net.pterodactylus.sone.data.SoneImpl;
+import net.pterodactylus.sone.data.impl.IdOnlySone;
 import net.pterodactylus.sone.database.SoneProvider;
 
 /**
@@ -186,16 +186,7 @@ public class SoneTextParserTest extends TestCase {
                 */
                @Override
                public Optional<Sone> getSone(final String soneId) {
-                       return Optional.<Sone>of(new SoneImpl(soneId, false) {
-
-                               /**
-                                * {@inheritDoc}
-                                */
-                               @Override
-                               public String getName() {
-                                       return soneId;
-                               }
-                       });
+                       return Optional.<Sone>of(new IdOnlySone(soneId));
                }
 
                /**