projects
/
Sone.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Remove possibility to create new replies from core interface.
[Sone.git]
/
src
/
main
/
java
/
net
/
pterodactylus
/
sone
/
data
/
Reply.java
diff --git
a/src/main/java/net/pterodactylus/sone/data/Reply.java
b/src/main/java/net/pterodactylus/sone/data/Reply.java
index
62aadea
..
c23426a
100644
(file)
--- a/
src/main/java/net/pterodactylus/sone/data/Reply.java
+++ b/
src/main/java/net/pterodactylus/sone/data/Reply.java
@@
-1,5
+1,5
@@
/*
/*
- * Sone - Reply.java - Copyright © 2010 David Roden
+ * Sone - Reply.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
*
* 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,134
+17,114
@@
package net.pterodactylus.sone.data;
package net.pterodactylus.sone.data;
-import java.util.UUID;
+import java.util.Comparator;
+
+import com.google.common.base.Predicate;
/**
/**
- * A reply is like a {@link Post} but can never be posted on its own, it always
- * refers to another {@link Post}.
+ * Defines methods common for all replies.
*
*
+ * @param <T>
+ * The type of the reply
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
* @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
*/
-public
class Reply
{
+public
interface Reply<T extends Reply<T>>
{
- /**
The ID of the reply
. */
- p
rivate final UUID id;
+ /**
Comparator that sorts replies ascending by time
. */
+ p
ublic static final Comparator<? super Reply<?>> TIME_COMPARATOR = new Comparator<Reply<?>>() {
- /** The Post this reply refers to. */
- private final Post post;
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public int compare(Reply<?> leftReply, Reply<?> rightReply) {
+ return (int) Math.max(Integer.MIN_VALUE, Math.min(Integer.MAX_VALUE, leftReply.getTime() - rightReply.getTime()));
+ }
- /** The time of the reply. */
- private final long time;
+ };
- /**
The text of the reply
. */
- p
rivate final String text;
+ /**
Filter for replies with timestamps from the future
. */
+ p
ublic static final Predicate<Reply<?>> FUTURE_REPLY_FILTER = new Predicate<Reply<?>>() {
- /**
- * Creates a new reply.
- *
- * @param post
- * The post to reply to
- * @param text
- * The text of the reply
- */
- public Reply(Post post, String text) {
- this(post, System.currentTimeMillis(), text);
- }
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean apply(Reply<?> reply) {
+ return reply.getTime() <= System.currentTimeMillis();
+ }
+
+ };
/**
/**
- *
Creates a new reply-
+ *
Returns the ID of the reply.
*
*
- * @param post
- * The post to reply to
- * @param time
- * The time of the reply
- * @param text
- * The text of the reply
+ * @return The ID of the reply
*/
*/
- public Reply(Post post, long time, String text) {
- this(UUID.randomUUID(), post, time, text);
- }
+ public String getId();
/**
/**
- *
Creates a new reply-
+ *
Returns the Sone that posted this reply.
*
*
- * @param id
- * The ID of the reply
- * @param post
- * The post to reply to
- * @param time
- * The time of the reply
- * @param text
- * The text of the reply
+ * @return The Sone that posted this reply
*/
*/
- public Reply(UUID id, Post post, long time, String text) {
- this.id = id;
- this.post = post;
- this.time = time;
- this.text = text;
- }
-
- //
- // ACCESSORS
- //
+ public Sone getSone();
/**
/**
- *
Returns the ID of the
reply.
+ *
Sets the Sone that posted this
reply.
*
*
- * @return The ID of the reply
+ * @param sone
+ * The Sone that posted this reply
+ * @return This reply
*/
*/
- public String getId() {
- return id.toString();
- }
+ public T setSone(Sone sone);
/**
/**
- * Returns the
post this reply refers to
.
+ * Returns the
time of the reply
.
*
*
- * @return The
post this reply refers to
+ * @return The
time of the reply (in milliseconds since Jan 1, 1970 UTC)
*/
*/
- public Post getPost() {
- return post;
- }
+ public long getTime();
/**
/**
- *
Return
s the time of the reply.
+ *
Set
s the time of the reply.
*
*
- * @return The time of the reply (in milliseconds since Jan 1, 1970 UTC)
+ * @param time
+ * The time of the reply (in milliseconds since Jan 1, 1970 UTC)
+ * @return This reply
*/
*/
- public long getTime() {
- return time;
- }
+ public T setTime(long time);
/**
* Returns the text of the reply.
*
* @return The text of the reply
*/
/**
* Returns the text of the reply.
*
* @return The text of the reply
*/
- public String getText() {
- return text;
- }
+ public String getText();
- //
- // OBJECT METHODS
- //
+ /**
+ * Sets the text of the reply.
+ *
+ * @param text
+ * The text of the reply
+ * @return This reply
+ */
+ public T setText(String text);
/**
/**
- * {@inheritDoc}
+ * Returns whether this reply is known.
+ *
+ * @return {@code true} if this reply is known, {@code false} otherwise
*/
*/
- @Override
- public int hashCode() {
- return post.hashCode() ^ id.hashCode();
- }
+ public boolean isKnown();
/**
/**
- * {@inheritDoc}
+ * Sets whether this reply is known.
+ *
+ * @param known
+ * {@code true} if this reply is known, {@code false} otherwise
+ * @return This reply
*/
*/
- @Override
- public boolean equals(Object object) {
- if (!(object instanceof Reply)) {
- return false;
- }
- return ((Reply) object).post.equals(post) && ((Reply) object).id.equals(id);
- }
+ public T setKnown(boolean known);
}
}