From 8a75000ecdcc07b514141930aaff2172beca329a Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Sun, 29 Jun 2014 12:13:54 +0000 Subject: [PATCH] * fix modularity issue --- .../net/filebot/format/ExpressionFormat.java | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/source/net/filebot/format/ExpressionFormat.java b/source/net/filebot/format/ExpressionFormat.java index 9a825ae9..5cd5a5c3 100644 --- a/source/net/filebot/format/ExpressionFormat.java +++ b/source/net/filebot/format/ExpressionFormat.java @@ -1,5 +1,6 @@ package net.filebot.format; +import static net.filebot.similarity.Normalization.*; import static net.filebot.util.ExceptionUtilities.*; import static net.filebot.util.FileUtilities.*; import groovy.lang.GroovyClassLoader; @@ -23,8 +24,6 @@ import javax.script.ScriptEngine; import javax.script.ScriptException; import javax.script.SimpleScriptContext; -import net.filebot.similarity.Normalization; - import org.codehaus.groovy.control.CompilerConfiguration; import org.codehaus.groovy.control.MultipleCompilationErrorsException; import org.codehaus.groovy.control.customizers.ImportCustomizer; @@ -179,10 +178,10 @@ public class ExpressionFormat extends Format { lastException = null; StringBuilder sb = new StringBuilder(); - for (Object snipped : compilation) { - if (snipped instanceof CompiledScript) { + for (Object snippet : compilation) { + if (snippet instanceof CompiledScript) { try { - Object value = normalizeExpressionValue(((CompiledScript) snipped).eval(context)); + CharSequence value = normalizeExpressionValue(((CompiledScript) snippet).eval(context)); if (value != null) { sb.append(value); } @@ -190,11 +189,11 @@ public class ExpressionFormat extends Format { handleException(e); } } else { - sb.append(snipped); + sb.append(snippet); } } - return Normalization.replaceSpace(sb.toString(), " ").trim(); + return normalizeResult(sb); } protected Object normalizeBindingValue(Object value) { @@ -207,8 +206,12 @@ public class ExpressionFormat extends Format { return value; } - protected Object normalizeExpressionValue(Object value) { - return value; + protected CharSequence normalizeExpressionValue(Object value) { + return value == null ? null : value.toString(); + } + + protected String normalizeResult(CharSequence value) { + return replaceSpace(value.toString(), " ").trim(); } protected void handleException(ScriptException exception) {