Add name comparator.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 1 Nov 2010 20:31:50 +0000 (21:31 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 1 Nov 2010 20:31:50 +0000 (21:31 +0100)
src/main/java/net/pterodactylus/sone/data/Sone.java

index 5c0e486..95c7a27 100644 (file)
@@ -41,6 +41,20 @@ import freenet.keys.FreenetURI;
  */
 public class Sone {
 
+       /** comparator that sorts Sones by their nice name. */
+       public static final Comparator<Sone> NICE_NAME_COMPARATOR = new Comparator<Sone>() {
+
+               @Override
+               public int compare(Sone leftSone, Sone rightSone) {
+                       int diff = SoneAccessor.getNiceName(leftSone).compareToIgnoreCase(SoneAccessor.getNiceName(rightSone));
+                       if (diff != 0) {
+                               return diff;
+                       }
+                       return leftSone.getId().compareToIgnoreCase(rightSone.getId());
+               }
+
+       };
+
        /** The logger. */
        private static final Logger logger = Logging.getLogger(Sone.class);