X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fdata%2FReply.java;h=a1063917692196b98ae1c5ea879b445a700c2b19;hb=e31ead2b972074c1e5ecc5213b2bdc34c453d8b6;hp=60bbc6d00ca1a4835933d6ab3f4760cb00f86528;hpb=d429bc07de2c62921323f300024c2df348ae71cf;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 60bbc6d..a106391 100644 --- a/src/main/java/net/pterodactylus/sone/data/Reply.java +++ b/src/main/java/net/pterodactylus/sone/data/Reply.java @@ -17,6 +17,7 @@ package net.pterodactylus.sone.data; +import java.util.Comparator; import java.util.UUID; /** @@ -27,20 +28,30 @@ 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())); + } + + }; + /** 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. @@ -210,7 +221,7 @@ public class Reply { */ @Override public int hashCode() { - return sone.hashCode() ^ id.hashCode() ^ post.hashCode() ^ (int) (time >> 32) ^ (int) (time & 0xffffffff) ^ text.hashCode(); + return id.hashCode(); } /** @@ -222,7 +233,7 @@ public class Reply { return false; } Reply reply = (Reply) object; - return reply.sone.equals(sone) && reply.id.equals(id) && reply.post.equals(post) && (reply.time == time) && reply.text.equals(text); + return reply.id.equals(id); } /**