X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2Fimpl%2FDefaultPost.java;h=a560185e36b62a82cfb4d20469644252f6ffc925;hb=72407829d504a0444aadd09cc937bae10b6cb866;hp=c4dcb62ff5a9e3aa86e3a98d0f7b09d62f4e7fa2;hpb=8d5dcab8d96af52241aaf425440680806c5e20d3;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/data/impl/DefaultPost.java b/src/main/java/net/pterodactylus/sone/data/impl/DefaultPost.java index c4dcb62..a560185 100644 --- a/src/main/java/net/pterodactylus/sone/data/impl/DefaultPost.java +++ b/src/main/java/net/pterodactylus/sone/data/impl/DefaultPost.java @@ -17,9 +17,14 @@ package net.pterodactylus.sone.data.impl; -import java.util.UUID; +import static com.google.common.collect.FluentIterable.from; + +import java.util.List; +import java.util.Set; import net.pterodactylus.sone.data.Post; +import net.pterodactylus.sone.data.PostReply; +import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.database.Database; @@ -35,8 +40,8 @@ public class DefaultPost implements Post { private final Database database; - /** The GUID of the post. */ - private final UUID id; + /** The ID of the post. */ + private final String id; /** The ID of the owning Sone. */ private final String soneId; @@ -50,9 +55,6 @@ public class DefaultPost implements Post { /** The text of the post. */ private final String text; - /** Whether the post is known. */ - private volatile boolean known; - /** * Creates a new post. * @@ -71,7 +73,7 @@ public class DefaultPost implements Post { */ public DefaultPost(Database database, String id, String soneId, String recipientId, long time, String text) { this.database = database; - this.id = UUID.fromString(id); + this.id = id; this.soneId = soneId; this.recipientId = recipientId; this.time = time; @@ -82,86 +84,81 @@ public class DefaultPost implements Post { // ACCESSORS // - /** - * {@inheritDoc} - */ @Override public String getId() { - return id.toString(); + return id; } - /** - * {@inheritDoc} - */ @Override public Sone getSone() { return database.getSone(soneId).get(); } - /** - * {@inheritDocs} - */ @Override public Optional getRecipientId() { return Optional.fromNullable(recipientId); } - /** - * {@inheritDoc} - */ @Override public Optional getRecipient() { return database.getSone(recipientId); } - /** - * {@inheritDoc} - */ @Override public long getTime() { return time; } - /** - * {@inheritDoc} - */ @Override public String getText() { return text; } - /** - * {@inheritDoc} - */ @Override public boolean isKnown() { - return known; + return database.isPostKnown(this); } - /** - * {@inheritDoc} - */ @Override - public DefaultPost setKnown(boolean known) { - this.known = known; + public DefaultPost setKnown() { + database.setPostKnown(this); return this; } + @Override + public void like(Sone localSone) { + database.likePost(this, localSone); + } + + @Override + public void unlike(Sone localSone) { + database.unlikePost(this, localSone); + } + + @Override + public boolean isLiked(Sone sone) { + return database.isLiked(this, sone); + } + + @Override + public Set getLikes() { + return database.getLikes(this); + } + + @Override + public List getReplies() { + return from(database.getReplies(getId())).toSortedList(Reply.TIME_COMPARATOR); + } + // // OBJECT METHODS // - /** - * {@inheritDoc} - */ @Override public int hashCode() { return id.hashCode(); } - /** - * {@inheritDoc} - */ @Override public boolean equals(Object object) { if (!(object instanceof DefaultPost)) { @@ -171,9 +168,6 @@ public class DefaultPost implements Post { return post.id.equals(id); } - /** - * {@inheritDoc} - */ @Override public String toString() { return String.format("%s[id=%s,sone=%s,recipient=%s,time=%d,text=%s]", getClass().getName(), id, soneId, recipientId, time, text);