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:com.espertech.esper.event.vaevent.VAERevisionProcessorDeclared.java

public Collection<EventBean> getSnapshot(EPStatementAgentInstanceHandle createWindowStmtHandle,
        Viewable parent) {/*from w  ww .  j a  va2 s.  c o m*/
    createWindowStmtHandle.getStatementAgentInstanceLock().acquireReadLock();
    try {
        Iterator<EventBean> it = parent.iterator();
        if (!it.hasNext()) {
            return Collections.EMPTY_LIST;
        }
        ArrayDeque<EventBean> list = new ArrayDeque<EventBean>();
        while (it.hasNext()) {
            RevisionEventBeanDeclared fullRevision = (RevisionEventBeanDeclared) it.next();
            Object key = fullRevision.getKey();
            RevisionStateDeclared state = statePerKey.get(key);
            list.add(state.getLastEvent());
        }
        return list;
    } finally {
        createWindowStmtHandle.getStatementAgentInstanceLock().releaseReadLock();
    }
}

From source file:org.lilyproject.repository.impl.AbstractTypeManager.java

private void collectSubTypes(SchemaId recordTypeId, Set<SchemaId> result, boolean recursive)
        throws InterruptedException {
    collectSubTypes(recordTypeId, result, new ArrayDeque<SchemaId>(), recursive);
}

From source file:com.espertech.esper.epl.agg.AggSvcGroupByReclaimAged.java

private void sweep(long currentTime, long currentMaxAge) {
    ArrayDeque<MultiKeyUntyped> removed = new ArrayDeque<MultiKeyUntyped>();
    for (Map.Entry<MultiKeyUntyped, AggregationMethodRowAged> entry : aggregatorsPerGroup.entrySet()) {
        long age = currentTime - entry.getValue().getLastUpdateTime();
        if (age > currentMaxAge) {
            removed.add(entry.getKey());
        }//  w w w .  ja v  a  2 s .c  o  m
    }

    for (MultiKeyUntyped key : removed) {
        aggregatorsPerGroup.remove(key);
    }
}

From source file:cc.kave.commons.pointsto.analysis.unification.UnificationAnalysisVisitorContext.java

/**
 * Reruns the unification until all lazily added locations have propagated
 * and no more changes are detected./*w  ww  .  j  a  v a 2s .c  o m*/
 * 
 * {@link LocationIdentifier} are added lazily to
 * {@link ExtendedReferenceLocation} instances. If a location is added to an
 * already unified {@link ExtendedReferenceLocation}, the unification has to
 * be applied again to ensure correctness of the result.
 */
private void finalizePendingUnifications() {
    Deque<Pair<ReferenceLocation, ReferenceLocation>> worklist = new ArrayDeque<>();
    for (Map.Entry<ReferenceLocation, ReferenceLocation> locations : pendingUnifications.entries()) {
        ReferenceLocation refLoc1 = locations.getKey();
        ReferenceLocation refLoc2 = locations.getValue();

        int loc1Identifiers = refLoc1.getIdentifiers().size();
        int loc2Identifiers = refLoc2.getIdentifiers().size();

        if (loc1Identifiers != loc2Identifiers) {
            worklist.addFirst(ImmutablePair.of(refLoc1, refLoc2));
        }
    }

    while (!worklist.isEmpty()) {
        Pair<ReferenceLocation, ReferenceLocation> locations = worklist.removeFirst();
        ReferenceLocation loc1 = locations.getLeft();
        ReferenceLocation loc2 = locations.getRight();

        int previousIdentifiersLoc1 = loc1.getIdentifiers().size();
        int previousIdentifiersLoc2 = loc2.getIdentifiers().size();
        unify(loc1, loc2);

        updateUnificationWorklist(worklist, previousIdentifiersLoc1, loc1, loc2);
        updateUnificationWorklist(worklist, previousIdentifiersLoc2, loc2, loc1);
    }
}

From source file:io.cloudslang.score.lang.ExecutionRuntimeServices.java

protected void addBranch(Long startPosition, Long executionPlanId, Map<String, Serializable> context,
        ExecutionRuntimeServices executionRuntimeServices) {
    if (!contextMap.containsKey(BRANCH_DATA)) {
        contextMap.put(BRANCH_DATA, new ArrayList<StartBranchDataContainer>());
    }/*  w  w  w .  j av  a2s  .  com*/
    List<StartBranchDataContainer> branchesData = getFromMap(BRANCH_DATA);

    Map<String, Serializable> contextMapForBranch = new HashMap<>(executionRuntimeServices.contextMap);
    contextMapForBranch.remove(BRANCH_DATA);
    contextMapForBranch.put(SCORE_EVENTS_QUEUE, (ArrayDeque) new ArrayDeque<>());

    branchesData.add(new StartBranchDataContainer(startPosition, executionPlanId, context,
            new SystemContext(contextMapForBranch)));
}

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

private void translatePTFChain() throws SemanticException {

    Deque<PTFInputSpec> ptfChain = new ArrayDeque<PTFInvocationSpec.PTFInputSpec>();
    PTFInputSpec currentSpec = ptfInvocation.getFunction();
    while (currentSpec != null) {
        ptfChain.push(currentSpec);/*from  w  ww.  j  a v a2  s. c o  m*/
        currentSpec = currentSpec.getInput();
    }

    int inputNum = 0;
    PTFInputDef currentDef = null;
    while (!ptfChain.isEmpty()) {
        currentSpec = ptfChain.pop();

        if (currentSpec instanceof PTFQueryInputSpec) {
            currentDef = translate((PTFQueryInputSpec) currentSpec, inputNum);
        } else {
            currentDef = translate((PartitionedTableFunctionSpec) currentSpec, currentDef, inputNum);
        }
        inputNum++;
    }
    ptfDesc.setFuncDef((PartitionedTableFunctionDef) currentDef);
}

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

public void testGetFirst() {
    Object o1 = new Object();
    Object o2 = new Object();

    ArrayDeque<Object> deque = new ArrayDeque<>();
    try {//  w  ww. ja va 2s. c  o m
        deque.getFirst();
        fail();
    } catch (NoSuchElementException expected) {
    }

    deque.add(o1);
    assertEquals(o1, deque.getFirst());
    checkDequeSizeAndContent(deque, o1);

    deque.add(o2);
    assertEquals(o1, deque.getFirst());
    checkDequeSizeAndContent(deque, o1, o2);

    deque.clear();
    assertTrue(deque.isEmpty());
    try {
        deque.getFirst();
        fail();
    } catch (NoSuchElementException expected) {
    }
}

From source file:nl.knaw.huc.di.tag.tagml.importer.TAGMLListener.java

@Override
public void enterStartTag(StartTagContext ctx) {
    checkEOF(ctx);// www . j av  a 2  s. c o m
    if (tagNameIsValid(ctx)) {
        MarkupNameContext markupNameContext = ctx.markupName();
        String markupName = markupNameContext.name().getText();
        //      LOG.debug("startTag.markupName=<{}>", markupName);
        checkNameSpace(ctx, markupName);
        ctx.annotation().forEach(annotation -> LOG.debug("  startTag.annotation={{}}", annotation.getText()));

        PrefixContext prefix = markupNameContext.prefix();
        boolean optional = prefix != null && prefix.getText().equals(OPTIONAL_PREFIX);
        boolean resume = prefix != null && prefix.getText().equals(RESUME_PREFIX);

        TAGMarkup markup = resume ? resumeMarkup(ctx)
                : addMarkup(markupName, ctx.annotation(), ctx).setOptional(optional);

        Set<String> layerIds = extractLayerInfo(ctx.markupName().layerInfo());
        Set<String> layers = new HashSet<>();
        state.allOpenMarkup.push(markup);
        boolean firstTag = !document.getLayerNames().contains(TAGML.DEFAULT_LAYER);
        if (firstTag) {
            addDefaultLayer(markup, layers);
            state.rootMarkupId = markup.getDbId();
        }
        layerIds.forEach(layerId -> {
            if (layerId.contains("+")) {
                String[] parts = layerId.split("\\+");
                String parentLayer = parts[0];
                String newLayerId = parts[1];
                document.addLayer(newLayerId, markup, parentLayer);
                //          layers.add(parentLayer);
                layers.add(newLayerId);

            } else if (!(firstTag && DEFAULT_LAYER.equals(layerId))) {
                checkLayerWasAdded(ctx, layerId);
                checkLayerIsOpen(ctx, layerId);
                document.openMarkupInLayer(markup, layerId);
                layers.add(layerId);
            }
        });
        markup.addAllLayers(layers);

        addSuffix(markupNameContext, markup);
        markup.getLayers().forEach(l -> {
            state.openMarkup.putIfAbsent(l, new ArrayDeque<>());
            state.openMarkup.get(l).push(markup);
        });

        currentTextVariationState().addOpenMarkup(markup);
        store.persist(markup.getDTO());
    }
}

From source file:org.aksw.simba.bengal.triple2nl.converter.DefaultIRIConverter.java

private static String splitCamelCase(String s) {
    StringBuilder sb = new StringBuilder();
    for (String token : s.split(" ")) {
        String[] split = StringUtils.splitByCharacterTypeCamelCase(token);
        Deque<String> list = new ArrayDeque<>();
        for (int i = 0; i < split.length; i++) {
            String s1 = split[i];
            if (i > 0 && s1.length() == 1 && !org.apache.commons.lang3.StringUtils.isNumeric(s1)) { // single
                // character
                // ->
                // append
                // to
                // previous
                // token
                list.add(list.pollLast() + s1);
            } else {
                list.add(s1);/*www.  j  a v a  2s  .c  om*/
            }
        }
        sb.append(StringUtils.join(list, ' ')).append(" ");
    }
    return sb.toString().trim();
    // return s.replaceAll(
    // String.format("%s|%s|%s",
    // "(?<=[A-Z])(?=[A-Z][a-z])",
    // "(?<=[^A-Z])(?=[A-Z])",
    // "(?<=[A-Za-z])(?=[^A-Za-z])"
    // ),
    // " "
    // );
}

From source file:io.github.benas.jpopulator.impl.PopulatorImpl.java

/**
 * Method to populate a collection type which can be an array or a {@link Collection}.
 *
 * @param field The field in which the generated value will be set
 * @return an random collection matching type of field.
 * @throws IllegalAccessException    Thrown when the generated value cannot be set to the given field
 * @throws NoSuchMethodException     Thrown when there is no setter for the given field
 * @throws InvocationTargetException Thrown when the setter of the given field can not be invoked
 *///from   www. j a v a  2  s. co  m
private Object getRandomCollection(final Field field)
        throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
    Class<?> fieldType = field.getType();

    //Array type
    if (fieldType.isArray()) {
        return Array.newInstance(fieldType.getComponentType(), 0);
    }

    //Collection type
    Object collection = null;
    if (List.class.isAssignableFrom(fieldType)) {
        collection = Collections.emptyList();
    } else if (NavigableSet.class.isAssignableFrom(fieldType)) {
        collection = new TreeSet();
    } else if (SortedSet.class.isAssignableFrom(fieldType)) {
        collection = new TreeSet();
    } else if (Set.class.isAssignableFrom(fieldType)) {
        collection = Collections.emptySet();
    } else if (Deque.class.isAssignableFrom(fieldType)) {
        collection = new ArrayDeque();
    } else if (Queue.class.isAssignableFrom(fieldType)) {
        collection = new ArrayDeque();
    } else if (NavigableMap.class.isAssignableFrom(fieldType)) {
        collection = new TreeMap();
    } else if (SortedMap.class.isAssignableFrom(fieldType)) {
        collection = new TreeMap();
    } else if (Map.class.isAssignableFrom(fieldType)) {
        collection = Collections.emptyMap();
    } else if (Collection.class.isAssignableFrom(fieldType)) {
        collection = Collections.emptyList();
    }

    return collection;
}