From aadf0893d8d3c791d9bb01db8009bb12f06e49c7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 27 Sep 2014 20:16:19 +0200 Subject: [PATCH] Use a special Sone implementation that only stores the Sone ID. --- .../pterodactylus/sone/data/impl/IdOnlySone.java | 258 +++++++++++++++++++++ .../pterodactylus/sone/text/SoneTextParser.java | 3 +- .../sone/text/SoneTextParserTest.java | 13 +- 3 files changed, 262 insertions(+), 12 deletions(-) create mode 100644 src/main/java/net/pterodactylus/sone/data/impl/IdOnlySone.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 index 0000000..1cc1801 --- /dev/null +++ b/src/main/java/net/pterodactylus/sone/data/impl/IdOnlySone.java @@ -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 David ‘Bombe’ Roden + */ +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 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 getPosts() { + return emptyList(); + } + + @Override + public Sone setPosts(Collection posts) { + return this; + } + + @Override + public void addPost(Post post) { + } + + @Override + public void removePost(Post post) { + } + + @Override + public Set getReplies() { + return emptySet(); + } + + @Override + public Sone setReplies(Collection replies) { + return this; + } + + @Override + public void addReply(PostReply reply) { + } + + @Override + public void removeReply(PostReply reply) { + } + + @Override + public Set getLikedPostIds() { + return emptySet(); + } + + @Override + public Sone setLikePostIds(Set 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 getLikedReplyIds() { + return emptySet(); + } + + @Override + public Sone setLikeReplyIds(Set 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; + } + +} diff --git a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java index 0b1585a..ab62fad 100644 --- a/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java +++ b/src/main/java/net/pterodactylus/sone/text/SoneTextParser.java @@ -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 { * don’t use create=true above, we don’t want * the empty shell. */ - sone = Optional.of(new SoneImpl(soneId, false)); + sone = Optional.of(new IdOnlySone(soneId)); } parts.add(new SonePart(sone.get())); line = line.substring(50); diff --git a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java index 2c04b23..c805998 100644 --- a/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java +++ b/src/test/java/net/pterodactylus/sone/text/SoneTextParserTest.java @@ -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 getSone(final String soneId) { - return Optional.of(new SoneImpl(soneId, false) { - - /** - * {@inheritDoc} - */ - @Override - public String getName() { - return soneId; - } - }); + return Optional.of(new IdOnlySone(soneId)); } /** -- 2.7.4