Search in sources :

Example 36 with ListIterator

use of java.util.ListIterator in project geode by apache.

the class QueryUtils method doNestedIterations.

// TODO:Optimize the function further in terms of reducing the
// parameters passed in the function, if possible
private static void doNestedIterations(int level, SelectResults returnSet, SelectResults[] results, RuntimeIterator[][] itrsForResultFields, List finalItrs, ListIterator expansionItrs, int finalLevel, ExecutionContext context, CompiledValue operand) throws FunctionDomainException, TypeMismatchException, NameResolutionException, QueryInvocationTargetException {
    if (level == finalLevel) {
        // end recusrion
        boolean select = true;
        if (operand != null) {
            select = applyCondition(operand, context);
        }
        Iterator itr = finalItrs.iterator();
        int len = finalItrs.size();
        if (len > 1) {
            Object[] values = new Object[len];
            int j = 0;
            while (itr.hasNext()) {
                values[j++] = ((RuntimeIterator) itr.next()).evaluate(context);
            }
            if (select) {
                ((StructFields) returnSet).addFieldValues(values);
            }
        } else {
            if (select)
                returnSet.add(((RuntimeIterator) itr.next()).evaluate(context));
        }
    } else if (level < results.length) {
        SelectResults individualResultSet = results[level];
        RuntimeIterator[] itrsForFields = itrsForResultFields[level];
        int len = itrsForFields.length;
        for (Object anIndividualResultSet : individualResultSet) {
            // Check if query execution on this thread is canceled.
            QueryMonitor.isQueryExecutionCanceled();
            if (len == 1) {
                // this means we have a ResultSet
                itrsForFields[0].setCurrent(anIndividualResultSet);
            } else {
                Struct struct = (Struct) anIndividualResultSet;
                Object[] fieldValues = struct.getFieldValues();
                int size = fieldValues.length;
                for (int i = 0; i < size; ++i) {
                    itrsForFields[i].setCurrent(fieldValues[i]);
                }
            }
            doNestedIterations(level + 1, returnSet, results, itrsForResultFields, finalItrs, expansionItrs, finalLevel, context, operand);
        }
    } else {
        RuntimeIterator currLevel = (RuntimeIterator) expansionItrs.next();
        SelectResults c = currLevel.evaluateCollection(context);
        if (c == null) {
            expansionItrs.previous();
            return;
        }
        for (Object aC : c) {
            currLevel.setCurrent(aC);
            doNestedIterations(level + 1, returnSet, results, itrsForResultFields, finalItrs, expansionItrs, finalLevel, context, operand);
        }
        expansionItrs.previous();
    }
}
Also used : SelectResults(org.apache.geode.cache.query.SelectResults) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) Struct(org.apache.geode.cache.query.Struct)

Example 37 with ListIterator

use of java.util.ListIterator in project gradle by gradle.

the class DefaultTaskDependency method visitDependencies.

@Override
public void visitDependencies(TaskDependencyResolveContext context) {
    Set<Object> mutableValues = getMutableValues();
    if (mutableValues.isEmpty() && immutableValues.isEmpty()) {
        return;
    }
    Deque<Object> queue = new ArrayDeque<Object>(mutableValues.size() + immutableValues.size());
    queue.addAll(immutableValues);
    queue.addAll(mutableValues);
    while (!queue.isEmpty()) {
        Object dependency = queue.removeFirst();
        if (dependency instanceof Buildable) {
            context.add(dependency);
        } else if (dependency instanceof Task) {
            context.add(dependency);
        } else if (dependency instanceof TaskDependency) {
            context.add(dependency);
        } else if (dependency instanceof Closure) {
            Closure closure = (Closure) dependency;
            Object closureResult = closure.call(context.getTask());
            if (closureResult != null) {
                queue.addFirst(closureResult);
            }
        } else if (dependency instanceof RealizableTaskCollection) {
            RealizableTaskCollection realizableTaskCollection = (RealizableTaskCollection) dependency;
            realizableTaskCollection.realizeRuleTaskTypes();
            addAllFirst(queue, realizableTaskCollection.toArray());
        } else if (dependency instanceof List) {
            List<?> list = (List) dependency;
            if (list instanceof RandomAccess) {
                for (int i = list.size() - 1; i >= 0; i--) {
                    queue.addFirst(list.get(i));
                }
            } else {
                ListIterator<?> iterator = list.listIterator(list.size());
                while (iterator.hasPrevious()) {
                    Object item = iterator.previous();
                    queue.addFirst(item);
                }
            }
        } else if (dependency instanceof Iterable) {
            Iterable<?> iterable = (Iterable) dependency;
            addAllFirst(queue, toArray(iterable, Object.class));
        } else if (dependency instanceof Map) {
            Map<?, ?> map = (Map) dependency;
            addAllFirst(queue, map.values().toArray());
        } else if (dependency instanceof Object[]) {
            Object[] array = (Object[]) dependency;
            addAllFirst(queue, array);
        } else if (dependency instanceof Callable) {
            Callable callable = (Callable) dependency;
            Object callableResult = uncheckedCall(callable);
            if (callableResult != null) {
                queue.addFirst(callableResult);
            }
        } else if (resolver != null && dependency instanceof TaskReference) {
            context.add(resolver.resolveTask((TaskReference) dependency));
        } else if (resolver != null && dependency instanceof CharSequence) {
            context.add(resolver.resolveTask(dependency.toString()));
        } else if (dependency instanceof TaskDependencyContainer) {
            ((TaskDependencyContainer) dependency).visitDependencies(context);
        } else if (dependency instanceof ProviderInternal) {
            ProviderInternal providerInternal = (ProviderInternal) dependency;
            if (providerInternal.getType() == null || providerInternal.getType().equals(Provider.class)) {
                queue.addFirst(providerInternal.get());
                continue;
            }
            List<String> formats = new ArrayList<String>();
            formats.add("A RegularFileProperty");
            formats.add("A DirectoryProperty");
            throw new UnsupportedNotationException(dependency, String.format("Cannot convert Provider %s to a task.", dependency), null, formats);
        } else {
            List<String> formats = new ArrayList<String>();
            if (resolver != null) {
                formats.add("A String or CharSequence task name or path");
                formats.add("A TaskReference instance");
            }
            formats.add("A Task instance");
            formats.add("A Buildable instance");
            formats.add("A TaskDependency instance");
            formats.add("A RegularFileProperty or DirectoryProperty instance");
            formats.add("A Provider instance that returns any of these types");
            formats.add("A Closure instance that returns any of these types");
            formats.add("A Callable instance that returns any of these types");
            formats.add("An Iterable, Collection, Map or array instance that contains any of these types");
            throw new UnsupportedNotationException(dependency, String.format("Cannot convert %s to a task.", dependency), null, formats);
        }
    }
}
Also used : TaskDependency(org.gradle.api.tasks.TaskDependency) Task(org.gradle.api.Task) Closure(groovy.lang.Closure) RandomAccess(java.util.RandomAccess) ListIterator(java.util.ListIterator) ArrayDeque(java.util.ArrayDeque) Callable(java.util.concurrent.Callable) TaskReference(org.gradle.api.tasks.TaskReference) ProviderInternal(org.gradle.api.internal.provider.ProviderInternal) UnsupportedNotationException(org.gradle.internal.typeconversion.UnsupportedNotationException) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) Buildable(org.gradle.api.Buildable)

Example 38 with ListIterator

use of java.util.ListIterator in project Lucee by lucee.

the class JSConverter method _serializeList.

/**
 * serialize a List (as Array)
 * @param name
 * @param list List to serialize
 * @param sb
 * @param done
 * @return serialized list
 * @throws ConverterException
 */
private void _serializeList(String name, List list, StringBuilder sb, Set<Object> done) throws ConverterException {
    if (useShortcuts)
        sb.append("[];");
    else
        sb.append("new Array();");
    ListIterator it = list.listIterator();
    int index = -1;
    while (it.hasNext()) {
        // if(index!=-1)sb.append(",");
        index = it.nextIndex();
        sb.append(name + "[" + index + "]=");
        _serialize(name + "[" + index + "]", it.next(), sb, done);
    // sb.append(";");
    }
}
Also used : ListIterator(java.util.ListIterator)

Example 39 with ListIterator

use of java.util.ListIterator in project Lucee by lucee.

the class JSONConverter method _serializeList.

/**
 * serialize a List (as Array)
 * @param list List to serialize
 * @param sb
 * @param serializeQueryByColumns
 * @param done
 * @throws ConverterException
 */
private void _serializeList(PageContext pc, Set test, List list, StringBuilder sb, boolean serializeQueryByColumns, Set<Object> done) throws ConverterException {
    sb.append(goIn());
    sb.append("[");
    boolean doIt = false;
    ListIterator it = list.listIterator();
    while (it.hasNext()) {
        if (doIt)
            sb.append(',');
        doIt = true;
        _serialize(pc, test, it.next(), sb, serializeQueryByColumns, done);
    }
    sb.append(']');
}
Also used : ListIterator(java.util.ListIterator)

Example 40 with ListIterator

use of java.util.ListIterator in project Lucee by lucee.

the class WDDXConverter method _serializeList.

/**
 * serialize a List (as Array)
 *
 * @param list
 *            List to serialize
 * @param done
 * @return serialized list
 * @throws ConverterException
 */
private String _serializeList(List list, Set<Object> done) throws ConverterException {
    StringBuilder sb = new StringBuilder(goIn() + "<array length=" + del + list.size() + del + ">");
    ListIterator it = list.listIterator();
    while (it.hasNext()) {
        sb.append(_serialize(it.next(), done));
    }
    sb.append(goIn() + "</array>");
    return sb.toString();
}
Also used : ListIterator(java.util.ListIterator)

Aggregations

ListIterator (java.util.ListIterator)121 ArrayList (java.util.ArrayList)42 List (java.util.List)41 LinkedList (java.util.LinkedList)26 Iterator (java.util.Iterator)21 Map (java.util.Map)12 Handler (com.sun.jsftemplating.annotation.Handler)8 AbstractList (java.util.AbstractList)7 HashMap (java.util.HashMap)7 AbstractSequentialList (java.util.AbstractSequentialList)6 IOException (java.io.IOException)5 RandomAccess (java.util.RandomAccess)5 SelectResults (org.apache.geode.cache.query.SelectResults)5 Test (org.junit.Test)5 File (java.io.File)4 HashSet (java.util.HashSet)4 NoSuchElementException (java.util.NoSuchElementException)4 SipURI (javax.sip.address.SipURI)4 ArgumentIntKey (lucee.runtime.type.scope.ArgumentIntKey)4 StructTypeImpl (org.apache.geode.cache.query.internal.types.StructTypeImpl)4