Search in sources :

Example 6 with ArgumentIntKey

use of lucee.runtime.type.scope.ArgumentIntKey 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 7 with ArgumentIntKey

use of lucee.runtime.type.scope.ArgumentIntKey in project Lucee by lucee.

the class Reduce method invoke.

private static Object invoke(PageContext pc, List list, UDF udf, Object initalValue) throws CasterException, PageException {
    ListIterator it = list.listIterator();
    Object v;
    int index;
    ArgumentIntKey k;
    while (it.hasNext()) {
        index = it.nextIndex();
        k = ArgumentIntKey.init(index);
        v = it.next();
        initalValue = udf.call(pc, new Object[] { initalValue, v, Caster.toDoubleValue(k.getString()), list }, true);
    }
    return initalValue;
}
Also used : ArgumentIntKey(lucee.runtime.type.scope.ArgumentIntKey) ListIterator(java.util.ListIterator)

Example 8 with ArgumentIntKey

use of lucee.runtime.type.scope.ArgumentIntKey in project Lucee by lucee.

the class Some method invoke.

private static boolean invoke(PageContext pc, List list, UDF udf, ExecutorService es, List<Future<Data<Object>>> futures) throws CasterException, PageException {
    ListIterator it = list.listIterator();
    boolean async = es != null;
    Object res, v;
    int index;
    ArgumentIntKey k;
    while (it.hasNext()) {
        index = it.nextIndex();
        k = ArgumentIntKey.init(index);
        v = it.next();
        res = _inv(pc, udf, new Object[] { v, Caster.toDoubleValue(k.getString()), list }, k, v, es, futures);
        if (!async && Caster.toBooleanValue(res))
            return true;
    }
    return false;
}
Also used : ArgumentIntKey(lucee.runtime.type.scope.ArgumentIntKey) ListIterator(java.util.ListIterator)

Example 9 with ArgumentIntKey

use of lucee.runtime.type.scope.ArgumentIntKey in project Lucee by lucee.

the class UDFUtil method argumentCollection.

public static void argumentCollection(Struct values, FunctionArgument[] funcArgs) {
    Object value = values.removeEL(KeyConstants._argumentCollection);
    if (value != null) {
        value = Caster.unwrap(value, value);
        if (value instanceof Argument) {
            Argument argColl = (Argument) value;
            Iterator<Key> it = argColl.keyIterator();
            Key k;
            int i = -1;
            while (it.hasNext()) {
                i++;
                k = it.next();
                if (funcArgs.length > i && k instanceof ArgumentIntKey) {
                    if (!values.containsKey(funcArgs[i].getName()))
                        values.setEL(funcArgs[i].getName(), argColl.get(k, Argument.NULL));
                    else
                        values.setEL(k, argColl.get(k, Argument.NULL));
                } else if (!values.containsKey(k)) {
                    values.setEL(k, argColl.get(k, Argument.NULL));
                }
            }
        } else if (value instanceof Collection) {
            Collection argColl = (Collection) value;
            // Collection.Key[] keys = argColl.keys();
            Iterator<Key> it = argColl.keyIterator();
            Key k;
            while (it.hasNext()) {
                k = it.next();
                if (!values.containsKey(k)) {
                    values.setEL(k, argColl.get(k, Argument.NULL));
                }
            }
        } else if (value instanceof Map) {
            Map map = (Map) value;
            Iterator it = map.entrySet().iterator();
            Map.Entry entry;
            Key key;
            while (it.hasNext()) {
                entry = (Entry) it.next();
                key = Caster.toKey(entry.getKey(), null);
                if (!values.containsKey(key)) {
                    values.setEL(key, entry.getValue());
                }
            }
        } else if (value instanceof java.util.List) {
            java.util.List list = (java.util.List) value;
            Iterator it = list.iterator();
            Object v;
            int index = 0;
            Key k;
            while (it.hasNext()) {
                v = it.next();
                k = ArgumentIntKey.init(++index);
                if (!values.containsKey(k)) {
                    values.setEL(k, v);
                }
            }
        } else {
            values.setEL(KeyConstants._argumentCollection, value);
        }
    }
}
Also used : Entry(java.util.Map.Entry) Argument(lucee.runtime.type.scope.Argument) FunctionArgument(lucee.runtime.type.FunctionArgument) Iterator(java.util.Iterator) Collection(lucee.runtime.type.Collection) ArgumentIntKey(lucee.runtime.type.scope.ArgumentIntKey) ArrayList(java.util.ArrayList) Map(java.util.Map) Key(lucee.runtime.type.Collection.Key) ArgumentIntKey(lucee.runtime.type.scope.ArgumentIntKey)

Example 10 with ArgumentIntKey

use of lucee.runtime.type.scope.ArgumentIntKey in project Lucee by lucee.

the class Every method invoke.

private static boolean invoke(PageContext pc, Enumeration e, UDF udf, ExecutorService es, List<Future<Data<Object>>> futures) throws PageException {
    Object v;
    boolean async = es != null;
    Object res;
    int count = 0;
    ArgumentIntKey k;
    while (e.hasMoreElements()) {
        v = e.nextElement();
        k = ArgumentIntKey.init(++count);
        res = _inv(pc, udf, new Object[] { v }, k, v, es, futures);
        if (!async && !Caster.toBooleanValue(res))
            return false;
    }
    return true;
}
Also used : ArgumentIntKey(lucee.runtime.type.scope.ArgumentIntKey)

Aggregations

ArgumentIntKey (lucee.runtime.type.scope.ArgumentIntKey)16 Array (lucee.runtime.type.Array)6 ArrayImpl (lucee.runtime.type.ArrayImpl)6 ListIterator (java.util.ListIterator)5 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Collection (lucee.runtime.type.Collection)1 Key (lucee.runtime.type.Collection.Key)1 FunctionArgument (lucee.runtime.type.FunctionArgument)1 Argument (lucee.runtime.type.scope.Argument)1