Search in sources :

Example 1 with Iteratorable

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

the class Every method _call.

public static boolean _call(PageContext pc, Object obj, UDF udf, boolean parallel, int maxThreads, short type) throws PageException {
    ExecutorService execute = null;
    List<Future<Data<Object>>> futures = null;
    if (parallel) {
        execute = Executors.newFixedThreadPool(maxThreads);
        futures = new ArrayList<Future<Data<Object>>>();
    }
    boolean res;
    // Array
    if (type == TYPE_ARRAY) {
        res = invoke(pc, (Array) obj, udf, execute, futures);
    } else // Query
    if (type == TYPE_QUERY) {
        res = invoke(pc, (Query) obj, udf, execute, futures);
    } else // Struct
    if (type == TYPE_STRUCT) {
        res = invoke(pc, (Struct) obj, udf, execute, futures);
    } else // Array
    if (obj instanceof Array) {
        res = invoke(pc, (Array) obj, udf, execute, futures);
    } else // Query
    if (obj instanceof Query) {
        res = invoke(pc, (Query) obj, udf, execute, futures);
    } else // Struct
    if (obj instanceof Struct) {
        res = invoke(pc, (Struct) obj, udf, execute, futures);
    } else // other Iteratorable
    if (obj instanceof Iteratorable) {
        res = invoke(pc, (Iteratorable) obj, udf, execute, futures);
    } else // Map
    if (obj instanceof java.util.Map) {
        res = invoke(pc, (java.util.Map) obj, udf, execute, futures);
    } else // List
    if (obj instanceof List) {
        res = invoke(pc, (List) obj, udf, execute, futures);
    } else // Iterator
    if (obj instanceof Iterator) {
        res = invoke(pc, (Iterator) obj, udf, execute, futures);
    } else // Enumeration
    if (obj instanceof Enumeration) {
        res = invoke(pc, (Enumeration) obj, udf, execute, futures);
    } else // String List
    if (obj instanceof StringListData) {
        res = invoke(pc, (StringListData) obj, udf, execute, futures);
    } else
        throw new FunctionException(pc, "Every", 1, "data", "cannot iterate througth this type " + Caster.toTypeName(obj.getClass()));
    if (parallel)
        res = afterCall(pc, futures, execute);
    return res;
}
Also used : Enumeration(java.util.Enumeration) Query(lucee.runtime.type.Query) FunctionException(lucee.runtime.exp.FunctionException) Struct(lucee.runtime.type.Struct) Array(lucee.runtime.type.Array) StringListData(lucee.runtime.type.util.StringListData) Iteratorable(lucee.runtime.type.Iteratorable) ExecutorService(java.util.concurrent.ExecutorService) ListIterator(java.util.ListIterator) ForEachQueryIterator(lucee.runtime.type.it.ForEachQueryIterator) Iterator(java.util.Iterator) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with Iteratorable

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

the class Map method _call.

public static Collection _call(PageContext pc, Object obj, UDF udf, boolean parallel, int maxThreads, Query resQry, short type) throws PageException {
    ExecutorService execute = null;
    List<Future<Data<Object>>> futures = null;
    if (parallel) {
        execute = Executors.newFixedThreadPool(maxThreads);
        futures = new ArrayList<Future<Data<Object>>>();
    }
    Collection coll;
    // Array
    if (type == TYPE_ARRAY) {
        coll = invoke(pc, (Array) obj, udf, execute, futures);
    } else // Query
    if (type == TYPE_QUERY) {
        coll = invoke(pc, (Query) obj, udf, execute, futures, resQry);
    } else // Struct
    if (type == TYPE_STRUCT) {
        coll = invoke(pc, (Struct) obj, udf, execute, futures);
    } else // Array
    if (obj instanceof Array) {
        coll = invoke(pc, (Array) obj, udf, execute, futures);
    } else // Query
    if (obj instanceof Query) {
        coll = invoke(pc, (Query) obj, udf, execute, futures, resQry);
    } else // Struct
    if (obj instanceof Struct) {
        coll = invoke(pc, (Struct) obj, udf, execute, futures);
    } else // other Iteratorable
    if (obj instanceof Iteratorable) {
        coll = invoke(pc, (Iteratorable) obj, udf, execute, futures);
    } else // Map
    if (obj instanceof java.util.Map) {
        coll = invoke(pc, (java.util.Map) obj, udf, execute, futures);
    } else // List
    if (obj instanceof List) {
        coll = invoke(pc, (List) obj, udf, execute, futures);
    } else // Iterator
    if (obj instanceof Iterator) {
        coll = invoke(pc, (Iterator) obj, udf, execute, futures);
    } else // Enumeration
    if (obj instanceof Enumeration) {
        coll = invoke(pc, (Enumeration) obj, udf, execute, futures);
    } else // String List
    if (obj instanceof StringListData) {
        coll = invoke(pc, (StringListData) obj, udf, execute, futures);
    } else
        throw new FunctionException(pc, "Map", 1, "data", "cannot iterate througth this type " + Caster.toTypeName(obj.getClass()));
    if (parallel)
        afterCall(pc, coll, futures, execute);
    return coll;
}
Also used : Enumeration(java.util.Enumeration) Query(lucee.runtime.type.Query) FunctionException(lucee.runtime.exp.FunctionException) Struct(lucee.runtime.type.Struct) Array(lucee.runtime.type.Array) StringListData(lucee.runtime.type.util.StringListData) Iteratorable(lucee.runtime.type.Iteratorable) ExecutorService(java.util.concurrent.ExecutorService) ListIterator(java.util.ListIterator) ForEachQueryIterator(lucee.runtime.type.it.ForEachQueryIterator) Iterator(java.util.Iterator) Future(java.util.concurrent.Future) Collection(lucee.runtime.type.Collection) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with Iteratorable

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

the class Some method _call.

public static boolean _call(PageContext pc, Object obj, UDF udf, boolean parallel, int maxThreads, short type) throws PageException {
    ExecutorService execute = null;
    List<Future<Data<Object>>> futures = null;
    if (parallel) {
        execute = Executors.newFixedThreadPool(maxThreads);
        futures = new ArrayList<Future<Data<Object>>>();
    }
    boolean res;
    // Array
    if (type == TYPE_ARRAY) {
        res = invoke(pc, (Array) obj, udf, execute, futures);
    } else // Query
    if (type == TYPE_QUERY) {
        res = invoke(pc, (Query) obj, udf, execute, futures);
    } else // Struct
    if (type == TYPE_STRUCT) {
        res = invoke(pc, (Struct) obj, udf, execute, futures);
    } else // Array
    if (obj instanceof Array) {
        res = invoke(pc, (Array) obj, udf, execute, futures);
    } else // Query
    if (obj instanceof Query) {
        res = invoke(pc, (Query) obj, udf, execute, futures);
    } else // Struct
    if (obj instanceof Struct) {
        res = invoke(pc, (Struct) obj, udf, execute, futures);
    } else // other Iteratorable
    if (obj instanceof Iteratorable) {
        res = invoke(pc, (Iteratorable) obj, udf, execute, futures);
    } else // Map
    if (obj instanceof java.util.Map) {
        res = invoke(pc, (java.util.Map) obj, udf, execute, futures);
    } else // List
    if (obj instanceof List) {
        res = invoke(pc, (List) obj, udf, execute, futures);
    } else // Iterator
    if (obj instanceof Iterator) {
        res = invoke(pc, (Iterator) obj, udf, execute, futures);
    } else // Enumeration
    if (obj instanceof Enumeration) {
        res = invoke(pc, (Enumeration) obj, udf, execute, futures);
    } else // String List
    if (obj instanceof StringListData) {
        res = invoke(pc, (StringListData) obj, udf, execute, futures);
    } else
        throw new FunctionException(pc, "Some", 1, "data", "cannot iterate througth this type " + Caster.toTypeName(obj.getClass()));
    if (parallel)
        res = afterCall(pc, futures, execute);
    return res;
}
Also used : Enumeration(java.util.Enumeration) Query(lucee.runtime.type.Query) FunctionException(lucee.runtime.exp.FunctionException) Struct(lucee.runtime.type.Struct) Array(lucee.runtime.type.Array) StringListData(lucee.runtime.type.util.StringListData) Iteratorable(lucee.runtime.type.Iteratorable) ExecutorService(java.util.concurrent.ExecutorService) ListIterator(java.util.ListIterator) ForEachQueryIterator(lucee.runtime.type.it.ForEachQueryIterator) Iterator(java.util.Iterator) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with Iteratorable

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

the class ForEachUtil method _toIterator.

private static Iterator _toIterator(Object o) {
    if (o instanceof Iteratorable) {
        return ((Iteratorable) o).keysAsStringIterator();
    }
    if (o instanceof Iterator) {
        return (Iterator) o;
    }
    if (o instanceof Enumeration) {
        return new EnumAsIt((Enumeration) o);
    }
    if (o instanceof JavaObject) {
        Collection coll = Caster.toCollection(((JavaObject) o).getEmbededObject(null), null);
        if (coll != null)
            return coll.getIterator();
        String[] names = ClassUtil.getFieldNames(((JavaObject) o).getClazz());
        return new ArrayIterator(names);
    } else if (o instanceof CharSequence) {
        return ListUtil.listToArray(o.toString(), ',').getIterator();
    }
    return null;
}
Also used : Enumeration(java.util.Enumeration) JavaObject(lucee.runtime.java.JavaObject) ForEachIteratorable(lucee.runtime.type.ForEachIteratorable) Iteratorable(lucee.runtime.type.Iteratorable) Iterator(java.util.Iterator) Collection(lucee.runtime.type.Collection) EnumAsIt(lucee.runtime.type.it.EnumAsIt)

Example 5 with Iteratorable

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

the class Each method _call.

private static String _call(PageContext pc, Object obj, UDF udf, boolean parallel, int maxThreads, short type) throws PageException {
    ExecutorService execute = null;
    List<Future<Data<Object>>> futures = null;
    if (parallel) {
        execute = Executors.newFixedThreadPool(maxThreads);
        futures = new ArrayList<Future<Data<Object>>>();
    }
    // Array
    if (type == TYPE_ARRAY) {
        invoke(pc, (Array) obj, udf, execute, futures);
    } else // Query
    if (type == TYPE_QUERY) {
        invoke(pc, (Query) obj, udf, execute, futures);
    } else // Array
    if (obj instanceof Array) {
        invoke(pc, (Array) obj, udf, execute, futures);
    } else // Query
    if (obj instanceof Query) {
        invoke(pc, (Query) obj, udf, execute, futures);
    } else // other Iteratorable
    if (obj instanceof Iteratorable) {
        invoke(pc, (Iteratorable) obj, udf, execute, futures);
    } else // Map
    if (obj instanceof Map) {
        Iterator it = ((Map) obj).entrySet().iterator();
        Entry e;
        while (it.hasNext()) {
            e = (Entry) it.next();
            _call(pc, udf, new Object[] { e.getKey(), e.getValue(), obj }, execute, futures);
        // udf.call(pc, new Object[]{e.getKey(),e.getValue()}, true);
        }
    } else // List
    if (obj instanceof List) {
        ListIterator it = ((List) obj).listIterator();
        int index;
        while (it.hasNext()) {
            index = it.nextIndex();
            _call(pc, udf, new Object[] { it.next(), new Double(index), obj }, execute, futures);
        // udf.call(pc, new Object[]{it.next()}, true);
        }
    } else // Iterator
    if (obj instanceof Iterator) {
        Iterator it = (Iterator) obj;
        while (it.hasNext()) {
            _call(pc, udf, new Object[] { it.next() }, execute, futures);
        // udf.call(pc, new Object[]{it.next()}, true);
        }
    } else // Enumeration
    if (obj instanceof Enumeration) {
        Enumeration e = (Enumeration) obj;
        while (e.hasMoreElements()) {
            _call(pc, udf, new Object[] { e.nextElement() }, execute, futures);
        // udf.call(pc, new Object[]{e.nextElement()}, true);
        }
    } else // StringListData
    if (obj instanceof StringListData) {
        invoke(pc, (StringListData) obj, udf, execute, futures);
    } else
        throw new FunctionException(pc, "Each", 1, "data", "cannot iterate througth this type " + Caster.toTypeName(obj.getClass()));
    if (parallel)
        afterCall(pc, futures, execute);
    return null;
}
Also used : Enumeration(java.util.Enumeration) Query(lucee.runtime.type.Query) FunctionException(lucee.runtime.exp.FunctionException) ListIterator(java.util.ListIterator) Array(lucee.runtime.type.Array) Entry(java.util.Map.Entry) StringListData(lucee.runtime.type.util.StringListData) Iteratorable(lucee.runtime.type.Iteratorable) ExecutorService(java.util.concurrent.ExecutorService) ListIterator(java.util.ListIterator) ForEachQueryIterator(lucee.runtime.type.it.ForEachQueryIterator) Iterator(java.util.Iterator) Future(java.util.concurrent.Future) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map)

Aggregations

Enumeration (java.util.Enumeration)6 Iterator (java.util.Iterator)6 Iteratorable (lucee.runtime.type.Iteratorable)6 ArrayList (java.util.ArrayList)5 List (java.util.List)5 ListIterator (java.util.ListIterator)5 ExecutorService (java.util.concurrent.ExecutorService)5 Future (java.util.concurrent.Future)5 FunctionException (lucee.runtime.exp.FunctionException)5 Array (lucee.runtime.type.Array)5 Query (lucee.runtime.type.Query)5 ForEachQueryIterator (lucee.runtime.type.it.ForEachQueryIterator)5 StringListData (lucee.runtime.type.util.StringListData)5 Struct (lucee.runtime.type.Struct)4 Collection (lucee.runtime.type.Collection)3 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Pair (lucee.commons.lang.Pair)1 JavaObject (lucee.runtime.java.JavaObject)1 ForEachIteratorable (lucee.runtime.type.ForEachIteratorable)1