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