Use all parameters for equality.
[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 Sone that posted this reply. */
31         private final Sone sone;
32
33         /** The ID of the reply. */
34         private final UUID id;
35
36         /** The Post this reply refers to. */
37         private final Post post;
38
39         /** The time of the reply. */
40         private final long time;
41
42         /** The text of the reply. */
43         private final 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(sone, UUID.randomUUID(), 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(Sone sone, UUID id, Post post, long time, String text) {
90                 this.sone = sone;
91                 this.id = id;
92                 this.post = post;
93                 this.time = time;
94                 this.text = text;
95         }
96
97         //
98         // ACCESSORS
99         //
100
101         /**
102          * Returns the Sone that posted this reply.
103          *
104          * @return The Sone that posted this reply
105          */
106         public Sone getSone() {
107                 return sone;
108         }
109
110         /**
111          * Returns the ID of the reply.
112          *
113          * @return The ID of the reply
114          */
115         public String getId() {
116                 return id.toString();
117         }
118
119         /**
120          * Returns the post this reply refers to.
121          *
122          * @return The post this reply refers to
123          */
124         public Post getPost() {
125                 return post;
126         }
127
128         /**
129          * Returns the time of the reply.
130          *
131          * @return The time of the reply (in milliseconds since Jan 1, 1970 UTC)
132          */
133         public long getTime() {
134                 return time;
135         }
136
137         /**
138          * Returns the text of the reply.
139          *
140          * @return The text of the reply
141          */
142         public String getText() {
143                 return text;
144         }
145
146         //
147         // OBJECT METHODS
148         //
149
150         /**
151          * {@inheritDoc}
152          */
153         @Override
154         public int hashCode() {
155                 return sone.hashCode() ^ id.hashCode() ^ post.hashCode() ^ (int) (time >> 32) ^ (int) (time & 0xffffffff);
156         }
157
158         /**
159          * {@inheritDoc}
160          */
161         @Override
162         public boolean equals(Object object) {
163                 if (!(object instanceof Reply)) {
164                         return false;
165                 }
166                 Reply reply = (Reply) object;
167                 return reply.sone.equals(sone) && reply.id.equals(id) && reply.post.equals(post) && (reply.time == time) && reply.text.equals(text);
168         }
169
170 }