X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=inline;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FPost.java;h=2524207c13f433a2024d580d9bb6aa952b7eeebe;hb=7b8fc206a4da09d1b4f61e8eea674ca0bbe5872b;hp=3c02a1c55462c9b64efcb3309b1c8f0dd5548628;hpb=6ddf54f1380880aedc9049342cbd796a528d4208;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/data/Post.java b/src/main/java/net/pterodactylus/sone/data/Post.java
index 3c02a1c..2524207 100644
--- a/src/main/java/net/pterodactylus/sone/data/Post.java
+++ b/src/main/java/net/pterodactylus/sone/data/Post.java
@@ -1,5 +1,5 @@
/*
- * FreenetSone - StatusUpdate.java - Copyright © 2010 David Roden
+ * Sone - Post.java - Copyright © 2010â2013 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -17,73 +17,101 @@
package net.pterodactylus.sone.data;
+import java.util.Comparator;
+
+import com.google.common.base.Optional;
+import com.google.common.base.Predicate;
+
/**
* A post is a short message that a user writes in his Sone to let other users
* know what is going on.
*
* @author David âBombeâ Roden
*/
-public class Post {
+public interface Post extends Identified {
+
+ /** Comparator for posts, sorts descending by time. */
+ public static final Comparator TIME_COMPARATOR = new Comparator() {
+
+ @Override
+ public int compare(Post leftPost, Post rightPost) {
+ return (int) Math.max(Integer.MIN_VALUE, Math.min(Integer.MAX_VALUE, rightPost.getTime() - leftPost.getTime()));
+ }
+
+ };
- /** The time of the post (in milliseconds since Jan 1, 1970 UTC). */
- private final long time;
+ /** Filter for posts with timestamps from the future. */
+ public static final Predicate FUTURE_POSTS_FILTER = new Predicate() {
+
+ @Override
+ public boolean apply(Post post) {
+ return post.getTime() <= System.currentTimeMillis();
+ }
- /** The text of the post. */
- private final String text;
+ };
+
+ //
+ // ACCESSORS
+ //
+
+ /**
+ * Returns the ID of the post.
+ *
+ * @return The ID of the post
+ */
+ public String getId();
/**
- * Creates a new post.
+ * Returns the Sone this post belongs to.
*
- * @param time
- * The time of the post (in milliseconds since Jan 1, 1970 UTC)
- * @param text
- * The text of the post
+ * @return The Sone of this post
*/
- public Post(long time, String text) {
- this.time = time;
- this.text = text;
- }
+ public Sone getSone();
+
+ /**
+ * Returns the ID of the recipient {@link Sone}, or
+ * {@link Optional#absent()} if this post does not have a recipient.
+ *
+ * @return The ID of the recipient, or {@link Optional#absent()}
+ */
+ public Optional getRecipientId();
+
+ /**
+ * Returns the recipient of this post, if any.
+ *
+ * @return The recipient of this post, or {@link Optional#absent()} if there
+ * is no recipient
+ */
+ public Optional getRecipient();
/**
* Returns the time of the post.
*
* @return The time of the post (in milliseconds since Jan 1, 1970 UTC)
*/
- public long getTime() {
- return time;
- }
+ public long getTime();
/**
* Returns the text of the post.
*
* @return The text of the post
*/
- public String getText() {
- return text;
- }
-
- //
- // OBJECT METHODS
- //
+ public String getText();
/**
- * {@inheritDoc}
+ * Returns whether this post is known.
+ *
+ * @return {@code true} if this post is known, {@code false} otherwise
*/
- @Override
- public int hashCode() {
- return text.hashCode() ^ (int) (time >> 32) ^ (int) (time & 0xffffffff);
- }
+ public boolean isKnown();
/**
- * {@inheritDoc}
+ * Sets whether this post is known.
+ *
+ * @param known
+ * {@code true} if this post is known, {@code false} otherwise
+ * @return This post
*/
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof Post)) {
- return false;
- }
- Post post = (Post) object;
- return (post.time == time) && (post.text.equals(text));
- }
+ public Post setKnown(boolean known);
}