Search in sources :

Example 1 with Closure

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;
}
Also used : Array(lucee.runtime.type.Array) Closure(lucee.runtime.type.Closure) ArrayImpl(lucee.runtime.type.ArrayImpl) FunctionException(lucee.runtime.exp.FunctionException)

Example 2 with Closure

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;
}
Also used : Closure(lucee.runtime.type.Closure) FunctionException(lucee.runtime.exp.FunctionException)

Example 3 with Closure

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);
    }
}
Also used : PageException(lucee.runtime.exp.PageException) Closure(lucee.runtime.type.Closure) FunctionException(lucee.runtime.exp.FunctionException) PageRuntimeException(lucee.runtime.exp.PageRuntimeException)

Aggregations

FunctionException (lucee.runtime.exp.FunctionException)3 Closure (lucee.runtime.type.Closure)3 PageException (lucee.runtime.exp.PageException)1 PageRuntimeException (lucee.runtime.exp.PageRuntimeException)1 Array (lucee.runtime.type.Array)1 ArrayImpl (lucee.runtime.type.ArrayImpl)1