From d28df068184954179bb3f0b5b3318755933ff4c9 Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sat, 18 May 2019 02:26:57 +0700 Subject: [PATCH] Allow custom parallelism for formats --- .../ui/rename/ExpressionFormatter.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/source/net/filebot/ui/rename/ExpressionFormatter.java b/source/net/filebot/ui/rename/ExpressionFormatter.java index 0e463beb..f8f639fb 100644 --- a/source/net/filebot/ui/rename/ExpressionFormatter.java +++ b/source/net/filebot/ui/rename/ExpressionFormatter.java @@ -18,7 +18,7 @@ import net.filebot.similarity.Match; class ExpressionFormatter implements MatchFormatter { - private final String expression; + private String expression; private ExpressionFileFormat format; private Format preview; @@ -41,6 +41,13 @@ class ExpressionFormatter implements MatchFormatter { this.format = format; } + public synchronized ExpressionFileFormat getFormat() throws ScriptException { + if (format == null) { + format = new ExpressionFileFormat(expression); + } + return format; + } + public Class getTargetClass() { return target; } @@ -57,15 +64,12 @@ class ExpressionFormatter implements MatchFormatter { } @Override - public synchronized String format(Match match, boolean extension, Map context) throws ScriptException { - // lazy initialize script engine - if (format == null) { - format = new ExpressionFileFormat(expression); - } - + public String format(Match match, boolean extension, Map context) throws ScriptException { // evaluate the expression using the given bindings Object bindingBean = new MediaBindingBean(match.getValue(), (File) match.getCandidate(), (Map) context); - String destination = format.format(bindingBean); + + // lazy initialize script engine + String destination = getFormat().format(bindingBean); return getPath((File) match.getCandidate(), destination); }