2 * Sone - Post.java - Copyright © 2010–2020 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 static com.google.common.base.Optional.absent;
22 import java.util.Comparator;
24 import com.google.common.base.Optional;
25 import com.google.common.base.Predicate;
28 * A post is a short message that a user writes in his Sone to let other users
29 * know what is going on.
31 public interface Post extends Identified {
33 /** Comparator for posts, sorts descending by time. */
34 public static final Comparator<Post> NEWEST_FIRST = new Comparator<Post>() {
37 public int compare(Post leftPost, Post rightPost) {
38 return (int) Math.max(Integer.MIN_VALUE, Math.min(Integer.MAX_VALUE, rightPost.getTime() - leftPost.getTime()));
43 /** Filter for posts with timestamps from the future. */
44 public static final Predicate<Post> FUTURE_POSTS_FILTER = new Predicate<Post>() {
47 public boolean apply(Post post) {
48 return (post != null) && (post.getTime() <= System.currentTimeMillis());
58 * Returns the ID of the post.
60 * @return The ID of the post
62 public String getId();
65 * Returns whether this post has already been loaded.
67 * @return {@code true} if this post has already been loaded, {@code
73 * Returns the Sone this post belongs to.
75 * @return The Sone of this post
77 public Sone getSone();
80 * Returns the ID of the recipient {@link Sone}, or
81 * {@link Optional#absent()} if this post does not have a recipient.
83 * @return The ID of the recipient, or {@link Optional#absent()}
85 public Optional<String> getRecipientId();
88 * Returns the recipient of this post, if any.
90 * @return The recipient of this post, or {@link Optional#absent()} if there
93 public Optional<Sone> getRecipient();
96 * Returns the time of the post.
98 * @return The time of the post (in milliseconds since Jan 1, 1970 UTC)
100 public long getTime();
103 * Returns the text of the post.
105 * @return The text of the post
107 public String getText();
110 * Returns whether this post is known.
112 * @return {@code true} if this post is known, {@code false} otherwise
114 public boolean isKnown();
117 * Sets whether this post is known.
120 * {@code true} if this post is known, {@code false} otherwise
123 public Post setKnown(boolean known);
126 * Shell for a post that has not yet been loaded.
128 public static class EmptyPost implements Post {
130 private final String id;
132 public EmptyPost(String id) {
137 public String getId() {
142 public boolean isLoaded() {
147 public Sone getSone() {
152 public Optional<String> getRecipientId() {
157 public Optional<Sone> getRecipient() {
162 public long getTime() {
167 public String getText() {
172 public boolean isKnown() {
177 public Post setKnown(boolean known) {