2 * Sone - MemoryPostReply.java - Copyright © 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.database.memory;
20 import net.pterodactylus.sone.data.IdBuilder;
21 import net.pterodactylus.sone.data.Post;
22 import net.pterodactylus.sone.data.PostReply;
23 import net.pterodactylus.sone.data.Sone;
24 import net.pterodactylus.sone.database.SoneProvider;
26 import com.google.common.base.Optional;
29 * Memory-based {@link PostReply} implementation.
31 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
33 class MemoryPostReply implements PostReply {
35 private final IdBuilder idBuilder = new IdBuilder();
38 private final MemoryDatabase database;
40 /** The Sone provider. */
41 private final SoneProvider soneProvider;
43 /** The ID of the post reply. */
44 private final String id;
46 /** The ID of the owning Sone. */
47 private final String soneId;
49 /** The time of the post reply. */
50 private final long time;
52 /** The text of the post reply. */
53 private final String text;
55 /** The ID of the post this post reply refers to. */
56 private final String postId;
59 * Creates a new memory-based {@link PostReply} implementation.
66 * The ID of the post reply
68 * The ID of the owning Sone
70 * The time of the post reply
72 * The text of the post reply
74 * The ID of the post this post reply refers to
76 public MemoryPostReply(MemoryDatabase database, SoneProvider soneProvider, String id, String soneId, long time, String text, String postId) {
77 this.database = database;
78 this.soneProvider = soneProvider;
94 public String getId() {
95 return idBuilder.buildId(soneId, id);
99 public String getInternalId() {
107 public Sone getSone() {
108 return soneProvider.getSone(soneId).get();
115 public long getTime() {
123 public String getText() {
131 public boolean isKnown() {
132 return database.isPostReplyKnown(this);
139 public PostReply setKnown(boolean known) {
140 database.setPostReplyKnown(this, known);
152 public String getPostId() {
160 public Optional<Post> getPost() {
161 return database.getPost(postId);
172 public int hashCode() {
173 return id.hashCode();
180 public boolean equals(Object object) {
181 if (!(object instanceof MemoryPostReply)) {
184 MemoryPostReply memoryPostReply = (MemoryPostReply) object;
185 return memoryPostReply.id.equals(id);