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.Comparator;
21 import java.util.UUID;
24 * A post is a short message that a user writes in his Sone to let other users
25 * know what is going on.
27 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
31 /** Comparator for posts, sorts descending by time. */
32 public static final Comparator<Post> TIME_COMPARATOR = new Comparator<Post>() {
35 public int compare(Post leftPost, Post rightPost) {
36 return (int) Math.max(Integer.MIN_VALUE, Math.min(Integer.MAX_VALUE, rightPost.getTime() - leftPost.getTime()));
41 /** The GUID of the post. */
42 private final UUID id;
44 /** The Sone this post belongs to. */
45 private volatile Sone sone;
47 /** The time of the post (in milliseconds since Jan 1, 1970 UTC). */
48 private volatile long time;
50 /** The text of the post. */
51 private volatile String text;
59 public Post(String id) {
60 this(id, null, 0, null);
67 * The Sone this post belongs to
69 * The text of the post
71 public Post(Sone sone, String text) {
72 this(sone, System.currentTimeMillis(), text);
79 * The Sone this post belongs to
81 * The time of the post (in milliseconds since Jan 1, 1970 UTC)
83 * The text of the post
85 public Post(Sone sone, long time, String text) {
86 this(UUID.randomUUID().toString(), sone, time, text);
95 * The Sone this post belongs to
97 * The time of the post (in milliseconds since Jan 1, 1970 UTC)
99 * The text of the post
101 public Post(String id, Sone sone, long time, String text) {
102 this.id = UUID.fromString(id);
113 * Returns the ID of the post.
115 * @return The ID of the post
117 public String getId() {
118 return id.toString();
122 * Returns the Sone this post belongs to.
124 * @return The Sone of this post
126 public Sone getSone() {
131 * Sets the Sone of this post.
134 * The Sone of this post
135 * @return This post (for method chaining)
137 public Post setSone(Sone sone) {
143 * Returns the time of the post.
145 * @return The time of the post (in milliseconds since Jan 1, 1970 UTC)
147 public long getTime() {
152 * Sets the time of this post.
155 * The time of this post (in milliseconds since Jan 1, 1970 UTC)
156 * @return This post (for method chaining)
158 public Post setTime(long time) {
164 * Returns the text of the post.
166 * @return The text of the post
168 public String getText() {
173 * Sets the text of this post.
176 * The text of this post
177 * @return This post (for method chaining)
179 public Post setText(String text) {
192 public int hashCode() {
193 return id.hashCode();
200 public boolean equals(Object object) {
201 if (!(object instanceof Post)) {
204 Post post = (Post) object;
205 return post.id.equals(id);
212 public String toString() {
213 return getClass().getName() + "[id=" + id + ",sone=" + sone + ",time=" + time + ",text=" + text + "]";