Store the originating Sone in the 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 /**
21  * A post is a short message that a user writes in his Sone to let other users
22  * know what is going on.
23  *
24  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
25  */
26 public class Post {
27
28         /** The Sone this post belongs to. */
29         private final Sone sone;
30
31         /** The time of the post (in milliseconds since Jan 1, 1970 UTC). */
32         private final long time;
33
34         /** The text of the post. */
35         private final String text;
36
37         /**
38          * Creates a new post.
39          *
40          * @param sone
41          *            The Sone this post belongs to
42          * @param time
43          *            The time of the post (in milliseconds since Jan 1, 1970 UTC)
44          * @param text
45          *            The text of the post
46          */
47         public Post(Sone sone, long time, String text) {
48                 this.sone = sone;
49                 this.time = time;
50                 this.text = text;
51         }
52
53         /**
54          * Returns the Sone this post belongs to.
55          *
56          * @return The Sone of this post
57          */
58         public Sone getSone() {
59                 return sone;
60         }
61
62         /**
63          * Returns the time of the post.
64          *
65          * @return The time of the post (in milliseconds since Jan 1, 1970 UTC)
66          */
67         public long getTime() {
68                 return time;
69         }
70
71         /**
72          * Returns the text of the post.
73          *
74          * @return The text of the post
75          */
76         public String getText() {
77                 return text;
78         }
79
80         //
81         // OBJECT METHODS
82         //
83
84         /**
85          * {@inheritDoc}
86          */
87         @Override
88         public int hashCode() {
89                 return text.hashCode() ^ (int) (time >> 32) ^ (int) (time & 0xffffffff);
90         }
91
92         /**
93          * {@inheritDoc}
94          */
95         @Override
96         public boolean equals(Object object) {
97                 if (!(object instanceof Post)) {
98                         return false;
99                 }
100                 Post post = (Post) object;
101                 return (post.time == time) && (post.text.equals(text));
102         }
103
104 }