2 * Sone - PostImpl.java - Copyright © 2010–2012 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.impl;
20 import java.util.UUID;
22 import net.pterodactylus.sone.data.Post;
23 import net.pterodactylus.sone.data.Sone;
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>
31 public class PostImpl implements Post {
33 /** The GUID of the post. */
34 private final UUID id;
36 /** The Sone this post belongs to. */
37 private volatile Sone sone;
39 /** The Sone of the recipient. */
40 private volatile Sone recipient;
42 /** The time of the post (in milliseconds since Jan 1, 1970 UTC). */
43 private volatile long time;
45 /** The text of the post. */
46 private volatile String text;
48 /** Whether the post is known. */
49 private volatile boolean known;
57 public PostImpl(String id) {
58 this(id, null, 0, null);
65 * The Sone this post belongs to
67 * The text of the post
69 public PostImpl(Sone sone, String text) {
70 this(sone, System.currentTimeMillis(), text);
77 * The Sone this post belongs to
79 * The time of the post (in milliseconds since Jan 1, 1970 UTC)
81 * The text of the post
83 public PostImpl(Sone sone, long time, String text) {
84 this(UUID.randomUUID().toString(), sone, time, text);
93 * The Sone this post belongs to
95 * The time of the post (in milliseconds since Jan 1, 1970 UTC)
97 * The text of the post
99 public PostImpl(String id, Sone sone, long time, String text) {
100 this.id = UUID.fromString(id);
114 public String getId() {
115 return id.toString();
122 public Sone getSone() {
130 public PostImpl setSone(Sone sone) {
139 public Sone getRecipient() {
147 public PostImpl setRecipient(Sone recipient) {
148 if (!sone.equals(recipient)) {
149 this.recipient = recipient;
158 public long getTime() {
166 public PostImpl setTime(long time) {
175 public String getText() {
183 public PostImpl setText(String text) {
192 public boolean isKnown() {
200 public PostImpl setKnown(boolean known) {
213 public int hashCode() {
214 return id.hashCode();
221 public boolean equals(Object object) {
222 if (!(object instanceof PostImpl)) {
225 PostImpl post = (PostImpl) object;
226 return post.id.equals(id);
233 public String toString() {
234 return getClass().getName() + "[id=" + id + ",sone=" + sone + ",time=" + time + ",text=" + text + "]";