Make episodes sortable.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 18 Feb 2013 20:58:21 +0000 (21:58 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 18 Feb 2013 21:38:39 +0000 (22:38 +0100)
src/main/java/net/pterodactylus/rhynodge/states/EpisodeState.java

index d7d90b2..c604634 100644 (file)
@@ -98,7 +98,7 @@ public class EpisodeState extends AbstractState implements Iterable<Episode> {
         *
         * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
         */
-       public static class Episode implements Iterable<TorrentFile> {
+       public static class Episode implements Comparable<Episode>, Iterable<TorrentFile> {
 
                /** The season of the episode. */
                @JsonProperty
@@ -199,6 +199,26 @@ public class EpisodeState extends AbstractState implements Iterable<Episode> {
                        return torrentFiles.iterator();
                }
 
+               /**
+                * {@inheritDoc}
+                */
+               @Override
+               public int compareTo(Episode episode) {
+                       if (season() < episode.season()) {
+                               return -1;
+                       }
+                       if (season() > episode.season()) {
+                               return 1;
+                       }
+                       if (episode() < episode.episode()) {
+                               return -1;
+                       }
+                       if (episode() > episode.episode()) {
+                               return 1;
+                       }
+                       return 0;
+               }
+
                //
                // OBJECT METHODS
                //