* String.join works slightly different than our own join() method, so to avoid any hidden issues keep using our own as before

This commit is contained in:
Reinhard Pointner 2015-05-25 10:37:42 +00:00
parent ea26287b92
commit aa5d5c901c
15 changed files with 31 additions and 19 deletions

View File

@ -1,6 +1,7 @@
package net.filebot; package net.filebot;
import static net.filebot.util.FileUtilities.*; import static net.filebot.util.FileUtilities.*;
import static net.filebot.util.StringUtilities.*;
import java.awt.GraphicsEnvironment; import java.awt.GraphicsEnvironment;
import java.io.File; import java.io.File;
@ -285,14 +286,14 @@ public final class Settings {
} }
public static String getApplicationIdentifier() { public static String getApplicationIdentifier() {
return String.join(" ", getApplicationName(), getApplicationVersion(), String.format("(r%s)", getApplicationRevisionNumber())); return join(" ", getApplicationName(), getApplicationVersion(), String.format("(r%s)", getApplicationRevisionNumber()));
} }
public static String getJavaRuntimeIdentifier() { public static String getJavaRuntimeIdentifier() {
String name = System.getProperty("java.runtime.name"); String name = System.getProperty("java.runtime.name");
String version = System.getProperty("java.version"); String version = System.getProperty("java.version");
String headless = GraphicsEnvironment.isHeadless() ? "(headless)" : null; String headless = GraphicsEnvironment.isHeadless() ? "(headless)" : null;
return String.join(" ", name, version, headless); return join(" ", name, version, headless);
} }
private static String[] applicationArgumentArray; private static String[] applicationArgumentArray;

View File

@ -5,6 +5,7 @@ import static java.util.Collections.*;
import static net.filebot.Settings.*; import static net.filebot.Settings.*;
import static net.filebot.media.MediaDetection.*; import static net.filebot.media.MediaDetection.*;
import static net.filebot.util.FileUtilities.*; import static net.filebot.util.FileUtilities.*;
import static net.filebot.util.StringUtilities.*;
import java.io.IOException; import java.io.IOException;
import java.util.LinkedHashSet; import java.util.LinkedHashSet;
@ -256,7 +257,7 @@ public final class WebServices {
if (LOGIN_OPENSUBTITLES.equals(id)) { if (LOGIN_OPENSUBTITLES.equals(id)) {
String password_md5 = md5(password); String password_md5 = md5(password);
OpenSubtitles.setUser(user, password_md5); OpenSubtitles.setUser(user, password_md5);
Settings.forPackage(WebServices.class).put(id, String.join(LOGIN_SEPARATOR, user, password_md5)); Settings.forPackage(WebServices.class).put(id, join(LOGIN_SEPARATOR, user, password_md5));
} else { } else {
throw new IllegalArgumentException(); throw new IllegalArgumentException();
} }

View File

@ -157,7 +157,7 @@ public class MediaBindingBean {
for (Episode it : getEpisodes()) { for (Episode it : getEpisodes()) {
title.add(removeTrailingBrackets(it.getTitle())); title.add(removeTrailingBrackets(it.getTitle()));
} }
return truncateText(String.join(" & ", title), limit); return truncateText(join(title, " & "), limit);
} }
@Define("d") @Define("d")
@ -353,7 +353,7 @@ public class MediaBindingBean {
return null; return null;
// e.g. 1280x720 // e.g. 1280x720
return String.join("x", dim.get(0).toString(), dim.get(1).toString()); return join(dim, "x");
} }
@Define("ws") @Define("ws")

View File

@ -7,6 +7,7 @@ import static net.filebot.Settings.*;
import static net.filebot.similarity.CommonSequenceMatcher.*; import static net.filebot.similarity.CommonSequenceMatcher.*;
import static net.filebot.similarity.Normalization.*; import static net.filebot.similarity.Normalization.*;
import static net.filebot.util.FileUtilities.*; import static net.filebot.util.FileUtilities.*;
import static net.filebot.util.StringUtilities.*;
import java.io.File; import java.io.File;
import java.io.FileFilter; import java.io.FileFilter;
@ -1046,7 +1047,7 @@ public class MediaDetection {
relativePath.addFirst(it.getName()); relativePath.addFirst(it.getName());
} }
return relativePath.isEmpty() ? null : new File(String.join(File.separator, relativePath)); return relativePath.isEmpty() ? null : new File(join(relativePath, File.separator));
} }
public static Map<File, List<File>> mapByMediaFolder(Collection<File> files) { public static Map<File, List<File>> mapByMediaFolder(Collection<File> files) {

View File

@ -38,7 +38,6 @@ import net.filebot.web.CachedResource;
import net.filebot.web.Movie; import net.filebot.web.Movie;
import net.filebot.web.SubtitleSearchResult; import net.filebot.web.SubtitleSearchResult;
import net.filebot.web.TheTVDBSearchResult; import net.filebot.web.TheTVDBSearchResult;
import net.filebot.web.SubtitleSearchResult.Kind;
import org.tukaani.xz.XZInputStream; import org.tukaani.xz.XZInputStream;

View File

@ -5,6 +5,7 @@ import static java.util.Collections.*;
import static java.util.regex.Pattern.*; import static java.util.regex.Pattern.*;
import static net.filebot.similarity.Normalization.*; import static net.filebot.similarity.Normalization.*;
import static net.filebot.util.FileUtilities.*; import static net.filebot.util.FileUtilities.*;
import static net.filebot.util.StringUtilities.*;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -435,7 +436,7 @@ public enum EpisodeMetrics implements SimilarityMetric {
while (scanner.hasNextInt()) { while (scanner.hasNextInt()) {
numbers.add(String.valueOf(scanner.nextInt())); numbers.add(String.valueOf(scanner.nextInt()));
} }
return String.join(" ", numbers); return join(numbers, " ");
} }
}), }),

View File

@ -4,6 +4,7 @@ import static java.util.Collections.*;
import static java.util.regex.Pattern.*; import static java.util.regex.Pattern.*;
import static net.filebot.similarity.CommonSequenceMatcher.*; import static net.filebot.similarity.CommonSequenceMatcher.*;
import static net.filebot.similarity.Normalization.*; import static net.filebot.similarity.Normalization.*;
import static net.filebot.util.StringUtilities.*;
import java.io.File; import java.io.File;
import java.text.CollationKey; import java.text.CollationKey;
@ -99,7 +100,7 @@ public class SeriesNameMatcher {
whitelist.addAll(deepMatchAll(focus, threshold)); whitelist.addAll(deepMatchAll(focus, threshold));
// 1. use pattern matching // 1. use pattern matching
seriesNames.addAll(flatMatchAll(names, compile(String.join("|", whitelist), CASE_INSENSITIVE | UNICODE_CHARACTER_CLASS), threshold, false)); seriesNames.addAll(flatMatchAll(names, compile(join(whitelist, "|"), CASE_INSENSITIVE | UNICODE_CHARACTER_CLASS), threshold, false));
// 2. use common word sequences // 2. use common word sequences
seriesNames.addAll(whitelist); seriesNames.addAll(whitelist);

View File

@ -1,5 +1,7 @@
package net.filebot.subtitle; package net.filebot.subtitle;
import static net.filebot.util.StringUtilities.*;
import java.text.DateFormat; import java.text.DateFormat;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
@ -48,7 +50,7 @@ public class SubRipReader extends SubtitleReader {
lines.add(line); lines.add(line);
} }
return new SubtitleElement(t1, t2, resolve(String.join("\n", lines))); return new SubtitleElement(t1, t2, resolve(join(lines, "\n")));
} }
protected String resolve(String text) { protected String resolve(String text) {

View File

@ -6,6 +6,7 @@ import static net.filebot.Settings.*;
import static net.filebot.WebServices.*; import static net.filebot.WebServices.*;
import static net.filebot.media.MediaDetection.*; import static net.filebot.media.MediaDetection.*;
import static net.filebot.util.FileUtilities.*; import static net.filebot.util.FileUtilities.*;
import static net.filebot.util.StringUtilities.*;
import static net.filebot.util.ui.SwingUI.*; import static net.filebot.util.ui.SwingUI.*;
import java.awt.Component; import java.awt.Component;
@ -285,7 +286,7 @@ class EpisodeListMatcher implements AutoCompleteMatcher {
if (episodes.isEmpty() && !strict) { if (episodes.isEmpty() && !strict) {
List<String> detectedSeriesNames = detectSeriesNames(files, useSeriesIndex, useAnimeIndex, locale); List<String> detectedSeriesNames = detectSeriesNames(files, useSeriesIndex, useAnimeIndex, locale);
String parentPathHint = normalizePathSeparators(getRelativePathTail(files.get(0).getParentFile(), 2).getPath()); String parentPathHint = normalizePathSeparators(getRelativePathTail(files.get(0).getParentFile(), 2).getPath());
String suggestion = detectedSeriesNames.size() > 0 ? String.join("; ", detectedSeriesNames) : parentPathHint; String suggestion = detectedSeriesNames.size() > 0 ? join(detectedSeriesNames, "; ") : parentPathHint;
List<String> input; List<String> input;
synchronized (inputMemory) { synchronized (inputMemory) {

View File

@ -1,6 +1,5 @@
package net.filebot.ui.rename; package net.filebot.ui.rename;
import static net.filebot.util.ui.SwingUI.*;
import static java.awt.Font.*; import static java.awt.Font.*;
import static java.util.Arrays.*; import static java.util.Arrays.*;
import static java.util.Collections.*; import static java.util.Collections.*;
@ -9,6 +8,7 @@ import static javax.swing.JOptionPane.*;
import static net.filebot.Settings.*; import static net.filebot.Settings.*;
import static net.filebot.UserFiles.*; import static net.filebot.UserFiles.*;
import static net.filebot.util.FileUtilities.*; import static net.filebot.util.FileUtilities.*;
import static net.filebot.util.ui.SwingUI.*;
import java.awt.Color; import java.awt.Color;
import java.awt.Component; import java.awt.Component;

View File

@ -1,7 +1,7 @@
package net.filebot.ui.rename; package net.filebot.ui.rename;
import static net.filebot.util.ui.SwingUI.*;
import static java.util.Collections.*; import static java.util.Collections.*;
import static net.filebot.util.ui.SwingUI.*;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;

View File

@ -61,8 +61,6 @@ import javax.swing.table.DefaultTableCellRenderer;
import net.filebot.ResourceManager; import net.filebot.ResourceManager;
import net.filebot.mac.MacAppUtilities; import net.filebot.mac.MacAppUtilities;
import net.filebot.similarity.EpisodeMetrics;
import net.filebot.similarity.MetricCascade;
import net.filebot.similarity.SimilarityMetric; import net.filebot.similarity.SimilarityMetric;
import net.filebot.subtitle.SubtitleMetrics; import net.filebot.subtitle.SubtitleMetrics;
import net.filebot.subtitle.SubtitleNaming; import net.filebot.subtitle.SubtitleNaming;

View File

@ -22,7 +22,6 @@ import java.util.regex.Pattern;
import javax.swing.AbstractAction; import javax.swing.AbstractAction;
import javax.swing.Action; import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JComponent; import javax.swing.JComponent;
import javax.swing.JFrame; import javax.swing.JFrame;
import javax.swing.JLabel; import javax.swing.JLabel;

View File

@ -4,7 +4,6 @@ import static java.util.Arrays.*;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import java.util.Iterator;
public final class StringUtilities { public final class StringUtilities {
@ -16,6 +15,14 @@ public final class StringUtilities {
return object == null || object.toString().length() == 0; return object == null || object.toString().length() == 0;
} }
public static String join(Iterable<?> values, CharSequence delimiter) {
return join(values, delimiter, "", "");
}
public static String join(CharSequence delimiter, Object... values) {
return join(asList(values), delimiter, "", "");
}
public static String join(Object[] values, CharSequence delimiter) { public static String join(Object[] values, CharSequence delimiter) {
return join(asList(values), delimiter, "", ""); return join(asList(values), delimiter, "", "");
} }

View File

@ -1,5 +1,7 @@
package net.filebot.web; package net.filebot.web;
import static net.filebot.util.StringUtilities.*;
import java.text.FieldPosition; import java.text.FieldPosition;
import java.text.Format; import java.text.Format;
import java.text.ParseException; import java.text.ParseException;
@ -108,8 +110,7 @@ public class EpisodeFormat extends Format {
sxe.add(formatSxE(it)); sxe.add(formatSxE(it));
title.add(it.getTitle().replaceAll("[(]([^)]*)[)]$", "").trim()); title.add(it.getTitle().replaceAll("[(]([^)]*)[)]$", "").trim());
} }
return String.format("%s - %s - %s", join(name, " & "), join(" & ", sxe), join(" & ", title));
return String.format("%s - %s - %s", String.join(" & ", name), String.join(" & ", sxe), String.join(" & ", title));
} }
public String formatMultiSxE(Iterable<Episode> episodes) { public String formatMultiSxE(Iterable<Episode> episodes) {