From 8cee5b9a2a3a80f42a9316f89a727131ff35db4f Mon Sep 17 00:00:00 2001 From: Reinhard Pointner Date: Tue, 15 Apr 2014 14:29:13 +0000 Subject: [PATCH] * avoid overloading issues --- .../format/ExpressionFormatFunctions.java | 42 ++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/source/net/sourceforge/filebot/format/ExpressionFormatFunctions.java b/source/net/sourceforge/filebot/format/ExpressionFormatFunctions.java index 70657d5b..f3f6ae38 100644 --- a/source/net/sourceforge/filebot/format/ExpressionFormatFunctions.java +++ b/source/net/sourceforge/filebot/format/ExpressionFormatFunctions.java @@ -21,10 +21,10 @@ public class ExpressionFormatFunctions { } } - public static Object any(Closure... closures) { - for (Closure it : closures) { + public static Object any(Object a0, Object a1, Object... args) { + for (Object it : new Object[] { a0, a1 }) { try { - Object result = it.call(); + Object result = callIfCallable(it); if (result != null) { return result; } @@ -32,15 +32,38 @@ public class ExpressionFormatFunctions { // ignore } } + + for (Object it : args) { + try { + Object result = callIfCallable(it); + if (result != null) { + return result; + } + } catch (Exception e) { + // ignore + } + } + return null; } - public static List allOf(Closure... closures) { + public static List allOf(Object a0, Object a1, Object... args) { List values = new ArrayList(); - for (Closure it : closures) { + for (Object it : new Object[] { a0, a1 }) { try { - Object result = it.call(); + Object result = callIfCallable(it); + if (result != null) { + values.add(result); + } + } catch (Exception e) { + // ignore + } + } + + for (Object it : args) { + try { + Object result = callIfCallable(it); if (result != null) { values.add(result); } @@ -52,4 +75,11 @@ public class ExpressionFormatFunctions { return values; } + private static Object callIfCallable(Object obj) throws Exception { + if (obj instanceof Closure) { + return ((Closure) obj).call(); + } + return obj; + } + }