Turn post into an interface, add default implementation.
[Sone.git] / src / main / java / net / pterodactylus / sone / data / Post.java
1 /*
2  * Sone - Post.java - Copyright © 2010–2012 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.Comparator;
21
22 import net.pterodactylus.util.collection.filter.Filter;
23
24 /**
25  * A post is a short message that a user writes in his Sone to let other users
26  * know what is going on.
27  *
28  * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
29  */
30 public interface Post {
31
32         /** Comparator for posts, sorts descending by time. */
33         public static final Comparator<Post> TIME_COMPARATOR = new Comparator<Post>() {
34
35                 @Override
36                 public int compare(Post leftPost, Post rightPost) {
37                         return (int) Math.max(Integer.MIN_VALUE, Math.min(Integer.MAX_VALUE, rightPost.getTime() - leftPost.getTime()));
38                 }
39
40         };
41
42         /** Filter for posts with timestamps from the future. */
43         public static final Filter<Post> FUTURE_POSTS_FILTER = new Filter<Post>() {
44
45                 @Override
46                 public boolean filterObject(Post post) {
47                         return post.getTime() <= System.currentTimeMillis();
48                 }
49
50         };
51
52         //
53         // ACCESSORS
54         //
55
56         /**
57          * Returns the ID of the post.
58          *
59          * @return The ID of the post
60          */
61         public String getId();
62
63         /**
64          * Returns the Sone this post belongs to.
65          *
66          * @return The Sone of this post
67          */
68         public Sone getSone();
69
70         /**
71          * Sets the Sone of this post.
72          *
73          * @param sone
74          *            The Sone of this post
75          * @return This post (for method chaining)
76          */
77         public Post setSone(Sone sone);
78
79         /**
80          * Returns the recipient of this post, if any.
81          *
82          * @return The recipient of this post, or {@code null}
83          */
84         public Sone getRecipient();
85
86         /**
87          * Sets the recipient of this post.
88          *
89          * @param recipient
90          *            The recipient of this post, or {@code null}
91          * @return This post (for method chaining)
92          */
93         public Post setRecipient(Sone recipient);
94
95         /**
96          * Returns the time of the post.
97          *
98          * @return The time of the post (in milliseconds since Jan 1, 1970 UTC)
99          */
100         public long getTime();
101
102         /**
103          * Sets the time of this post.
104          *
105          * @param time
106          *            The time of this post (in milliseconds since Jan 1, 1970 UTC)
107          * @return This post (for method chaining)
108          */
109         public Post setTime(long time);
110
111         /**
112          * Returns the text of the post.
113          *
114          * @return The text of the post
115          */
116         public String getText();
117
118         /**
119          * Sets the text of this post.
120          *
121          * @param text
122          *            The text of this post
123          * @return This post (for method chaining)
124          */
125         public Post setText(String text);
126
127         /**
128          * Returns whether this post is known.
129          *
130          * @return {@code true} if this post is known, {@code false} otherwise
131          */
132         public boolean isKnown();
133
134         /**
135          * Sets whether this post is known.
136          *
137          * @param known
138          *            {@code true} if this post is known, {@code false} otherwise
139          * @return This post
140          */
141         public Post setKnown(boolean known);
142
143 }