Search in sources :

Example 26 with ArrayImpl

use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.

the class Map method invoke.

private static Collection invoke(PageContext pc, Array arr, UDF udf, ExecutorService es, List<Future<Data<Object>>> futures) throws CasterException, PageException {
    Array rtn = new ArrayImpl();
    Iterator it = (arr instanceof ArrayPro ? ((ArrayPro) arr).entryArrayIterator() : arr.entryIterator());
    Entry e;
    boolean async = es != null;
    Object res;
    while (it.hasNext()) {
        e = (Entry) it.next();
        res = _inv(pc, udf, new Object[] { e.getValue(), Caster.toDoubleValue(e.getKey()), arr }, e.getKey(), es, futures);
        if (!async)
            rtn.set(Caster.toString(e.getKey()), res);
    }
    return rtn;
}
Also used : Array(lucee.runtime.type.Array) Entry(java.util.Map.Entry) ArrayImpl(lucee.runtime.type.ArrayImpl) ListIterator(java.util.ListIterator) ForEachQueryIterator(lucee.runtime.type.it.ForEachQueryIterator) Iterator(java.util.Iterator) ArrayPro(lucee.runtime.type.ArrayPro)

Example 27 with ArrayImpl

use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.

the class Map method invoke.

private static Array invoke(PageContext pc, Iterator it, UDF udf, ExecutorService es, List<Future<Data<Object>>> futures) throws PageException {
    Array rtn = new ArrayImpl();
    Object v;
    boolean async = es != null;
    Object res;
    int count = 0;
    ArgumentIntKey k;
    while (it.hasNext()) {
        v = it.next();
        k = ArgumentIntKey.init(++count);
        res = _inv(pc, udf, new Object[] { v }, k, es, futures);
        if (!async)
            rtn.set(k, res);
    }
    return rtn;
}
Also used : Array(lucee.runtime.type.Array) ArrayImpl(lucee.runtime.type.ArrayImpl) ArgumentIntKey(lucee.runtime.type.scope.ArgumentIntKey)

Example 28 with ArrayImpl

use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.

the class ComponentListPackage method call.

public static Array call(PageContext pc, String packageName) throws PageException {
    Set<String> names;
    try {
        names = _call(pc, packageName);
    } catch (IOException e) {
        throw Caster.toPageException(e);
    }
    Array arr = new ArrayImpl();
    String name;
    Iterator<String> it = names.iterator();
    while (it.hasNext()) {
        name = it.next();
        if (Constants.isComponentExtension(ResourceUtil.getExtension(name, ""))) {
            name = ResourceUtil.removeExtension(name, name);
        }
        arr.appendEL(name);
    }
    return arr;
}
Also used : Array(lucee.runtime.type.Array) ArrayImpl(lucee.runtime.type.ArrayImpl) IOException(java.io.IOException)

Example 29 with ArrayImpl

use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.

the class DeserializeJSON method toData.

private static Array[] toData(Object obj, Key[] columns) throws PageException {
    if (columns == null)
        return null;
    Array arr = Caster.toArray(obj, null);
    if (arr != null) {
        Array[] datas = new Array[columns.length];
        for (int i = 0; i < datas.length; i++) {
            datas[i] = new ArrayImpl();
        }
        Array data;
        Iterator<Object> it = arr.valueIterator();
        while (it.hasNext()) {
            data = Caster.toArray(it.next(), null);
            if (data == null || data.size() != datas.length)
                return null;
            for (int i = 0; i < datas.length; i++) {
                datas[i].appendEL(toQuery(data.get(i + 1, null)));
            }
        }
        return datas;
    }
    return null;
}
Also used : Array(lucee.runtime.type.Array) ArrayImpl(lucee.runtime.type.ArrayImpl)

Example 30 with ArrayImpl

use of lucee.runtime.type.ArrayImpl in project Lucee by lucee.

the class SerializeJSON method _call.

private static String _call(PageContext pc, Object var, Object options, Charset charset) throws PageException {
    try {
        JSONConverter json = new JSONConverter(true, charset);
        if (Decision.isBoolean(options))
            return json.serialize(pc, var, Caster.toBoolean(options));
        if (Decision.isQuery(var)) {
            if (Decision.isSimpleValue(options)) {
                String opt = Caster.toString(options);
                if ("struct".equalsIgnoreCase(opt)) {
                    Array arr = new ArrayImpl();
                    ForEachQueryIterator it = new ForEachQueryIterator((Query) var, pc.getId());
                    try {
                        while (it.hasNext()) {
                            // append each record from the query as a struct
                            arr.append(it.next());
                        }
                    } finally {
                        it.reset();
                    }
                    return json.serialize(pc, arr, false);
                }
            } else if (Decision.isBoolean(options)) {
                return json.serialize(pc, var, Caster.toBoolean(options));
            } else
                throw new FunctionException(pc, SerializeJSON.class.getSimpleName(), 2, "options", "When var is a Query, argument [options] must be either a boolean value or a string with the value of [struct]");
        }
        // var is not a query so options doesn't make a difference here
        return json.serialize(pc, var, false);
    } catch (ConverterException e) {
        throw Caster.toPageException(e);
    }
}
Also used : Array(lucee.runtime.type.Array) ForEachQueryIterator(lucee.runtime.type.it.ForEachQueryIterator) ConverterException(lucee.runtime.converter.ConverterException) ArrayImpl(lucee.runtime.type.ArrayImpl) FunctionException(lucee.runtime.exp.FunctionException) JSONConverter(lucee.runtime.converter.JSONConverter)

Aggregations

ArrayImpl (lucee.runtime.type.ArrayImpl)100 Array (lucee.runtime.type.Array)79 Struct (lucee.runtime.type.Struct)33 StructImpl (lucee.runtime.type.StructImpl)24 PageException (lucee.runtime.exp.PageException)14 Entry (java.util.Map.Entry)13 Key (lucee.runtime.type.Collection.Key)12 ArgumentIntKey (lucee.runtime.type.scope.ArgumentIntKey)8 IOException (java.io.IOException)7 Iterator (java.util.Iterator)7 ArrayList (java.util.ArrayList)6 ListIterator (java.util.ListIterator)6 FunctionException (lucee.runtime.exp.FunctionException)6 ForEachQueryIterator (lucee.runtime.type.it.ForEachQueryIterator)6 ApplicationException (lucee.runtime.exp.ApplicationException)5 ExpressionException (lucee.runtime.exp.ExpressionException)5 Query (lucee.runtime.type.Query)5 QueryImpl (lucee.runtime.type.QueryImpl)5 ListAsArray (lucee.runtime.type.wrap.ListAsArray)5 NodeList (org.w3c.dom.NodeList)5