2 * Sone - PostShell.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.Collections;
21 import java.util.HashSet;
23 import java.util.UUID;
26 * {@link Shell} around a {@link Post} that has not yet been retrieved from
29 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
31 public class PostShell extends Post implements Shell<Post> {
33 /** The shell creator. */
34 public static final ShellCreator<Post> creator = new ShellCreator<Post>() {
37 public Shell<Post> createShell() {
38 return new PostShell();
42 /** The GUID of the post. */
45 /** The Sone this post belongs to. */
48 /** The time of the post (in milliseconds since Jan 1, 1970 UTC). */
51 /** The text of the post. */
54 /** The replies that have been loaded for this post. */
55 private final Set<Reply> replies = new HashSet<Reply>();
58 * Creates a new post shell.
69 * Returns the ID of the post.
71 * @return The ID of the post
74 public String getId() {
79 * Sets the ID of the post.
83 * @return This post shell (for method chaining)
85 public PostShell setId(UUID id) {
91 * Returns the Sone this post belongs to.
93 * @return The Sone of this post
96 public Sone getSone() {
101 * Sets the Sone the post belongs to.
104 * The Sone the post belongs to
105 * @return This post shell (for method chaining)
107 public PostShell setSone(Sone sone) {
113 * Returns the time of the post.
115 * @return The time of the post (in milliseconds since Jan 1, 1970 UTC)
118 public long getTime() {
123 * Sets the time of the post.
126 * The time of the post (in milliseconds since Jan 1, 1970 UTC)
127 * @return This post shell (for method chaining)
129 public PostShell setTime(long time) {
135 * Returns the text of the post.
137 * @return The text of the post
140 public String getText() {
145 * Sets the text of the post.
148 * The text of the post.
149 * @return This post shell (for method chaining)
151 public PostShell setText(String text) {
157 * Returns all replies to this post in unspecified order.
159 * @return All replies to this post
162 public Set<Reply> getReplies() {
163 return Collections.unmodifiableSet(replies);
167 * Adds a reply to this post. The reply will not be added if its
168 * {@link Reply#getPost() post} is not equal to this post.
174 public void addReply(Reply reply) {
175 if (reply.getPost().equals(this)) {
181 * Removes a reply from this post.
184 * The reply to remove
187 public void removeReply(Reply reply) {
188 if (reply.getPost().equals(this)) {
189 replies.remove(reply);
201 public boolean canUnshell() {
202 return (id != null) && (sone != null) && (time != null) && (text != null);
209 public Post getShelled() {
211 Post post = new Post(id, sone, time, text);
212 for (Reply reply : replies) {
213 post.addReply(reply);