2 * Sone - ReplyShell.java - Copyright © 2010 David Roden
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 package net.pterodactylus.sone.data;
20 import java.util.UUID;
21 import java.util.logging.Level;
22 import java.util.logging.Logger;
24 import net.pterodactylus.util.logging.Logging;
27 * A shell around a {@link Reply} for replies that have not yet been retrieved
30 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
32 public class ReplyShell extends Reply implements Shell<Reply> {
35 private static final Logger logger = Logging.getLogger(ReplyShell.class);
37 /** The shell creator. */
38 public static final ShellCreator<Reply> creator = new ShellCreator<Reply>() {
41 public Shell<Reply> createShell(String id) {
42 return new ReplyShell().setId(id);
46 /** The Sone that posted this reply. */
49 /** The ID of the reply. */
52 /** The Post this reply refers to. */
55 /** The time of the reply. */
58 /** The text of the reply. */
62 * Creates a new reply shell.
65 super(null, null, null);
73 * Returns the Sone that posted this reply.
75 * @return The Sone that posted this reply
78 public Sone getSone() {
83 * Sets the Sone that posted this reply.
86 * The sone that pasted this reply
87 * @return This reply shell (for method chaining)
89 public ReplyShell setSone(Sone sone) {
95 * Returns the ID of the reply.
97 * @return The ID of the reply
100 public String getId() {
101 return id.toString();
105 * Sets the ID of this reply.
108 * The ID of this reply
109 * @return This reply shell (for method chaining)
111 public ReplyShell setId(String id) {
113 this.id = UUID.fromString(id);
114 } catch (IllegalArgumentException iae1) {
115 logger.log(Level.WARNING, "Invalid ID: “" + id + "”.", iae1);
116 this.id = UUID.randomUUID();
122 * Returns the post this reply refers to.
124 * @return The post this reply refers to
127 public Post getPost() {
132 * Sets the post this reply refers to.
135 * The post this reply refers to
136 * @return This reply shell (for method chaining)
138 public ReplyShell setPost(Post post) {
144 * Returns the time of the reply.
146 * @return The time of the reply (in milliseconds since Jan 1, 1970 UTC)
149 public long getTime() {
154 * Sets the time of this reply.
157 * The time of this reply (in milliseconds since Jan 1, 1970 UTC)
158 * @return This reply shell (for method chaining)
160 public ReplyShell setTime(long time) {
166 * Returns the text of the reply.
168 * @return The text of the reply
171 public String getText() {
176 * Sets the text of the reply.
179 * The text of the reply
180 * @return This reply shell (for method chaining)
182 public ReplyShell setText(String text) {
195 public boolean canUnshell() {
196 return (sone != null) && (!(sone instanceof Shell<?>)) && (id != null) && (post != null) && (!(post instanceof Shell<?>)) && (time != null) && (text != null);
203 public Reply getShelled() {
205 return new Reply(sone, id, post, time, text);