From ac5e77ed4eb9e825ec3f0de347517c630e1b597d Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 8 May 2016 01:53:36 +0800 Subject: [PATCH] Make sure that Artwork is always sorted by rating --- source/net/filebot/web/Artwork.java | 3 +++ source/net/filebot/web/FanartTVClient.java | 2 +- source/net/filebot/web/TMDbClient.java | 2 +- source/net/filebot/web/TheTVDBClient.java | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/source/net/filebot/web/Artwork.java b/source/net/filebot/web/Artwork.java index 1c77923f..148351cd 100644 --- a/source/net/filebot/web/Artwork.java +++ b/source/net/filebot/web/Artwork.java @@ -6,6 +6,7 @@ import static java.util.Collections.*; import java.io.Serializable; import java.net.URL; import java.text.DecimalFormat; +import java.util.Comparator; import java.util.List; import java.util.Locale; import java.util.Objects; @@ -82,4 +83,6 @@ public class Artwork implements Serializable { return asList(String.join("/", tags), language, new DecimalFormat("0.##").format(rating), url).toString(); } + public static final Comparator RATING_ORDER = Comparator.comparing(Artwork::getRating, reverseOrder()); + } diff --git a/source/net/filebot/web/FanartTVClient.java b/source/net/filebot/web/FanartTVClient.java index dfee00c4..adcd96e7 100644 --- a/source/net/filebot/web/FanartTVClient.java +++ b/source/net/filebot/web/FanartTVClient.java @@ -59,7 +59,7 @@ public class FanartTVClient implements Datasource, ArtworkProvider { return null; } }); - }).filter(Objects::nonNull).collect(toList()); + }).filter(Objects::nonNull).sorted(Artwork.RATING_ORDER).collect(toList()); } } diff --git a/source/net/filebot/web/TMDbClient.java b/source/net/filebot/web/TMDbClient.java index 40e8d89e..db8bb022 100644 --- a/source/net/filebot/web/TMDbClient.java +++ b/source/net/filebot/web/TMDbClient.java @@ -288,7 +288,7 @@ public class TMDbClient implements MovieIdentificationService, ArtworkProvider { debug.log(Level.WARNING, e, e::getMessage); return null; } - }).filter(Objects::nonNull).collect(toList()); + }).filter(Objects::nonNull).sorted(Artwork.RATING_ORDER).collect(toList()); } protected Object request(String resource, Map parameters, Locale locale, final FloodLimit limit) throws Exception { diff --git a/source/net/filebot/web/TheTVDBClient.java b/source/net/filebot/web/TheTVDBClient.java index d20b0b64..973b3fe2 100644 --- a/source/net/filebot/web/TheTVDBClient.java +++ b/source/net/filebot/web/TheTVDBClient.java @@ -258,7 +258,7 @@ public class TheTVDBClient extends AbstractEpisodeListProvider implements Artwor debug.log(Level.WARNING, e, e::getMessage); return null; } - }).filter(Objects::nonNull).collect(toList()); + }).filter(Objects::nonNull).sorted(Artwork.RATING_ORDER).collect(toList()); } protected URL resolveBanner(String path) {