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.SoneProvider;
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 PostImpl implements Post {
36 /** The Sone provider. */
37 private final SoneProvider soneProvider;
39 /** The GUID of the post. */
40 private final UUID id;
42 /** The ID of the owning Sone. */
43 private final String soneId;
45 /** The ID of the recipient Sone. */
46 private final String recipientId;
48 /** The time of the post (in milliseconds since Jan 1, 1970 UTC). */
49 private final long time;
51 /** The text of the post. */
52 private final String text;
54 /** Whether the post is known. */
55 private volatile boolean known;
65 * The ID of the Sone this post belongs to
67 * The ID of the recipient of the post
69 * The time of the post (in milliseconds since Jan 1, 1970 UTC)
71 * The text of the post
73 public PostImpl(SoneProvider soneProvider, String id, String soneId, String recipientId, long time, String text) {
74 this.soneProvider = soneProvider;
75 this.id = UUID.fromString(id);
77 this.recipientId = recipientId;
90 public String getId() {
98 public Sone getSone() {
99 return soneProvider.getSone(soneId).get();
106 public Optional<String> getRecipientId() {
107 return Optional.fromNullable(recipientId);
114 public Optional<Sone> getRecipient() {
115 return soneProvider.getSone(recipientId);
122 public long getTime() {
130 public String getText() {
138 public boolean isKnown() {
146 public PostImpl setKnown(boolean known) {
159 public int hashCode() {
160 return id.hashCode();
167 public boolean equals(Object object) {
168 if (!(object instanceof PostImpl)) {
171 PostImpl post = (PostImpl) object;
172 return post.id.equals(id);
179 public String toString() {
180 return String.format("%s[id=%s,sone=%s,recipient=%s,time=%d,text=%s]", getClass().getName(), id, soneId, recipientId, time, text);