X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FReply.java;h=2dacfbee93b4085dcd42f2400fc5fc9ea22d8ccd;hb=73be50df4f7b7761fe7f286f2fdb73a142c14926;hp=4429abfbaeebcac8cd42ab6faaac50436d816058;hpb=5baa28c3936cebfa7b5f33f78125d721c8d0e1fc;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/data/Reply.java b/src/main/java/net/pterodactylus/sone/data/Reply.java index 4429abf..2dacfbe 100644 --- a/src/main/java/net/pterodactylus/sone/data/Reply.java +++ b/src/main/java/net/pterodactylus/sone/data/Reply.java @@ -17,8 +17,11 @@ package net.pterodactylus.sone.data; +import java.util.Comparator; import java.util.UUID; +import net.pterodactylus.util.filter.Filter; + /** * A reply is like a {@link Post} but can never be posted on its own, it always * refers to another {@link Post}. @@ -27,20 +30,40 @@ import java.util.UUID; */ public class Reply { + /** Comparator that sorts replies ascending by time. */ + public static final Comparator TIME_COMPARATOR = new Comparator() { + + @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 FUTURE_REPLIES_FILTER = new Filter() { + + @Override + public boolean filterObject(Reply reply) { + return reply.getTime() <= System.currentTimeMillis(); + } + + }; + /** The ID of the reply. */ private final UUID id; /** The Sone that posted this reply. */ - private Sone sone; + private volatile Sone sone; /** The Post this reply refers to. */ - private Post post; + private volatile Post post; /** The time of the reply. */ - private long time; + private volatile long time; /** The text of the reply. */ - private String text; + private volatile String text; /** * Creates a new reply.