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 net.pterodactylus.sone.data.IdBuilder;
21 import net.pterodactylus.sone.data.Reply;
22 import net.pterodactylus.sone.data.Sone;
23 import net.pterodactylus.sone.database.SoneProvider;
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 private final IdBuilder idBuilder = new IdBuilder();
36 /** The Sone provider. */
37 private final SoneProvider soneProvider;
39 /** The ID of the reply. */
40 private final String id;
42 /** The Sone that created this reply. */
43 private final String soneId;
45 /** The time of the reply. */
46 private final long time;
48 /** The text of the reply. */
49 private final String text;
51 /** Whether the reply is known. */
52 private volatile boolean known;
55 * Creates a new reply.
62 * The ID of the Sone of the reply
64 * The time of the reply
66 * The text of the reply
68 protected ReplyImpl(SoneProvider soneProvider, String id, String soneId, long time, String text) {
69 this.soneProvider = soneProvider;
80 public String getId() {
81 return idBuilder.buildId(soneId, id);
85 public String getInternalId() {
93 public Sone getSone() {
94 return soneProvider.getSone(soneId).get();
101 public long getTime() {
109 public String getText() {
117 public boolean isKnown() {
125 @SuppressWarnings("unchecked")
126 public T setKnown(boolean known) {
139 public int hashCode() {
140 return id.hashCode();
147 public boolean equals(Object object) {
148 if (!(object instanceof Reply<?>)) {
151 Reply<?> reply = (Reply<?>) object;
152 return reply.getId().equals(id);
159 public String toString() {
160 return String.format("%s[id=%s,sone=%s,time=%d,text=%s]", getClass().getName(), id, soneId, time, text);