use of lucee.runtime.type.Closure in project Lucee by lucee.
the class ArrayFindAll method find.
public static Array find(PageContext pc, Array array, UDF udf) throws PageException {
Array rtn = new ArrayImpl();
int len = array.size();
Object[] arr = new Object[1];
Object res;
Boolean b;
for (int i = 1; i <= len; i++) {
arr[0] = array.get(i, null);
if (arr[0] != null) {
res = udf.call(pc, arr, false);
b = Caster.toBoolean(res, null);
if (b == null)
throw new FunctionException(pc, "ArrayFindAll", 2, "function", "return value of the " + (udf instanceof Closure ? "closure" : "function [" + udf.getFunctionName() + "]") + " cannot be casted to a boolean value.", CasterException.createMessage(res, "boolean"));
if (b.booleanValue()) {
rtn.appendEL(Caster.toDouble(i));
}
}
}
return rtn;
}
use of lucee.runtime.type.Closure in project Lucee by lucee.
the class ArrayFind method find.
public static int find(PageContext pc, Array array, UDF udf) throws PageException {
int len = array.size();
Object[] arr = new Object[1];
Object res;
Boolean b;
for (int i = 1; i <= len; i++) {
arr[0] = array.get(i, null);
if (arr[0] != null) {
res = udf.call(pc, arr, false);
b = Caster.toBoolean(res, null);
if (b == null)
throw new FunctionException(pc, "ArrayFind", 2, "function", "return value of the " + (udf instanceof Closure ? "closure" : "function [" + udf.getFunctionName() + "]") + " cannot be casted to a boolean value.", CasterException.createMessage(res, "boolean"));
if (b.booleanValue())
return i;
}
}
return 0;
}
use of lucee.runtime.type.Closure in project Lucee by lucee.
the class UDFComparator method compare.
@Override
public int compare(Object oLeft, Object oRight) {
try {
args[0] = oLeft;
args[1] = oRight;
Object res = udf.call(pc, args, false);
Integer i = Caster.toInteger(res, null);
if (i == null)
throw new FunctionException(pc, "ArraySort", 2, "function", "return value of the " + (udf instanceof Closure ? "closure" : "function [" + udf.getFunctionName() + "]") + " cannot be casted to a integer.", CasterException.createMessage(res, "integer"));
return i.intValue();
} catch (PageException pe) {
throw new PageRuntimeException(pe);
}
}
Aggregations