From e3ee25879bc4fe405d9a60b4aa5d739223b7c3e8 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 29 Jan 2019 04:07:43 +0700 Subject: [PATCH] Preserve group order according to original file order --- source/net/filebot/media/AutoDetection.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/net/filebot/media/AutoDetection.java b/source/net/filebot/media/AutoDetection.java index dc5ec916..96e85142 100644 --- a/source/net/filebot/media/AutoDetection.java +++ b/source/net/filebot/media/AutoDetection.java @@ -21,12 +21,12 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Comparator; import java.util.EnumMap; +import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Objects; import java.util.Set; -import java.util.TreeMap; import java.util.TreeSet; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -141,12 +141,12 @@ public class AutoDetection { public Map> group() { // sort keys and values - Map> groups = new TreeMap>(); + Map> groups = new LinkedHashMap>(); // can't use parallel stream because default fork/join pool doesn't play well with the security manager ExecutorService workerThreadPool = Executors.newFixedThreadPool(getPreferredThreadPoolSize()); try { - stream(files).collect(toMap(f -> f, f -> workerThreadPool.submit(() -> detectGroup(f)))).forEach((file, group) -> { + stream(files).collect(toMap(f -> f, f -> workerThreadPool.submit(() -> detectGroup(f)), (a, b) -> a, LinkedHashMap::new)).forEach((file, group) -> { try { groups.computeIfAbsent(group.get(), k -> new TreeSet()).add(new File(file.getPath())); // use FastFile internally but do not expose to outside code that expects File objects } catch (Exception e) {