Expose following times from FriendProvider
[Sone.git] / src / main / java / net / pterodactylus / sone / database / memory / MemoryPostReply.java
1 /*
2  * Sone - MemoryPostReply.java - Copyright © 2013–2016 David Roden
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.pterodactylus.sone.database.memory;
19
20 import static com.google.common.base.Optional.fromNullable;
21
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;
26
27 import com.google.common.base.Optional;
28
29 /**
30  * Memory-based {@link PostReply} implementation.
31  *
32  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
33  */
34 class MemoryPostReply implements PostReply {
35
36         /** The database. */
37         private final MemoryDatabase database;
38
39         /** The Sone provider. */
40         private final SoneProvider soneProvider;
41
42         /** The ID of the post reply. */
43         private final String id;
44
45         /** The ID of the owning Sone. */
46         private final String soneId;
47
48         /** The time of the post reply. */
49         private final long time;
50
51         /** The text of the post reply. */
52         private final String text;
53
54         /** The ID of the post this post reply refers to. */
55         private final String postId;
56
57         /**
58          * Creates a new memory-based {@link PostReply} implementation.
59          *
60          * @param database
61          *            The database
62          * @param soneProvider
63          *            The Sone provider
64          * @param id
65          *            The ID of the post reply
66          * @param soneId
67          *            The ID of the owning Sone
68          * @param time
69          *            The time of the post reply
70          * @param text
71          *            The text of the post reply
72          * @param postId
73          *            The ID of the post this post reply refers to
74          */
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;
78                 this.id = id;
79                 this.soneId = soneId;
80                 this.time = time;
81                 this.text = text;
82                 this.postId = postId;
83         }
84
85         //
86         // REPLY METHODS
87         //
88
89         /**
90          * {@inheritDocs}
91          */
92         @Override
93         public String getId() {
94                 return id;
95         }
96
97         /**
98          * {@inheritDocs}
99          */
100         @Override
101         public Sone getSone() {
102                 return soneProvider.getSone(soneId);
103         }
104
105         /**
106          * {@inheritDocs}
107          */
108         @Override
109         public long getTime() {
110                 return time;
111         }
112
113         /**
114          * {@inheritDocs}
115          */
116         @Override
117         public String getText() {
118                 return text;
119         }
120
121         /**
122          * {@inheritDocs}
123          */
124         @Override
125         public boolean isKnown() {
126                 return database.isPostReplyKnown(this);
127         }
128
129         /**
130          * {@inheritDocs}
131          */
132         @Override
133         public PostReply setKnown(boolean known) {
134                 database.setPostReplyKnown(this, known);
135                 return this;
136         }
137
138         //
139         // POSTREPLY METHODS
140         //
141
142         /**
143          * {@inheritDocs}
144          */
145         @Override
146         public String getPostId() {
147                 return postId;
148         }
149
150         /**
151          * {@inheritDocs}
152          */
153         @Override
154         public Optional<Post> getPost() {
155                 return fromNullable(database.getPost(postId));
156         }
157
158         //
159         // OBJECT METHODS
160         //
161
162         /**
163          * {@inheritDocs}
164          */
165         @Override
166         public int hashCode() {
167                 return id.hashCode();
168         }
169
170         /**
171          * {@inheritDocs}
172          */
173         @Override
174         public boolean equals(Object object) {
175                 if (!(object instanceof MemoryPostReply)) {
176                         return false;
177                 }
178                 MemoryPostReply memoryPostReply = (MemoryPostReply) object;
179                 return memoryPostReply.id.equals(id);
180         }
181
182 }