X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Frhynodge%2Fstates%2FEpisodeState.java;h=5d494e58ce2b66458bc519929fc304fe9224f370;hb=87cc39dc3c43bf007ead00ee8a515bb0636c016e;hp=d7d90b2a60554269ba1ae1c8ed9e8b2de453c391;hpb=6ec36ef950c23c135bf0e112d932c5b7068189b8;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..5d494e5 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 @@ -184,7 +194,9 @@ public class EpisodeState extends AbstractState implements Iterable { * The torrent file to add */ public void addTorrentFile(TorrentFile torrentFile) { - torrentFiles.add(torrentFile); + if (!torrentFiles.contains(torrentFile)) { + torrentFiles.add(torrentFile); + } } // @@ -199,6 +211,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 //