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 GUID of the post. */
36 /** The Sone this post belongs to. */
39 /** The time of the post (in milliseconds since Jan 1, 1970 UTC). */
42 /** The text of the post. */
45 /** The replies that have been loaded for this post. */
46 private final Set<Reply> replies = new HashSet<Reply>();
49 * Creates a new post shell.
60 * Returns the ID of the post.
62 * @return The ID of the post
65 public String getId() {
70 * Sets the ID of the post.
74 * @return This post shell (for method chaining)
76 public PostShell setId(UUID id) {
82 * Returns the Sone this post belongs to.
84 * @return The Sone of this post
87 public Sone getSone() {
92 * Sets the Sone the post belongs to.
95 * The Sone the post belongs to
96 * @return This post shell (for method chaining)
98 public PostShell setSone(Sone sone) {
104 * Returns the time of the post.
106 * @return The time of the post (in milliseconds since Jan 1, 1970 UTC)
109 public long getTime() {
114 * Sets the time of the post.
117 * The time of the post (in milliseconds since Jan 1, 1970 UTC)
118 * @return This post shell (for method chaining)
120 public PostShell setTime(long time) {
126 * Returns the text of the post.
128 * @return The text of the post
131 public String getText() {
136 * Sets the text of the post.
139 * The text of the post.
140 * @return This post shell (for method chaining)
142 public PostShell setText(String text) {
148 * Returns all replies to this post in unspecified order.
150 * @return All replies to this post
153 public Set<Reply> getReplies() {
154 return Collections.unmodifiableSet(replies);
158 * Adds a reply to this post. The reply will not be added if its
159 * {@link Reply#getPost() post} is not equal to this post.
165 public void addReply(Reply reply) {
166 if (reply.getPost().equals(this)) {
172 * Removes a reply from this post.
175 * The reply to remove
178 public void removeReply(Reply reply) {
179 if (reply.getPost().equals(this)) {
180 replies.remove(reply);
192 public boolean canUnshell() {
193 return (id != null) && (sone != null) && (time != null) && (text != null);
200 public Post getShelled() {
202 Post post = new Post(id, sone, time, text);
203 for (Reply reply : replies) {
204 post.addReply(reply);