Add last activity comparator.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 20 Jun 2011 05:52:43 +0000 (07:52 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 20 Jun 2011 05:52:43 +0000 (07:52 +0200)
src/main/java/net/pterodactylus/sone/data/Sone.java

index e1c0391..ca87856 100644 (file)
@@ -60,6 +60,17 @@ public class Sone implements Fingerprintable, Comparable<Sone> {
 
        };
 
+       /**
+        * Comparator that sorts Sones by last activity (least recent active first).
+        */
+       public static final Comparator<Sone> LAST_ACTIVITY_COMPARATOR = new Comparator<Sone>() {
+
+               @Override
+               public int compare(Sone firstSone, Sone secondSone) {
+                       return (int) Math.min(Integer.MAX_VALUE, Math.max(Integer.MIN_VALUE, secondSone.getTime() - firstSone.getTime()));
+               }
+       };
+
        /** Filter to remove Sones that have not been downloaded. */
        public static final Filter<Sone> EMPTY_SONE_FILTER = new Filter<Sone>() {