2 * Sone - ReplyImpl.java - Copyright © 2011–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.Reply;
23 import net.pterodactylus.sone.data.Sone;
26 * Abstract base class for all replies.
29 * The type of the reply
30 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
32 public abstract class ReplyImpl<T extends Reply<T>> implements Reply<T> {
34 /** The ID of the reply. */
35 private final String id;
37 /** The Sone that created this reply. */
38 private volatile Sone sone;
40 /** The time of the reply. */
41 private volatile long time;
43 /** The text of the reply. */
44 private volatile String text;
46 /** Whether the reply is known. */
47 private volatile boolean known;
50 * Creates a new reply with the given ID.
55 protected ReplyImpl(String id) {
56 this(id, null, 0, null);
60 * Creates a new reply with a new random ID.
63 * The Sone of the reply
65 * The time of the reply
67 * The text of the reply
69 protected ReplyImpl(Sone sone, long time, String text) {
70 this(UUID.randomUUID().toString(), sone, time, text);
74 * Creates a new reply.
79 * The Sone of the reply
81 * The time of the reply
83 * The text of the reply
85 protected ReplyImpl(String id, Sone sone, long time, String text) {
96 public String getId() {
104 public Sone getSone() {
109 * Sets the Sone that posted this reply.
112 * The Sone that posted this reply
113 * @return This reply (for method chaining)
116 @SuppressWarnings("unchecked")
117 public T setSone(Sone sone) {
126 public long getTime() {
131 * Sets the time of this reply.
134 * The time of this reply (in milliseconds since Jan 1, 1970 UTC)
135 * @return This reply (for method chaining)
138 @SuppressWarnings("unchecked")
139 public T setTime(long time) {
148 public String getText() {
153 * Sets the text of this reply.
156 * The text of this reply
157 * @return This reply (for method chaining)
160 @SuppressWarnings("unchecked")
161 public T setText(String text) {
170 public boolean isKnown() {
178 @SuppressWarnings("unchecked")
179 public T setKnown(boolean known) {
192 public int hashCode() {
193 return id.hashCode();
200 public boolean equals(Object object) {
201 if (!(object instanceof Reply<?>)) {
204 Reply<?> reply = (Reply<?>) object;
205 return reply.getId().equals(id);
212 public String toString() {
213 return getClass().getName() + "[id=" + id + ",sone=" + sone + ",time=" + time + ",text=" + text + "]";