Add container for replies.
[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 Post this reply refers to. */
34         private final Post post;
35
36         /** The time of the reply. */
37         private final long time;
38
39         /** The text of the reply. */
40         private final String text;
41
42         /**
43          * Creates a new reply.
44          *
45          * @param post
46          *            The post to reply to
47          * @param text
48          *            The text of the reply
49          */
50         public Reply(Post post, String text) {
51                 this(post, System.currentTimeMillis(), text);
52         }
53
54         /**
55          * Creates a new reply-
56          *
57          * @param post
58          *            The post to reply to
59          * @param time
60          *            The time of the reply
61          * @param text
62          *            The text of the reply
63          */
64         public Reply(Post post, long time, String text) {
65                 this(UUID.randomUUID(), post, time, text);
66         }
67
68         /**
69          * Creates a new reply-
70          *
71          * @param id
72          *            The ID of the reply
73          * @param post
74          *            The post to reply to
75          * @param time
76          *            The time of the reply
77          * @param text
78          *            The text of the reply
79          */
80         public Reply(UUID id, Post post, long time, String text) {
81                 this.id = id;
82                 this.post = post;
83                 this.time = time;
84                 this.text = text;
85         }
86
87         //
88         // ACCESSORS
89         //
90
91         /**
92          * Returns the ID of the reply.
93          *
94          * @return The ID of the reply
95          */
96         public String getId() {
97                 return id.toString();
98         }
99
100         /**
101          * Returns the post this reply refers to.
102          *
103          * @return The post this reply refers to
104          */
105         public Post getPost() {
106                 return post;
107         }
108
109         /**
110          * Returns the time of the reply.
111          *
112          * @return The time of the reply (in milliseconds since Jan 1, 1970 UTC)
113          */
114         public long getTime() {
115                 return time;
116         }
117
118         /**
119          * Returns the text of the reply.
120          *
121          * @return The text of the reply
122          */
123         public String getText() {
124                 return text;
125         }
126
127         //
128         // OBJECT METHODS
129         //
130
131         /**
132          * {@inheritDoc}
133          */
134         @Override
135         public int hashCode() {
136                 return post.hashCode() ^ id.hashCode();
137         }
138
139         /**
140          * {@inheritDoc}
141          */
142         @Override
143         public boolean equals(Object object) {
144                 if (!(object instanceof Reply)) {
145                         return false;
146                 }
147                 return ((Reply) object).post.equals(post) && ((Reply) object).id.equals(id);
148         }
149
150 }