X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FPostShell.java;h=05b0045c3e0a31d566741ce99354719f43a3a705;hb=6a0938d8f6fdf9dbc45f03384a3cd83efeef022c;hp=b0cb8e6eb3c8fabff063e29efc6dd78ee5153f00;hpb=5e815759fafbf3a9fa0ea031f2520826ba3029af;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/data/PostShell.java b/src/main/java/net/pterodactylus/sone/data/PostShell.java index b0cb8e6..05b0045 100644 --- a/src/main/java/net/pterodactylus/sone/data/PostShell.java +++ b/src/main/java/net/pterodactylus/sone/data/PostShell.java @@ -17,10 +17,17 @@ package net.pterodactylus.sone.data; +import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.HashSet; +import java.util.List; import java.util.Set; import java.util.UUID; +import java.util.logging.Level; +import java.util.logging.Logger; + +import net.pterodactylus.util.logging.Logging; /** * {@link Shell} around a {@link Post} that has not yet been retrieved from @@ -30,12 +37,15 @@ import java.util.UUID; */ public class PostShell extends Post implements Shell { + /** The logger. */ + private static final Logger logger = Logging.getLogger(PostShell.class); + /** The shell creator. */ public static final ShellCreator creator = new ShellCreator() { @Override - public Shell createShell() { - return new PostShell(); + public Shell createShell(String id) { + return new PostShell().setId(id); } }; @@ -82,8 +92,13 @@ public class PostShell extends Post implements Shell { * The ID of the post * @return This post shell (for method chaining) */ - public PostShell setId(UUID id) { - this.id = id; + public PostShell setId(String id) { + try { + this.id = UUID.fromString(id); + } catch (IllegalArgumentException iae1) { + logger.log(Level.WARNING, "Invalid ID: “" + id + "”.", iae1); + this.id = UUID.randomUUID(); + } return this; } @@ -116,7 +131,7 @@ public class PostShell extends Post implements Shell { */ @Override public long getTime() { - return time; + return (time != null) ? time : 0; } /** @@ -159,8 +174,17 @@ public class PostShell extends Post implements Shell { * @return All replies to this post */ @Override - public Set getReplies() { - return Collections.unmodifiableSet(replies); + public List getReplies() { + List sortedReplies = new ArrayList(replies); + Collections.sort(sortedReplies, new Comparator() { + + @Override + public int compare(Reply leftReply, Reply rightReply) { + return (int) Math.max(Integer.MIN_VALUE, Math.min(Integer.MAX_VALUE, leftReply.getTime() - rightReply.getTime())); + } + + }); + return sortedReplies; } /**