2 * Sone - Post.java - Copyright © 2010–2013 David Roden
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.
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.
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/>.
18 package net.pterodactylus.sone.data;
20 import java.util.Comparator;
22 import com.google.common.base.Predicate;
25 * A post is a short message that a user writes in his Sone to let other users
26 * know what is going on.
28 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
30 public interface Post {
32 /** Comparator for posts, sorts descending by time. */
33 public static final Comparator<Post> TIME_COMPARATOR = new Comparator<Post>() {
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()));
42 /** Filter for posts with timestamps from the future. */
43 public static final Predicate<Post> FUTURE_POSTS_FILTER = new Predicate<Post>() {
46 public boolean apply(Post post) {
47 return post.getTime() <= System.currentTimeMillis();
57 * Returns the ID of the post.
59 * @return The ID of the post
61 public String getId();
64 * Returns the Sone this post belongs to.
66 * @return The Sone of this post
68 public Sone getSone();
71 * Returns the recipient of this post, if any.
73 * @return The recipient of this post, or {@code null}
75 public Sone getRecipient();
78 * Returns the time of the post.
80 * @return The time of the post (in milliseconds since Jan 1, 1970 UTC)
82 public long getTime();
85 * Returns the text of the post.
87 * @return The text of the post
89 public String getText();
92 * Returns whether this post is known.
94 * @return {@code true} if this post is known, {@code false} otherwise
96 public boolean isKnown();
99 * Sets whether this post is known.
102 * {@code true} if this post is known, {@code false} otherwise
105 public Post setKnown(boolean known);