3571172e9127e1e45af91bc14a408368ad210837
[Sone.git] / src / main / java / net / pterodactylus / sone / data / impl / PostReplyImpl.java
1 /*
2  * Sone - PostReplyImpl.java - Copyright © 2010–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.data.impl;
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.database.PostProvider;
25 import net.pterodactylus.sone.database.SoneProvider;
26
27 import com.google.common.base.Optional;
28
29 /**
30  * Simple {@link PostReply} implementation.
31  *
32  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
33  */
34 public class PostReplyImpl extends ReplyImpl<PostReply> implements PostReply {
35
36         /** The post provider. */
37         private final PostProvider postProvider;
38
39         /** The Post this reply refers to. */
40         private final String postId;
41
42         /**
43          * Creates a new reply.
44          *
45          * @param soneProvider
46          *            The Sone provider
47          * @param postProvider
48          *            The post provider
49          * @param id
50          *            The ID of the reply
51          * @param soneId
52          *            The ID of the Sone of the reply
53          * @param time
54          *            The time of the reply
55          * @param text
56          *            The text of the reply
57          * @param postId
58          *            The ID of the post this reply refers to
59          */
60         public PostReplyImpl(SoneProvider soneProvider, PostProvider postProvider, String id, String soneId, long time, String text, String postId) {
61                 super(soneProvider, id, soneId, time, text);
62                 this.postProvider = postProvider;
63                 this.postId = postId;
64         }
65
66         //
67         // ACCESSORS
68         //
69
70         /**
71          * {@inheritDocs}
72          */
73         @Override
74         public String getPostId() {
75                 return postId;
76         }
77
78         /**
79          * {@inheritDoc}
80          */
81         @Override
82         public Optional<Post> getPost() {
83                 return fromNullable(postProvider.getPost(postId));
84         }
85
86 }