Remove @author tags
[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 class MemoryPostReply implements PostReply {
33
34         /** The database. */
35         private final MemoryDatabase database;
36
37         /** The Sone provider. */
38         private final SoneProvider soneProvider;
39
40         /** The ID of the post reply. */
41         private final String id;
42
43         /** The ID of the owning Sone. */
44         private final String soneId;
45
46         /** The time of the post reply. */
47         private final long time;
48
49         /** The text of the post reply. */
50         private final String text;
51
52         /** The ID of the post this post reply refers to. */
53         private final String postId;
54
55         /**
56          * Creates a new memory-based {@link PostReply} implementation.
57          *
58          * @param database
59          *            The database
60          * @param soneProvider
61          *            The Sone provider
62          * @param id
63          *            The ID of the post reply
64          * @param soneId
65          *            The ID of the owning Sone
66          * @param time
67          *            The time of the post reply
68          * @param text
69          *            The text of the post reply
70          * @param postId
71          *            The ID of the post this post reply refers to
72          */
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;
76                 this.id = id;
77                 this.soneId = soneId;
78                 this.time = time;
79                 this.text = text;
80                 this.postId = postId;
81         }
82
83         //
84         // REPLY METHODS
85         //
86
87         /**
88          * {@inheritDocs}
89          */
90         @Override
91         public String getId() {
92                 return id;
93         }
94
95         /**
96          * {@inheritDocs}
97          */
98         @Override
99         public Sone getSone() {
100                 return soneProvider.getSone(soneId);
101         }
102
103         /**
104          * {@inheritDocs}
105          */
106         @Override
107         public long getTime() {
108                 return time;
109         }
110
111         /**
112          * {@inheritDocs}
113          */
114         @Override
115         public String getText() {
116                 return text;
117         }
118
119         /**
120          * {@inheritDocs}
121          */
122         @Override
123         public boolean isKnown() {
124                 return database.isPostReplyKnown(this);
125         }
126
127         /**
128          * {@inheritDocs}
129          */
130         @Override
131         public PostReply setKnown(boolean known) {
132                 database.setPostReplyKnown(this, known);
133                 return this;
134         }
135
136         //
137         // POSTREPLY METHODS
138         //
139
140         /**
141          * {@inheritDocs}
142          */
143         @Override
144         public String getPostId() {
145                 return postId;
146         }
147
148         /**
149          * {@inheritDocs}
150          */
151         @Override
152         public Optional<Post> getPost() {
153                 return fromNullable(database.getPost(postId));
154         }
155
156         //
157         // OBJECT METHODS
158         //
159
160         /**
161          * {@inheritDocs}
162          */
163         @Override
164         public int hashCode() {
165                 return id.hashCode();
166         }
167
168         /**
169          * {@inheritDocs}
170          */
171         @Override
172         public boolean equals(Object object) {
173                 if (!(object instanceof MemoryPostReply)) {
174                         return false;
175                 }
176                 MemoryPostReply memoryPostReply = (MemoryPostReply) object;
177                 return memoryPostReply.id.equals(id);
178         }
179
180 }