2 * FreenetSone - StatusUpdate.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.Collection;
21 import java.util.Collections;
22 import java.util.HashSet;
24 import java.util.UUID;
27 * A post is a short message that a user writes in his Sone to let other users
28 * know what is going on.
30 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
34 /** The GUID of the post. */
35 private final UUID id;
37 /** The Sone this post belongs to. */
38 private final Sone sone;
40 /** The time of the post (in milliseconds since Jan 1, 1970 UTC). */
41 private final long time;
43 /** The text of the post. */
44 private final String text;
46 /** The replies that have been loaded for this post. */
47 private final Set<Reply> replies = new HashSet<Reply>();
53 * The Sone this post belongs to
55 * The text of the post
57 public Post(Sone sone, String text) {
58 this(sone, System.currentTimeMillis(), text);
65 * The Sone this post belongs to
67 * The time of the post (in milliseconds since Jan 1, 1970 UTC)
69 * The text of the post
71 public Post(Sone sone, long time, String text) {
72 this(UUID.randomUUID(), sone, time, text);
81 * The Sone this post belongs to
83 * The time of the post (in milliseconds since Jan 1, 1970 UTC)
85 * The text of the post
87 public Post(UUID id, Sone sone, long time, String text) {
99 * Returns the ID of the post.
101 * @return The ID of the post
103 public String getId() {
104 return id.toString();
108 * Returns the Sone this post belongs to.
110 * @return The Sone of this post
112 public Sone getSone() {
117 * Returns the time of the post.
119 * @return The time of the post (in milliseconds since Jan 1, 1970 UTC)
121 public long getTime() {
126 * Returns the text of the post.
128 * @return The text of the post
130 public String getText() {
135 * Returns all replies to this post in unspecified order.
137 * @return All replies to this post
139 public Collection<Reply> getReplies() {
140 return Collections.unmodifiableSet(replies);
144 * Adds a reply to this post. The reply will not be added if its
145 * {@link Reply#getPost() post} is not equal to this post.
150 public void addReply(Reply reply) {
151 if (reply.getPost().equals(this)) {
157 * Removes a reply from this post.
160 * The reply to remove
162 public void removeReply(Reply reply) {
163 if (reply.getPost().equals(this)) {
164 replies.remove(reply);
176 public int hashCode() {
177 return id.hashCode();
184 public boolean equals(Object object) {
185 if (!(object instanceof Post)) {
188 return ((Post) object).id.equals(id);