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.Post;
21 import net.pterodactylus.sone.data.PostReply;
22 import net.pterodactylus.sone.data.Sone;
23 import net.pterodactylus.sone.database.SoneProvider;
25 import com.google.common.base.Optional;
28 * Memory-based {@link PostReply} implementation.
30 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
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).get();
107 public long getTime() {
115 public String getText() {
123 public boolean isKnown() {
124 return database.isPostReplyKnown(this);
131 public PostReply setKnown(boolean known) {
132 database.setPostReplyKnown(this, known);
144 public String getPostId() {
152 public Optional<Post> getPost() {
153 return database.getPost(postId);
164 public int hashCode() {
165 return id.hashCode();
172 public boolean equals(Object object) {
173 if (!(object instanceof MemoryPostReply)) {
176 MemoryPostReply memoryPostReply = (MemoryPostReply) object;
177 return memoryPostReply.id.equals(id);