2 * Sone - MemoryPostReply.java - Copyright © 2013–2016 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 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
34 class MemoryPostReply implements PostReply {
37 private final MemoryDatabase database;
39 /** The Sone provider. */
40 private final SoneProvider soneProvider;
42 /** The ID of the post reply. */
43 private final String id;
45 /** The ID of the owning Sone. */
46 private final String soneId;
48 /** The time of the post reply. */
49 private final long time;
51 /** The text of the post reply. */
52 private final String text;
54 /** The ID of the post this post reply refers to. */
55 private final String postId;
58 * Creates a new memory-based {@link PostReply} implementation.
65 * The ID of the post reply
67 * The ID of the owning Sone
69 * The time of the post reply
71 * The text of the post reply
73 * The ID of the post this post reply refers to
75 public MemoryPostReply(MemoryDatabase database, SoneProvider soneProvider, String id, String soneId, long time, String text, String postId) {
76 this.database = database;
77 this.soneProvider = soneProvider;
93 public String getId() {
101 public Sone getSone() {
102 return soneProvider.getSone(soneId);
109 public long getTime() {
117 public String getText() {
125 public boolean isKnown() {
126 return database.isPostReplyKnown(this);
133 public PostReply setKnown(boolean known) {
134 database.setPostReplyKnown(this, known);
146 public String getPostId() {
154 public Optional<Post> getPost() {
155 return fromNullable(database.getPost(postId));
166 public int hashCode() {
167 return id.hashCode();
174 public boolean equals(Object object) {
175 if (!(object instanceof MemoryPostReply)) {
178 MemoryPostReply memoryPostReply = (MemoryPostReply) object;
179 return memoryPostReply.id.equals(id);