X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Frhynodge%2Fstates%2FEpisodeState.java;h=7ed3dcecd9ec3d725be693e74af20b308c3b0e9e;hb=6ea5acf682dec9e234df216e61a60bb23cdd5d0c;hp=d7d90b2a60554269ba1ae1c8ed9e8b2de453c391;hpb=6f69aff66ba5617d0bb27874014b4274bc551ab8;p=rhynodge.git diff --git a/src/main/java/net/pterodactylus/rhynodge/states/EpisodeState.java b/src/main/java/net/pterodactylus/rhynodge/states/EpisodeState.java index d7d90b2..7ed3dce 100644 --- a/src/main/java/net/pterodactylus/rhynodge/states/EpisodeState.java +++ b/src/main/java/net/pterodactylus/rhynodge/states/EpisodeState.java @@ -29,6 +29,7 @@ import net.pterodactylus.rhynodge.states.EpisodeState.Episode; import net.pterodactylus.rhynodge.states.TorrentState.TorrentFile; import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.common.base.Function; /** * {@link State} implementation that stores episodes of TV shows, parsed via @@ -98,7 +99,16 @@ public class EpisodeState extends AbstractState implements Iterable { * * @author David ‘Bombe’ Roden */ - public static class Episode implements Iterable { + public static class Episode implements Comparable, Iterable { + + /** Function to extract the season of an episode. */ + public static final Function BY_SEASON = new Function() { + + @Override + public Integer apply(Episode episode) { + return episode.season(); + } + }; /** The season of the episode. */ @JsonProperty @@ -199,6 +209,26 @@ public class EpisodeState extends AbstractState implements Iterable { 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 //