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.Collections;
21 import java.util.HashSet;
23 import java.util.UUID;
26 * A post is a short message that a user writes in his Sone to let other users
27 * know what is going on.
29 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
33 /** The GUID of the post. */
34 private final UUID id;
36 /** The Sone this post belongs to. */
37 private final Sone sone;
39 /** The time of the post (in milliseconds since Jan 1, 1970 UTC). */
40 private final long time;
42 /** The text of the post. */
43 private final String text;
45 /** The replies that have been loaded for this post. */
46 private final Set<Reply> replies = new HashSet<Reply>();
52 * The Sone this post belongs to
54 * The text of the post
56 public Post(Sone sone, String text) {
57 this(sone, System.currentTimeMillis(), text);
64 * The Sone this post belongs to
66 * The time of the post (in milliseconds since Jan 1, 1970 UTC)
68 * The text of the post
70 public Post(Sone sone, long time, String text) {
71 this(UUID.randomUUID(), sone, time, text);
80 * The Sone this post belongs to
82 * The time of the post (in milliseconds since Jan 1, 1970 UTC)
84 * The text of the post
86 public Post(UUID id, Sone sone, long time, String text) {
98 * Returns the ID of the post.
100 * @return The ID of the post
102 public String getId() {
103 return id.toString();
107 * Returns the Sone this post belongs to.
109 * @return The Sone of this post
111 public Sone getSone() {
116 * Returns the time of the post.
118 * @return The time of the post (in milliseconds since Jan 1, 1970 UTC)
120 public long getTime() {
125 * Returns the text of the post.
127 * @return The text of the post
129 public String getText() {
134 * Returns all replies to this post in unspecified order.
136 * @return All replies to this post
138 public Set<Reply> getReplies() {
139 return Collections.unmodifiableSet(replies);
143 * Adds a reply to this post. The reply will not be added if its
144 * {@link Reply#getPost() post} is not equal to this post.
149 public void addReply(Reply reply) {
150 if (reply.getPost().equals(this)) {
156 * Removes a reply from this post.
159 * The reply to remove
161 public void removeReply(Reply reply) {
162 if (reply.getPost().equals(this)) {
163 replies.remove(reply);
175 public int hashCode() {
176 return id.hashCode() ^ sone.hashCode() ^ (int) (time >> 32) ^ (int) (time & 0xffffffff) ^ text.hashCode();
183 public boolean equals(Object object) {
184 if (!(object instanceof Post)) {
187 Post post = (Post) object;
188 return post.id.equals(id) && post.sone.equals(sone) && (post.time == time) && post.text.equals(text);