X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FReplyShell.java;h=3886e63ea894acf8f95f23c27aa578145aff7e1f;hb=20673d9e01a985df985690090b5e5cdb05f25d01;hp=fcab34af6ba7eaf6fcfc8480e78bccbd124b769d;hpb=3a14939c2d0d6f781e43bb25e7911018bafb96a7;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/data/ReplyShell.java b/src/main/java/net/pterodactylus/sone/data/ReplyShell.java index fcab34a..3886e63 100644 --- a/src/main/java/net/pterodactylus/sone/data/ReplyShell.java +++ b/src/main/java/net/pterodactylus/sone/data/ReplyShell.java @@ -18,6 +18,10 @@ package net.pterodactylus.sone.data; import java.util.UUID; +import java.util.logging.Level; +import java.util.logging.Logger; + +import net.pterodactylus.util.logging.Logging; /** * A shell around a {@link Reply} for replies that have not yet been retrieved @@ -27,6 +31,18 @@ import java.util.UUID; */ public class ReplyShell extends Reply implements Shell { + /** The logger. */ + private static final Logger logger = Logging.getLogger(ReplyShell.class); + + /** The shell creator. */ + public static final ShellCreator creator = new ShellCreator() { + + @Override + public Shell createShell(String id) { + return new ReplyShell().setId(id); + } + }; + /** The Sone that posted this reply. */ private Sone sone; @@ -92,8 +108,13 @@ public class ReplyShell extends Reply implements Shell { * The ID of this reply * @return This reply shell (for method chaining) */ - public ReplyShell setId(UUID id) { - this.id = id; + public ReplyShell 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; } @@ -126,7 +147,7 @@ public class ReplyShell extends Reply implements Shell { */ @Override public long getTime() { - return time; + return (time != null) ? time : 0; } /** @@ -172,7 +193,7 @@ public class ReplyShell extends Reply implements Shell { */ @Override public boolean canUnshell() { - return (sone != null) && (id != null) && (post != null) && (time != null) && (text != null); + return (sone != null) && (!(sone instanceof Shell)) && (id != null) && (post != null) && (!(post instanceof Shell)) && (time != null) && (text != null); } /** @@ -183,7 +204,7 @@ public class ReplyShell extends Reply implements Shell { if (canUnshell()) { return new Reply(sone, id, post, time, text); } - return null; + return this; } }