From 8a9a6c62bb97b91a87244cf22d07a2f3fdeb6e50 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 12 Feb 2017 20:08:54 +0800 Subject: [PATCH] groupingBy() does NOT preserve order by default (but we used to assume that it does) --- source/net/filebot/UserFiles.java | 3 ++- source/net/filebot/media/MediaDetection.java | 2 +- source/net/filebot/ui/rename/MovieMatcher.java | 3 ++- .../net/filebot/ui/subtitle/upload/SubtitleUploadDialog.java | 4 +++- source/net/filebot/web/TMDbClient.java | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/source/net/filebot/UserFiles.java b/source/net/filebot/UserFiles.java index 2b630e40..ffe563f0 100644 --- a/source/net/filebot/UserFiles.java +++ b/source/net/filebot/UserFiles.java @@ -16,6 +16,7 @@ import java.awt.event.ActionEvent; import java.io.File; import java.io.IOException; import java.util.Collection; +import java.util.LinkedHashMap; import java.util.List; import java.util.concurrent.Callable; import java.util.concurrent.FutureTask; @@ -57,7 +58,7 @@ public class UserFiles { public static void revealFiles(Collection files) { if (isMacApp()) { - files.stream().collect(groupingBy(File::getParentFile)).forEach((parent, children) -> { + files.stream().collect(groupingBy(File::getParentFile, LinkedHashMap::new, toList())).forEach((parent, children) -> { try { FileManager.revealInFinder(children.get(children.size() - 1)); } catch (Exception e) { diff --git a/source/net/filebot/media/MediaDetection.java b/source/net/filebot/media/MediaDetection.java index be28053b..4b65629a 100644 --- a/source/net/filebot/media/MediaDetection.java +++ b/source/net/filebot/media/MediaDetection.java @@ -1127,7 +1127,7 @@ public class MediaDetection { } } return emptyList(); - })).forEach((group, videos) -> groups.add(videos)); + }, LinkedHashMap::new, toList())).forEach((group, videos) -> groups.add(videos)); }); }); diff --git a/source/net/filebot/ui/rename/MovieMatcher.java b/source/net/filebot/ui/rename/MovieMatcher.java index 3450cf11..3332f9ca 100644 --- a/source/net/filebot/ui/rename/MovieMatcher.java +++ b/source/net/filebot/ui/rename/MovieMatcher.java @@ -19,6 +19,7 @@ import java.util.ArrayList; import java.util.Collection; import java.util.EnumSet; import java.util.HashMap; +import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.List; import java.util.Locale; @@ -195,7 +196,7 @@ class MovieMatcher implements AutoCompleteMatcher { } // map movies to (possibly multiple) files (in natural order) - Map> filesByMovie = movieByFile.entrySet().stream().collect(groupingBy(Entry::getValue, mapping(Entry::getKey, toCollection(TreeSet::new)))); + Map> filesByMovie = movieByFile.entrySet().stream().collect(groupingBy(Entry::getValue, LinkedHashMap::new, mapping(Entry::getKey, toCollection(TreeSet::new)))); // collect all File/MoviePart matches List> matches = new ArrayList>(); diff --git a/source/net/filebot/ui/subtitle/upload/SubtitleUploadDialog.java b/source/net/filebot/ui/subtitle/upload/SubtitleUploadDialog.java index df80b1fc..f08001ab 100644 --- a/source/net/filebot/ui/subtitle/upload/SubtitleUploadDialog.java +++ b/source/net/filebot/ui/subtitle/upload/SubtitleUploadDialog.java @@ -1,6 +1,7 @@ package net.filebot.ui.subtitle.upload; import static java.util.Collections.*; +import static java.util.stream.Collectors.*; import static net.filebot.Logging.*; import static net.filebot.media.MediaDetection.*; import static net.filebot.util.FileUtilities.*; @@ -13,6 +14,7 @@ import java.awt.event.ActionEvent; import java.io.File; import java.util.ArrayList; import java.util.Collection; +import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; @@ -127,7 +129,7 @@ public class SubtitleUploadDialog extends JDialog { } private List getUploadGroups(SubtitleMapping[] table) { - return StreamEx.ofValues(StreamEx.of(table).groupingBy(SubtitleMapping::getGroup)).flatMap(this::groupRunsByCD).toList(); + return StreamEx.ofValues(StreamEx.of(table).groupingBy(SubtitleMapping::getGroup, LinkedHashMap::new, toList())).flatMap(this::groupRunsByCD).toList(); } private Stream groupRunsByCD(Collection group) { diff --git a/source/net/filebot/web/TMDbClient.java b/source/net/filebot/web/TMDbClient.java index 98a89edb..86bd277c 100644 --- a/source/net/filebot/web/TMDbClient.java +++ b/source/net/filebot/web/TMDbClient.java @@ -328,7 +328,7 @@ public class TMDbClient implements MovieIdentificationService, ArtworkProvider { return streamJsonObjects(titles, "titles").collect(groupingBy(it -> { return getString(it, "iso_3166_1"); - }, mapping(it -> { + }, LinkedHashMap::new, mapping(it -> { return getString(it, "title"); }, toList()))); }