1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-12-24 00:38:52 -05:00

* use String.join()

This commit is contained in:
Reinhard Pointner 2015-05-20 07:35:40 +00:00
parent d8d7b80474
commit 8a885ff1fe
10 changed files with 28 additions and 42 deletions

View File

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

View File

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

View File

@ -59,7 +59,6 @@ import net.filebot.similarity.SeriesNameMatcher;
import net.filebot.similarity.SimilarityComparator;
import net.filebot.similarity.SimilarityMetric;
import net.filebot.similarity.StringEqualsMetric;
import net.filebot.util.StringUtilities;
import net.filebot.vfs.FileInfo;
import net.filebot.web.Episode;
import net.filebot.web.Movie;
@ -948,7 +947,7 @@ public class MediaDetection {
querySet = getUniqueQuerySet(stripBlacklistedTerms(querySet));
// DEBUG
// System.out.format("Query %s: %s%n", queryLookupService.getName(), querySet);
System.out.format("Query %s: %s%n", queryLookupService.getName(), querySet);
final Map<Movie, Float> probabilityMap = new LinkedHashMap<Movie, Float>();
final SimilarityMetric metric = getMovieMatchMetric();
@ -1047,7 +1046,7 @@ public class MediaDetection {
relativePath.addFirst(it.getName());
}
return relativePath.isEmpty() ? null : new File(StringUtilities.join(relativePath, File.separator));
return relativePath.isEmpty() ? null : new File(String.join(File.separator, relativePath));
}
public static Map<File, List<File>> mapByMediaFolder(Collection<File> files) {

View File

@ -5,7 +5,6 @@ import static java.util.Collections.*;
import static java.util.regex.Pattern.*;
import static net.filebot.similarity.Normalization.*;
import static net.filebot.util.FileUtilities.*;
import static net.filebot.util.StringUtilities.*;
import java.io.File;
import java.io.IOException;
@ -431,12 +430,12 @@ public enum EpisodeMetrics implements SimilarityMetric {
}
// simplify file name if possible and extract numbers
List<Integer> numbers = new ArrayList<Integer>(4);
List<String> numbers = new ArrayList<String>(4);
Scanner scanner = new Scanner(normalizeObject(object)).useDelimiter("\\D+");
while (scanner.hasNextInt()) {
numbers.add(scanner.nextInt());
numbers.add(String.valueOf(scanner.nextInt()));
}
return join(numbers, " ");
return String.join(" ", numbers);
}
}),

View File

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

View File

@ -1,9 +1,5 @@
package net.filebot.subtitle;
import static net.filebot.util.StringUtilities.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@ -12,56 +8,52 @@ import java.util.Locale;
import java.util.TimeZone;
import java.util.regex.Pattern;
public class SubRipReader extends SubtitleReader {
private final DateFormat timeFormat;
private final Pattern tag;
public SubRipReader(Readable source) {
super(source);
// format used to parse time stamps (e.g. 00:02:26,407 --> 00:02:31,356)
timeFormat = new SimpleDateFormat("HH:mm:ss,SSS", Locale.ROOT);
timeFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
// pattern for <b>, <u>, <i>, <font color="#ccffee"> and corresponding end tags
tag = Pattern.compile("</?(b|u|i|font[^<>]*)>", Pattern.CASE_INSENSITIVE);
}
@Override
protected SubtitleElement readNext() throws Exception {
String number = scanner.nextLine();
// ignore illegal lines
if (!number.matches("\\d+"))
return null;
String[] interval = scanner.nextLine().split("-->", 2);
// ignore illegal lines
if (interval.length < 2)
return null;
long t1 = timeFormat.parse(interval[0].trim()).getTime();
long t2 = timeFormat.parse(interval[1].trim()).getTime();
List<String> lines = new ArrayList<String>(2);
// read all lines until the next empty line
for (String line = scanner.nextLine(); line.length() > 0; line = scanner.hasNextLine() ? scanner.nextLine() : "") {
lines.add(line);
}
return new SubtitleElement(t1, t2, resolve(join(lines, "\n")));
return new SubtitleElement(t1, t2, resolve(String.join("\n", lines)));
}
protected String resolve(String text) {
// remove tags
return tag.matcher(text).replaceAll("").trim();
}
}

View File

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

View File

@ -22,7 +22,6 @@ import java.awt.event.WindowEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.text.Format;
import java.util.LinkedHashSet;

View File

@ -1,12 +1,14 @@
package net.filebot.util;
import java.io.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import com.ibm.icu.text.CharsetDetector;
import com.ibm.icu.text.CharsetMatch;
public class UnicodeReader extends Reader {

View File

@ -1,7 +1,5 @@
package net.filebot.web;
import static net.filebot.util.StringUtilities.*;
import java.text.FieldPosition;
import java.text.Format;
import java.text.ParseException;
@ -111,7 +109,7 @@ public class EpisodeFormat extends Format {
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) {