6886a9da2f8e4fb8159ad3984a9e138acb5047e1
[Sone.git] / src / main / java / net / pterodactylus / sone / data / ReplyShell.java
1 /*
2  * Sone - ReplyShell.java - Copyright © 2010 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;
19
20 import java.util.UUID;
21
22 /**
23  * A shell around a {@link Reply} for replies that have not yet been retrieved
24  * from Freenet.
25  *
26  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
27  */
28 public class ReplyShell extends Reply implements Shell<Reply> {
29
30         /** The shell creator. */
31         public static final ShellCreator<Reply> creator = new ShellCreator<Reply>() {
32
33                 @Override
34                 public Shell<Reply> createShell(String id) {
35                         return new ReplyShell().setId(UUID.fromString(id));
36                 }
37         };
38
39         /** The Sone that posted this reply. */
40         private Sone sone;
41
42         /** The ID of the reply. */
43         private UUID id;
44
45         /** The Post this reply refers to. */
46         private Post post;
47
48         /** The time of the reply. */
49         private Long time;
50
51         /** The text of the reply. */
52         private String text;
53
54         /**
55          * Creates a new reply shell.
56          */
57         public ReplyShell() {
58                 super(null, null, null);
59         }
60
61         //
62         // ACCESSORS
63         //
64
65         /**
66          * Returns the Sone that posted this reply.
67          *
68          * @return The Sone that posted this reply
69          */
70         @Override
71         public Sone getSone() {
72                 return sone;
73         }
74
75         /**
76          * Sets the Sone that posted this reply.
77          *
78          * @param sone
79          *            The sone that pasted this reply
80          * @return This reply shell (for method chaining)
81          */
82         public ReplyShell setSone(Sone sone) {
83                 this.sone = sone;
84                 return this;
85         }
86
87         /**
88          * Returns the ID of the reply.
89          *
90          * @return The ID of the reply
91          */
92         @Override
93         public String getId() {
94                 return id.toString();
95         }
96
97         /**
98          * Sets the ID of this reply.
99          *
100          * @param id
101          *            The ID of this reply
102          * @return This reply shell (for method chaining)
103          */
104         public ReplyShell setId(UUID id) {
105                 this.id = id;
106                 return this;
107         }
108
109         /**
110          * Returns the post this reply refers to.
111          *
112          * @return The post this reply refers to
113          */
114         @Override
115         public Post getPost() {
116                 return post;
117         }
118
119         /**
120          * Sets the post this reply refers to.
121          *
122          * @param post
123          *            The post this reply refers to
124          * @return This reply shell (for method chaining)
125          */
126         public ReplyShell setPost(Post post) {
127                 this.post = post;
128                 return this;
129         }
130
131         /**
132          * Returns the time of the reply.
133          *
134          * @return The time of the reply (in milliseconds since Jan 1, 1970 UTC)
135          */
136         @Override
137         public long getTime() {
138                 return time;
139         }
140
141         /**
142          * Sets the time of this reply.
143          *
144          * @param time
145          *            The time of this reply (in milliseconds since Jan 1, 1970 UTC)
146          * @return This reply shell (for method chaining)
147          */
148         public ReplyShell setTime(long time) {
149                 this.time = time;
150                 return this;
151         }
152
153         /**
154          * Returns the text of the reply.
155          *
156          * @return The text of the reply
157          */
158         @Override
159         public String getText() {
160                 return text;
161         }
162
163         /**
164          * Sets the text of the reply.
165          *
166          * @param text
167          *            The text of the reply
168          * @return This reply shell (for method chaining)
169          */
170         public ReplyShell setText(String text) {
171                 this.text = text;
172                 return this;
173         }
174
175         //
176         // INTERFACE Shell
177         //
178
179         /**
180          * {@inheritDoc}
181          */
182         @Override
183         public boolean canUnshell() {
184                 return (sone != null) && (!(sone instanceof Shell<?>)) && (id != null) && (post != null) && (!(post instanceof Shell<?>)) && (time != null) && (text != null);
185         }
186
187         /**
188          * {@inheritDoc}
189          */
190         @Override
191         public Reply getShelled() {
192                 if (canUnshell()) {
193                         return new Reply(sone, id, post, time, text);
194                 }
195                 return this;
196         }
197
198 }