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
*/
public class ReplyShell extends Reply implements Shell<Reply> {
+ /** The logger. */
+ private static final Logger logger = Logging.getLogger(ReplyShell.class);
+
+ /** The shell creator. */
+ public static final ShellCreator<Reply> creator = new ShellCreator<Reply>() {
+
+ @Override
+ public Shell<Reply> createShell(String id) {
+ return new ReplyShell().setId(id);
+ }
+ };
+
/** The Sone that posted this reply. */
private Sone sone;
* 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;
}
*/
@Override
public long getTime() {
- return time;
+ return (time != null) ? time : 0;
}
/**
*/
@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);
}
/**
if (canUnshell()) {
return new Reply(sone, id, post, time, text);
}
- return null;
+ return this;
}
}