-public abstract class Reply<T extends Reply<T>> {
-
- /** Comparator that sorts replies ascending by time. */
- public static final Comparator<Reply<?>> TIME_COMPARATOR = new Comparator<Reply<?>>() {
-
- /**
- * {@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()));
- }
-
- };
-
- /** Filter for replies with timestamps from the future. */
- public static final Filter<Reply<?>> FUTURE_REPLY_FILTER = new Filter<Reply<?>>() {
-
- /**
- * {@inheritDoc}
- */
- @Override
- public boolean filterObject(Reply<?> reply) {
- return reply.getTime() <= System.currentTimeMillis();
- }
-
- };
-
- /** The ID of the reply. */
- private final String id;
-
- /** The Sone that created this reply. */
- private volatile Sone sone;
-
- /** The time of the reply. */
- private volatile long time;
-
- /** The text of the reply. */
- private volatile String text;
-
- /**
- * Creates a new reply with the given ID.
- *
- * @param id
- * The ID of the reply
- */
- protected Reply(String id) {
- this(id, null, 0, null);
- }
-
- /**
- * Creates a new reply with a new random ID.
- *
- * @param sone
- * The Sone of the reply
- * @param time
- * The time of the reply
- * @param text
- * The text of the reply
- */
- protected Reply(Sone sone, long time, String text) {
- this(UUID.randomUUID().toString(), sone, time, text);
- }
-
- /**
- * Creates a new reply.
- *
- * @param id
- * The ID of the reply
- * @param sone
- * The Sone of the reply
- * @param time
- * The time of the reply
- * @param text
- * The text of the reply
- */
- protected Reply(String id, Sone sone, long time, String text) {
- this.id = id;
- this.sone = sone;
- this.time = time;
- this.text = text;
- }