2 * Sone - PostImpl.java - Copyright © 2010–2013 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;
24 import net.pterodactylus.sone.database.Database;
26 import com.google.common.base.Optional;
29 * A post is a short message that a user writes in his Sone to let other users
30 * know what is going on.
32 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
34 public class DefaultPost implements Post {
36 private final Database database;
38 /** The GUID of the post. */
39 private final UUID id;
41 /** The ID of the owning Sone. */
42 private final String soneId;
44 /** The ID of the recipient Sone. */
45 private final String recipientId;
47 /** The time of the post (in milliseconds since Jan 1, 1970 UTC). */
48 private final long time;
50 /** The text of the post. */
51 private final String text;
53 /** Whether the post is known. */
54 private volatile boolean known;
64 * The ID of the Sone this post belongs to
66 * The ID of the recipient of the post
68 * The time of the post (in milliseconds since Jan 1, 1970 UTC)
70 * The text of the post
72 public DefaultPost(Database database, String id, String soneId, String recipientId, long time, String text) {
73 this.database = database;
74 this.id = UUID.fromString(id);
76 this.recipientId = recipientId;
86 public String getId() {
91 public Sone getSone() {
92 return database.getSone(soneId).get();
96 public Optional<String> getRecipientId() {
97 return Optional.fromNullable(recipientId);
101 public Optional<Sone> getRecipient() {
102 return database.getSone(recipientId);
106 public long getTime() {
111 public String getText() {
116 public boolean isKnown() {
121 public DefaultPost setKnown(boolean known) {
131 public int hashCode() {
132 return id.hashCode();
136 public boolean equals(Object object) {
137 if (!(object instanceof DefaultPost)) {
140 DefaultPost post = (DefaultPost) object;
141 return post.id.equals(id);
145 public String toString() {
146 return String.format("%s[id=%s,sone=%s,recipient=%s,time=%d,text=%s]", getClass().getName(), id, soneId, recipientId, time, text);