Merge branch 'master' into next
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Reply.java
1 /*
2  * Sone - Reply.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 reply is like a {@link Post} but can never be posted on its own, it always
24  * refers to another {@link Post}.
25  *
26  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
27  */
28 public class Reply {
29
30         /** The ID of the reply. */
31         private final UUID id;
32
33         /** The Sone that posted this reply. */
34         private volatile Sone sone;
35
36         /** The Post this reply refers to. */
37         private volatile Post post;
38
39         /** The time of the reply. */
40         private volatile long time;
41
42         /** The text of the reply. */
43         private volatile String text;
44
45         /**
46          * Creates a new reply.
47          *
48          * @param id
49          *            The ID of the reply
50          */
51         public Reply(String id) {
52                 this(id, null, null, 0, null);
53         }
54
55         /**
56          * Creates a new reply.
57          *
58          * @param sone
59          *            The sone that posted the reply
60          * @param post
61          *            The post to reply to
62          * @param text
63          *            The text of the reply
64          */
65         public Reply(Sone sone, Post post, String text) {
66                 this(sone, post, System.currentTimeMillis(), text);
67         }
68
69         /**
70          * Creates a new reply-
71          *
72          * @param sone
73          *            The sone that posted the reply
74          * @param post
75          *            The post to reply to
76          * @param time
77          *            The time of the reply
78          * @param text
79          *            The text of the reply
80          */
81         public Reply(Sone sone, Post post, long time, String text) {
82                 this(UUID.randomUUID().toString(), sone, post, time, text);
83         }
84
85         /**
86          * Creates a new reply-
87          *
88          * @param sone
89          *            The sone that posted the reply
90          * @param id
91          *            The ID of the reply
92          * @param post
93          *            The post to reply to
94          * @param time
95          *            The time of the reply
96          * @param text
97          *            The text of the reply
98          */
99         public Reply(String id, Sone sone, Post post, long time, String text) {
100                 this.id = UUID.fromString(id);
101                 this.sone = sone;
102                 this.post = post;
103                 this.time = time;
104                 this.text = text;
105         }
106
107         //
108         // ACCESSORS
109         //
110
111         /**
112          * Returns the ID of the reply.
113          *
114          * @return The ID of the reply
115          */
116         public String getId() {
117                 return id.toString();
118         }
119
120         /**
121          * Returns the Sone that posted this reply.
122          *
123          * @return The Sone that posted this reply
124          */
125         public Sone getSone() {
126                 return sone;
127         }
128
129         /**
130          * Sets the Sone that posted this reply.
131          *
132          * @param sone
133          *            The Sone that posted this reply
134          * @return This reply (for method chaining)
135          */
136         public Reply setSone(Sone sone) {
137                 this.sone = sone;
138                 return this;
139         }
140
141         /**
142          * Returns the post this reply refers to.
143          *
144          * @return The post this reply refers to
145          */
146         public Post getPost() {
147                 return post;
148         }
149
150         /**
151          * Sets the post this reply refers to.
152          *
153          * @param post
154          *            The post this reply refers to
155          * @return This reply (for method chaining)
156          */
157         public Reply setPost(Post post) {
158                 this.post = post;
159                 return this;
160         }
161
162         /**
163          * Returns the time of the reply.
164          *
165          * @return The time of the reply (in milliseconds since Jan 1, 1970 UTC)
166          */
167         public long getTime() {
168                 return time;
169         }
170
171         /**
172          * Sets the time of this reply.
173          *
174          * @param time
175          *            The time of this reply (in milliseconds since Jan 1, 1970 UTC)
176          * @return This reply (for method chaining)
177          */
178         public Reply setTime(long time) {
179                 this.time = time;
180                 return this;
181         }
182
183         /**
184          * Returns the text of the reply.
185          *
186          * @return The text of the reply
187          */
188         public String getText() {
189                 return text;
190         }
191
192         /**
193          * Sets the text of this reply.
194          *
195          * @param text
196          *            The text of this reply
197          * @return This reply (for method chaining)
198          */
199         public Reply setText(String text) {
200                 this.text = text;
201                 return this;
202         }
203
204         //
205         // OBJECT METHODS
206         //
207
208         /**
209          * {@inheritDoc}
210          */
211         @Override
212         public int hashCode() {
213                 return id.hashCode();
214         }
215
216         /**
217          * {@inheritDoc}
218          */
219         @Override
220         public boolean equals(Object object) {
221                 if (!(object instanceof Reply)) {
222                         return false;
223                 }
224                 Reply reply = (Reply) object;
225                 return reply.id.equals(id);
226         }
227
228         /**
229          * {@inheritDoc}
230          */
231         @Override
232         public String toString() {
233                 return getClass().getName() + "[id=" + id + ",sone=" + sone + ",post=" + post + ",time=" + time + ",text=" + text + "]";
234         }
235
236 }