1
0
mirror of https://github.com/mitb-archive/filebot synced 2024-08-13 17:03:45 -04:00
filebot/source/net/sourceforge/filebot/format/ExpressionFormatFunctions.java

56 lines
960 B
Java
Raw Normal View History

package net.sourceforge.filebot.format;
import groovy.lang.Closure;
import java.util.ArrayList;
import java.util.List;
/**
* Global functions available in the {@link ExpressionFormat}
*/
public class ExpressionFormatFunctions {
/**
* General helpers and utilities
*/
public static Object c(Closure<?> c) {
try {
return c.call();
} catch (Exception e) {
return null;
}
}
public static Object any(Closure<?>... closures) {
for (Closure<?> it : closures) {
try {
Object result = it.call();
if (result != null) {
return result;
}
} catch (Exception e) {
// ignore
}
}
return null;
}
public static List<Object> allOf(Closure<?>... closures) {
List<Object> values = new ArrayList<Object>();
for (Closure<?> it : closures) {
try {
Object result = it.call();
if (result != null) {
values.add(result);
}
} catch (Exception e) {
// ignore
}
}
return values;
}
}