From 49710f27f9528c31cd93d82c2f010d1c40bea18c Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 9 Feb 2016 13:34:55 +0000 Subject: [PATCH] Refactor --- .../ui/subtitle/upload/SubtitleUploadDialog.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/source/net/filebot/ui/subtitle/upload/SubtitleUploadDialog.java b/source/net/filebot/ui/subtitle/upload/SubtitleUploadDialog.java index 6e53ac67..b24ac2c5 100644 --- a/source/net/filebot/ui/subtitle/upload/SubtitleUploadDialog.java +++ b/source/net/filebot/ui/subtitle/upload/SubtitleUploadDialog.java @@ -21,6 +21,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; +import java.util.stream.Stream; import javax.swing.JComponent; import javax.swing.JDialog; @@ -125,10 +126,12 @@ public class SubtitleUploadDialog extends JDialog { return i; } - private List groupRunsByCD(SubtitleMapping[] table) { - return StreamEx.ofValues(StreamEx.of(table).sortedBy(SubtitleMapping::getVideo).groupingBy(SubtitleMapping::getGroup)).flatMap((group) -> { - return StreamEx.of(group).groupRuns((m1, m2) -> getCD(m1) + 1 == getCD(m2)).map(SubtitleGroup::new); - }).toList(); + private List getUploadGroups(SubtitleMapping[] table) { + return StreamEx.ofValues(StreamEx.of(table).groupingBy(SubtitleMapping::getGroup)).flatMap(this::groupRunsByCD).toList(); + } + + private Stream groupRunsByCD(Collection group) { + return StreamEx.of(group).sortedBy(SubtitleMapping::getVideo).groupRuns((m1, m2) -> getCD(m1) + 1 == getCD(m2)).map(SubtitleGroup::new); } private void runCheck(SubtitleMapping mapping) { @@ -226,7 +229,7 @@ public class SubtitleUploadDialog extends JDialog { uploadExecutorService = Executors.newSingleThreadExecutor(); SubtitleMapping[] table = ((SubtitleMappingTableModel) subtitleMappingTable.getModel()).getData(); - for (SubtitleGroup group : groupRunsByCD(table)) { + for (SubtitleGroup group : getUploadGroups(table)) { if (group.isUploadReady()) { uploadExecutorService.submit(() -> runUpload(group)); }