Example usage for java.util ArrayDeque ArrayDeque

List of usage examples for java.util ArrayDeque ArrayDeque

Introduction

In this page you can find the example usage for java.util ArrayDeque ArrayDeque.

Prototype

public ArrayDeque() 

Source Link

Document

Constructs an empty array deque with an initial capacity sufficient to hold 16 elements.

Usage

From source file:org.apache.asterix.optimizer.rules.IntroduceAutogenerateIDRule.java

@Override
public boolean rewritePost(Mutable<ILogicalOperator> opRef, IOptimizationContext context)
        throws AlgebricksException {

    // match: commit OR distribute-result OR SINK - ... followed by:
    // [insert to internal dataset with autogenerated id] - assign - project
    // produce: insert - assign - assign* - project
    // **/*  w  w  w.j a v a2 s.  co m*/
    // OR [insert to internal dataset with autogenerated id] - assign - [datasource scan]
    // produce insert - assign - assign* - datasource scan

    AbstractLogicalOperator currentOp = (AbstractLogicalOperator) opRef.getValue();
    if (currentOp.getOperatorTag() == LogicalOperatorTag.DELEGATE_OPERATOR) {
        DelegateOperator dOp = (DelegateOperator) currentOp;
        if (!(dOp.getDelegate() instanceof CommitOperator)) {
            return false;
        } else if (!((CommitOperator) dOp.getDelegate()).isSink()) {
            return false;
        }

    } else if (currentOp.getOperatorTag() != LogicalOperatorTag.DISTRIBUTE_RESULT
            && currentOp.getOperatorTag() != LogicalOperatorTag.SINK) {
        return false;
    }
    ArrayDeque<AbstractLogicalOperator> opStack = new ArrayDeque<>();
    opStack.push(currentOp);
    while (currentOp.getInputs().size() == 1) {
        currentOp = (AbstractLogicalOperator) currentOp.getInputs().get(0).getValue();
        if (currentOp.getOperatorTag() == LogicalOperatorTag.INSERT_DELETE_UPSERT) {
            break;
        }
        opStack.push(currentOp);
    }
    if (currentOp.getOperatorTag() != LogicalOperatorTag.INSERT_DELETE_UPSERT) {
        return false;
    }

    InsertDeleteUpsertOperator insertOp = (InsertDeleteUpsertOperator) currentOp;
    if (insertOp.getOperation() != Kind.INSERT) {
        return false;
    }

    DatasetDataSource dds = (DatasetDataSource) insertOp.getDataSource();
    boolean autogenerated = ((InternalDatasetDetails) dds.getDataset().getDatasetDetails()).isAutogenerated();
    if (!autogenerated) {
        return false;
    }

    if (((AqlDataSource) insertOp.getDataSource()).getDatasourceType() != AqlDataSourceType.INTERNAL_DATASET) {
        return false;
    }

    AbstractLogicalOperator parentOp = (AbstractLogicalOperator) currentOp.getInputs().get(0).getValue();
    if (parentOp.getOperatorTag() != LogicalOperatorTag.ASSIGN) {
        return false;
    }
    AssignOperator assignOp = (AssignOperator) parentOp;
    LogicalVariable inputRecord;

    //TODO: bug here. will not work for internal datasets with filters since the pattern becomes 
    //[project-assign-assign-insert]
    AbstractLogicalOperator grandparentOp = (AbstractLogicalOperator) parentOp.getInputs().get(0).getValue();
    if (grandparentOp.getOperatorTag() == LogicalOperatorTag.PROJECT) {
        ProjectOperator projectOp = (ProjectOperator) grandparentOp;
        inputRecord = projectOp.getVariables().get(0);
    } else if (grandparentOp.getOperatorTag() == LogicalOperatorTag.DATASOURCESCAN) {
        DataSourceScanOperator dssOp = (DataSourceScanOperator) grandparentOp;
        inputRecord = dssOp.getVariables().get(0);
    } else {
        return false;
    }

    List<String> pkFieldName = ((InternalDatasetDetails) dds.getDataset().getDatasetDetails()).getPrimaryKey()
            .get(0);
    ILogicalExpression rec0 = new VariableReferenceExpression(inputRecord);
    ILogicalExpression rec1 = createPrimaryKeyRecordExpression(pkFieldName);
    ILogicalExpression mergedRec = createRecordMergeFunction(rec0, rec1);
    ILogicalExpression nonNullMergedRec = createNotNullFunction(mergedRec);

    LogicalVariable v = context.newVar();
    AssignOperator newAssign = new AssignOperator(v, new MutableObject<ILogicalExpression>(nonNullMergedRec));
    newAssign.getInputs().add(new MutableObject<ILogicalOperator>(grandparentOp));
    assignOp.getInputs().set(0, new MutableObject<ILogicalOperator>(newAssign));
    VariableUtilities.substituteVariables(assignOp, inputRecord, v, context);
    VariableUtilities.substituteVariables(insertOp, inputRecord, v, context);
    context.computeAndSetTypeEnvironmentForOperator(newAssign);
    context.computeAndSetTypeEnvironmentForOperator(assignOp);
    context.computeAndSetTypeEnvironmentForOperator(insertOp);
    ;
    for (AbstractLogicalOperator op : opStack) {
        VariableUtilities.substituteVariables(op, inputRecord, v, context);
        context.computeAndSetTypeEnvironmentForOperator(op);
    }

    return true;
}

From source file:io.inkstand.scribble.jcr.rules.util.XMLContentHandler.java

/**
 * Creates a new content handler using the specified session for performing the input.
 *
 * @param session/*from w w w  .j av a  2  s.co  m*/
 *         the JCR session bound to a user with sufficient privileges to perform the content loader operation.
 */
public XMLContentHandler(final Session session) {

    this.session = session;
    this.nodeStack = new ArrayDeque<>();
    this.textStack = new ArrayDeque<>();
    this.propertyStack = new ArrayDeque<>();
}

From source file:com.google.gwt.emultest.java.util.ArrayDequeTest.java

public void testContains() {
    Object o1 = new Object();
    Object o2 = new Object();
    Object o3 = new Object();

    ArrayDeque<Object> deque = new ArrayDeque<>();
    assertFalse(deque.contains(o3));/*from w w w.  j  av a  2 s  .c om*/
    assertFalse(deque.contains(null));
    assertTrue(deque.add(o1));
    assertTrue(deque.add(o2));
    assertTrue(deque.add(o1));
    assertTrue(deque.add(o3));
    assertTrue(deque.contains(o1));
    assertTrue(deque.contains(o2));
    assertTrue(deque.contains(o3));
    assertFalse(deque.contains(null));

    deque.clear();
    assertTrue(deque.isEmpty());
    assertFalse(deque.contains(o1));
    assertFalse(deque.contains(o2));
    assertFalse(deque.contains(o3));
}

From source file:net.sf.jasperreports.engine.json.expression.member.evaluation.ObjectConstructionExpressionEvaluator.java

private List<JRJsonNode> goAnywhereDown(JRJsonNode jrJsonNode) {
    List<JRJsonNode> result = new ArrayList<>();
    Deque<JRJsonNode> stack = new ArrayDeque<>();

    if (log.isDebugEnabled()) {
        log.debug("initial stack population with: " + jrJsonNode.getDataNode());
    }//from  w  ww .jav  a 2 s .  com

    // populate the stack initially
    stack.push(jrJsonNode);

    while (!stack.isEmpty()) {
        JRJsonNode stackNode = stack.pop();
        JsonNode stackDataNode = stackNode.getDataNode();

        addChildrenToStack(stackNode, stack);

        if (log.isDebugEnabled()) {
            log.debug("processing stack element: " + stackDataNode);
        }

        // process the current stack item
        if (stackDataNode.isObject()) {
            JRJsonNode childWithKeys = constructNewObjectNodeWithKeys(stackNode);

            if (childWithKeys != null) {
                result.add(childWithKeys);
            }
        }
    }

    return result;
}

From source file:org.apache.hadoop.hive.ql.parse.ASTNode.java

private StringBuilder dump(StringBuilder sb) {
    Deque<ASTNode> stack = new ArrayDeque<ASTNode>();
    stack.push(this);
    int tabLength = 0;

    while (!stack.isEmpty()) {
        ASTNode next = stack.peek();// www  .  ja v a 2 s . com

        if (!next.visited) {
            sb.append(StringUtils.repeat(" ", tabLength * 3));
            sb.append(next.toString());
            sb.append("\n");

            if (next.children != null) {
                for (int i = next.children.size() - 1; i >= 0; i--) {
                    stack.push((ASTNode) next.children.get(i));
                }
            }

            tabLength++;
            next.visited = true;
        } else {
            tabLength--;
            next.visited = false;
            stack.pop();
        }
    }

    return sb;
}

From source file:fr.acxio.tools.agia.alfresco.AlfrescoNodeReader.java

@Override
public void open(ExecutionContext sExecutionContext) throws ItemStreamException {

    String aFullPath = null;/*from  w  w  w  .j a v  a2 s .  co  m*/

    try {
        baseURI = new URI(getAlfrescoService().getWebappAddress()).resolve(WEBDAV_PATH);
        aFullPath = getWebDavDirectoryURI(baseURI.getPath() + path).getPath();
    } catch (URISyntaxException e) {
        throw new ItemStreamException(e);
    }

    currentDirPath = sExecutionContext.getString(CONTEXT_KEY_CURRENTPATH, aFullPath);
    Object aCurrentIndexes = sExecutionContext.get(CONTEXT_KEY_CURRENTINDEXES);
    if (aCurrentIndexes == null) {
        currentIndexes = new ArrayDeque<Integer>();
        currentIndexes.addFirst(0);
    } else {
        Integer[] aArray = (Integer[]) aCurrentIndexes;
        currentIndexes = new ArrayDeque<Integer>(Arrays.asList(aArray));
    }

    sardine = getAlfrescoService().startWebDavSession();
}

From source file:org.restheart.test.performance.LoadGetPT.java

/**
 *
 *///from w ww  .j  av a2s. c om
public void dbdirect() {
    final Database dbsDAO = new DbsDAO();
    DBCollection dbcoll = dbsDAO.getCollection(db, coll);

    Deque<String> _filter;

    if (filter == null) {
        _filter = null;
    } else {
        _filter = new ArrayDeque<>();
        _filter.add(filter);
    }

    ArrayList<DBObject> data;

    try {
        data = new DbsDAO().getCollectionData(dbcoll, page, pagesize, null, _filter,
                DBCursorPool.EAGER_CURSOR_ALLOCATION_POLICY.NONE);
    } catch (Exception e) {
        System.out.println("error: " + e.getMessage());
        return;
    }

    assertNotNull(data);
    assertFalse(data.isEmpty());

    if (printData) {
        System.out.println(data);
    }
}

From source file:org.lilyproject.indexer.engine.ValueEvaluator.java

private List<String> extractContent(String table, List<IndexValue> indexValues, LRepository repository) {
    // At this point we can be sure the value will be a blob, this is
    // validated during
    // the construction of the indexer conf.

    List<String> result = new ArrayList<String>(indexValues.size());

    Deque<Integer> indexes = new ArrayDeque<Integer>();

    for (IndexValue indexValue : indexValues) {
        indexes.clear();//from ww  w.  j  a  va  2 s. c  o  m

        if (indexValue.listIndex != null) {
            indexes.addLast(indexValue.listIndex);
        }

        extractContent(table, indexValue.value, indexes, indexValue.record, indexValue.fieldType, result,
                repository);
    }

    return result.isEmpty() ? null : result;
}

From source file:io.fabric8.mockwebserver.internal.InlineWebSocketSessionBuilder.java

private void enqueue(Object req, WebSocketMessage resp) {
    Queue<WebSocketMessage> queuedResponses = session.getRequestEvents().get(req);
    if (queuedResponses == null) {
        queuedResponses = new ArrayDeque<>();
        session.getRequestEvents().put(req, queuedResponses);
    }/*from ww w . j  ava 2 s .c o m*/
    queuedResponses.add(resp);
}

From source file:org.gradle.model.internal.method.WeaklyTypeReferencingMethod.java

private Method findMethod(Class<?> clazz, Class<?>[] paramTypes) {
    Set<Class<?>> seenInterfaces = null;
    Queue<Class<?>> queue = null;
    Class<?> type = clazz;/*from   w  w w. java2  s.  c om*/
    while (type != null) {
        for (Method method : type.getDeclaredMethods()) {
            if (method.getName().equals(name) && Arrays.equals(paramTypes, method.getParameterTypes())) {
                return method;
            }
        }

        if (queue == null) {
            queue = new ArrayDeque<Class<?>>();
            seenInterfaces = Sets.newHashSet();
        }

        Class<?> superclass = type.getSuperclass();
        if (superclass != null) {
            queue.add(superclass);
        }
        for (Class<?> iface : type.getInterfaces()) {
            if (seenInterfaces.add(iface)) {
                queue.add(iface);
            }
        }

        type = queue.poll();
    }

    throw new org.gradle.internal.reflect.NoSuchMethodException(
            String.format("Could not find method %s(%s) on %s.", name, Joiner.on(", ").join(paramTypes),
                    this.target.getRawClass().getSimpleName()));
}