X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FPostShell.java;h=716aab99b43594eb306755aaf26b43e8bf256bae;hb=5a4b73512da5715a7f69735c0821ca1d57479d6f;hp=36dba4202e3b690e7d0a07ce4b61a74de5139253;hpb=3a14939c2d0d6f781e43bb25e7911018bafb96a7;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 36dba42..716aab9 100644 --- a/src/main/java/net/pterodactylus/sone/data/PostShell.java +++ b/src/main/java/net/pterodactylus/sone/data/PostShell.java @@ -21,6 +21,10 @@ import java.util.Collections; import java.util.HashSet; 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,6 +34,18 @@ 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(String id) { + return new PostShell().setId(id); + } + }; + /** The GUID of the post. */ private UUID id; @@ -73,8 +89,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; } @@ -107,7 +128,7 @@ public class PostShell extends Post implements Shell { */ @Override public long getTime() { - return time; + return (time != null) ? time : 0; } /** @@ -190,7 +211,7 @@ public class PostShell extends Post implements Shell { */ @Override public boolean canUnshell() { - return (id != null) && (sone != null) && (time != null) && (text != null); + return (id != null) && (sone != null) && (!(sone instanceof Shell)) && (time != null) && (text != null); } /** @@ -204,7 +225,7 @@ public class PostShell extends Post implements Shell { post.addReply(reply); } } - return null; + return this; } }