Remove replies from post.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Post.java
1 /*
2  * FreenetSone - StatusUpdate.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 post is a short message that a user writes in his Sone to let other users
24  * know what is going on.
25  *
26  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
27  */
28 public class Post {
29
30         /** The GUID of the post. */
31         private final UUID id;
32
33         /** The Sone this post belongs to. */
34         private Sone sone;
35
36         /** The time of the post (in milliseconds since Jan 1, 1970 UTC). */
37         private long time;
38
39         /** The text of the post. */
40         private String text;
41
42         /**
43          * Creates a new post.
44          *
45          * @param id
46          *            The ID of the post
47          */
48         public Post(String id) {
49                 this(id, null, 0, null);
50         }
51
52         /**
53          * Creates a new post.
54          *
55          * @param sone
56          *            The Sone this post belongs to
57          * @param text
58          *            The text of the post
59          */
60         public Post(Sone sone, String text) {
61                 this(sone, System.currentTimeMillis(), text);
62         }
63
64         /**
65          * Creates a new post.
66          *
67          * @param sone
68          *            The Sone this post belongs to
69          * @param time
70          *            The time of the post (in milliseconds since Jan 1, 1970 UTC)
71          * @param text
72          *            The text of the post
73          */
74         public Post(Sone sone, long time, String text) {
75                 this(UUID.randomUUID().toString(), sone, time, text);
76         }
77
78         /**
79          * Creates a new post.
80          *
81          * @param id
82          *            The ID of the post
83          * @param sone
84          *            The Sone this post belongs to
85          * @param time
86          *            The time of the post (in milliseconds since Jan 1, 1970 UTC)
87          * @param text
88          *            The text of the post
89          */
90         public Post(String id, Sone sone, long time, String text) {
91                 this.id = UUID.fromString(id);
92                 this.sone = sone;
93                 this.time = time;
94                 this.text = text;
95         }
96
97         //
98         // ACCESSORS
99         //
100
101         /**
102          * Returns the ID of the post.
103          *
104          * @return The ID of the post
105          */
106         public String getId() {
107                 return id.toString();
108         }
109
110         /**
111          * Returns the Sone this post belongs to.
112          *
113          * @return The Sone of this post
114          */
115         public Sone getSone() {
116                 return sone;
117         }
118
119         /**
120          * Sets the Sone of this post.
121          *
122          * @param sone
123          *            The Sone of this post
124          * @return This post (for method chaining)
125          */
126         public Post setSone(Sone sone) {
127                 this.sone = sone;
128                 return this;
129         }
130
131         /**
132          * Returns the time of the post.
133          *
134          * @return The time of the post (in milliseconds since Jan 1, 1970 UTC)
135          */
136         public long getTime() {
137                 return time;
138         }
139
140         /**
141          * Sets the time of this post.
142          *
143          * @param time
144          *            The time of this post (in milliseconds since Jan 1, 1970 UTC)
145          * @return This post (for method chaining)
146          */
147         public Post setTime(long time) {
148                 this.time = time;
149                 return this;
150         }
151
152         /**
153          * Returns the text of the post.
154          *
155          * @return The text of the post
156          */
157         public String getText() {
158                 return text;
159         }
160
161         /**
162          * Sets the text of this post.
163          *
164          * @param text
165          *            The text of this post
166          * @return This post (for method chaining)
167          */
168         public Post setText(String text) {
169                 this.text = text;
170                 return this;
171         }
172
173         //
174         // OBJECT METHODS
175         //
176
177         /**
178          * {@inheritDoc}
179          */
180         @Override
181         public int hashCode() {
182                 return id.hashCode() ^ sone.hashCode() ^ (int) (time >> 32) ^ (int) (time & 0xffffffff) ^ text.hashCode();
183         }
184
185         /**
186          * {@inheritDoc}
187          */
188         @Override
189         public boolean equals(Object object) {
190                 if (!(object instanceof Post)) {
191                         return false;
192                 }
193                 Post post = (Post) object;
194                 return post.id.equals(id) && post.sone.equals(sone) && (post.time == time) && post.text.equals(text);
195         }
196
197         /**
198          * {@inheritDoc}
199          */
200         @Override
201         public String toString() {
202                 return getClass().getName() + "[id=" + id + ",sone=" + sone + ",time=" + time + ",text=" + text + "]";
203         }
204
205 }