2 * Sone - MemoryPostReply.java - Copyright © 2013–2020 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.database.memory;
20 import static com.google.common.base.Optional.fromNullable;
22 import net.pterodactylus.sone.data.Post;
23 import net.pterodactylus.sone.data.PostReply;
24 import net.pterodactylus.sone.data.Sone;
25 import net.pterodactylus.sone.database.SoneProvider;
27 import com.google.common.base.Optional;
30 * Memory-based {@link PostReply} implementation.
32 class MemoryPostReply implements PostReply {
35 private final MemoryDatabase database;
37 /** The Sone provider. */
38 private final SoneProvider soneProvider;
40 /** The ID of the post reply. */
41 private final String id;
43 /** The ID of the owning Sone. */
44 private final String soneId;
46 /** The time of the post reply. */
47 private final long time;
49 /** The text of the post reply. */
50 private final String text;
52 /** The ID of the post this post reply refers to. */
53 private final String postId;
56 * Creates a new memory-based {@link PostReply} implementation.
63 * The ID of the post reply
65 * The ID of the owning Sone
67 * The time of the post reply
69 * The text of the post reply
71 * The ID of the post this post reply refers to
73 public MemoryPostReply(MemoryDatabase database, SoneProvider soneProvider, String id, String soneId, long time, String text, String postId) {
74 this.database = database;
75 this.soneProvider = soneProvider;
91 public String getId() {
99 public Sone getSone() {
100 return soneProvider.getSone(soneId);
107 public long getTime() {
115 public String getText() {
123 public boolean isKnown() {
124 return database.isPostReplyKnown(this);
135 public String getPostId() {
143 public Optional<Post> getPost() {
144 return fromNullable(database.getPost(postId));
155 public int hashCode() {
156 return id.hashCode();
163 public boolean equals(Object object) {
164 if (!(object instanceof MemoryPostReply)) {
167 MemoryPostReply memoryPostReply = (MemoryPostReply) object;
168 return memoryPostReply.id.equals(id);
172 public String toString() {
173 return "MemoryPostReply{" +
174 "database=" + database +
175 ", soneProvider=" + soneProvider +
176 ", id='" + id + '\'' +
177 ", soneId='" + soneId + '\'' +
179 ", text='" + text + '\'' +
180 ", postId='" + postId + '\'' +