From b301f445a5a388431dc9f72aad6935cd2c501f17 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Fri, 26 Feb 2016 17:42:21 +0000 Subject: [PATCH] Fix formatMultiEpisode preview format --- source/net/filebot/web/EpisodeFormat.java | 27 +++++++++-------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/source/net/filebot/web/EpisodeFormat.java b/source/net/filebot/web/EpisodeFormat.java index 3ab01481..2133c500 100644 --- a/source/net/filebot/web/EpisodeFormat.java +++ b/source/net/filebot/web/EpisodeFormat.java @@ -2,22 +2,21 @@ package net.filebot.web; import static java.util.stream.Collectors.*; import static net.filebot.similarity.Normalization.*; -import static net.filebot.util.StringUtilities.*; import java.text.FieldPosition; import java.text.Format; import java.text.ParseException; import java.text.ParsePosition; -import java.util.LinkedHashSet; import java.util.List; -import java.util.Set; import java.util.SortedMap; import java.util.SortedSet; import java.util.TreeMap; import java.util.TreeSet; +import java.util.function.Function; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.IntStream; +import java.util.stream.Stream; public class EpisodeFormat extends Format { @@ -60,15 +59,13 @@ public class EpisodeFormat extends Format { } public String formatMultiEpisode(List episodes) { - Set name = new LinkedHashSet(2); - Set sxe = new LinkedHashSet(2); - Set title = new LinkedHashSet(2); - for (Episode it : episodes) { - name.add(it.getSeriesName()); - sxe.add(formatSxE(it)); - title.add(removeTrailingBrackets(it.getTitle())); - } - return String.format("%s - %s - %s", join(name, " & "), join(" & ", sxe), join(" & ", title)); + Function seriesName = it -> it.getSeriesName(); + Function episodeNumber = it -> formatSxE(it); + Function episodeTitle = it -> removeTrailingBrackets(it.getTitle()); + + return Stream.of(seriesName, episodeNumber, episodeTitle).map(f -> { + return episodes.stream().map(f::apply).distinct().collect(joining(" & ")); + }).collect(joining(" - ")); } public String formatSxE(Episode episode) { @@ -102,7 +99,7 @@ public class EpisodeFormat extends Format { } public String formatMultiTitle(List episodes) { - return episodes.stream().map(e -> removeTrailingBrackets(e.getTitle())).distinct().collect(joining(" & ")); + return episodes.stream().map(it -> removeTrailingBrackets(it.getTitle())).distinct().collect(joining(" & ")); } public String formatMultiRangeSxE(List episodes) { @@ -116,8 +113,7 @@ public class EpisodeFormat extends Format { public String formatMultiRangeNumbers(List episodes, String seasonFormat, String episodeFormat) { return getSeasonEpisodeNumbers(episodes).entrySet().stream().map(it -> { String s = it.getKey() >= 0 ? String.format(seasonFormat, it.getKey()) : ""; - String e = IntStream.of(it.getValue().first(), it.getValue().last()).distinct().mapToObj(i -> String.format(episodeFormat, i)).collect(joining("-")); - return s + e; + return IntStream.of(it.getValue().first(), it.getValue().last()).distinct().mapToObj(i -> String.format(episodeFormat, i)).collect(joining("-", s, "")); }).collect(joining(" - ")); } @@ -126,7 +122,6 @@ public class EpisodeFormat extends Format { for (Episode it : episodes) { Integer s = it.getSeason() == null || it.getSpecial() != null ? it.getSpecial() == null ? -1 : 0 : it.getSeason(); Integer e = it.getEpisode() == null ? it.getSpecial() == null ? -1 : it.getSpecial() : it.getEpisode(); - n.computeIfAbsent(s, key -> new TreeSet()).add(e); } return n;