From: David ‘Bombe’ Roden Date: Fri, 5 Nov 2010 22:41:41 +0000 (+0100) Subject: Add post comparator that sorts by time. X-Git-Tag: 0.2-RC1~7 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=e23887b689392f9a4a9f65b53b644d379b94bc3a;p=Sone.git Add post comparator that sorts by time. --- diff --git a/src/main/java/net/pterodactylus/sone/data/Post.java b/src/main/java/net/pterodactylus/sone/data/Post.java index c30665a..654b827 100644 --- a/src/main/java/net/pterodactylus/sone/data/Post.java +++ b/src/main/java/net/pterodactylus/sone/data/Post.java @@ -17,6 +17,7 @@ package net.pterodactylus.sone.data; +import java.util.Comparator; import java.util.UUID; /** @@ -27,6 +28,16 @@ import java.util.UUID; */ public class Post { + /** 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 GUID of the post. */ private final UUID id;