Example usage for java.util Deque add

List of usage examples for java.util Deque add

Introduction

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

Prototype

boolean add(E e);

Source Link

Document

Inserts the specified element into the queue represented by this deque (in other words, at the tail of this deque) if it is possible to do so immediately without violating capacity restrictions, returning true upon success and throwing an IllegalStateException if no space is currently available.

Usage

From source file:specminers.evaluation.MinedSpecsFilter.java

private boolean checkIfCatchSectionSwallowsException(String catchBlockStartLine) {
    int startIndex = this.lines.indexOf(catchBlockStartLine);

    // contains return, continue or does not throw.
    Deque<String> blocks = new LinkedList<>();
    blocks.add(catchBlockStartLine);

    Deque<Integer> blockStartPositions = new LinkedList<>();
    blockStartPositions.add(sourceCode.indexOf(catchBlockStartLine) + catchBlockStartLine.indexOf("{"));

    boolean throwFound = false;

    int currentBlockStart = blockStartPositions.peekFirst();
    int currentIndexInFile = currentBlockStart;
    for (int i = startIndex; i < lines.size(); i++) {
        String line = lines.get(i);
        if (!blocks.isEmpty()) {
            if (line.contains("{") && i != startIndex) {
                blocks.add(line);/*from   ww w . j  av  a  2 s . c  om*/
                blockStartPositions.add(sourceCode.indexOf(line.trim()));
            }

            if (line.contains("}") && line.indexOf("}") + currentIndexInFile > currentBlockStart) {
                blocks.pop();
                currentBlockStart = blockStartPositions.pop();
            }
            if (line.contains("return ") || line.contains("return;") || line.contains("continue;")) {
                return true;
            }

            if (line.contains("throw ")) {
                throwFound = true;
            }
        }
        currentIndexInFile += line.length();
    }

    return !throwFound;
}

From source file:org.lunarray.model.descriptor.builder.annotation.base.listener.operation.parameter.collection.SetCollectionTypeListener.java

/** {@inheritDoc} */
@Override/* w  ww.  j  av  a  2 s  . c  om*/
public void handleEvent(final UpdatedParameterEvent<P, B> event) throws EventException {
    SetCollectionTypeListener.LOGGER.debug("Handling event {}", event);
    Validate.notNull(event, "Event may not be null.");
    @SuppressWarnings("unchecked")
    final AnnotationCollectionParameterDescriptorBuilder<C, P, B> builder = (AnnotationCollectionParameterDescriptorBuilder<C, P, B>) event
            .getBuilder();
    final Class<?> collectionType;
    final Deque<DescribedParameter<?>> params = new LinkedList<DescribedParameter<?>>();
    params.add(event.getParameter());
    final java.lang.reflect.Type tmpType = GenericsUtil.getPropertyGenericType(Collection.class, 0, params);
    if (tmpType instanceof Class) {
        collectionType = (Class<?>) tmpType;
    } else if (tmpType instanceof ParameterizedType) {
        final ParameterizedType ptype = (ParameterizedType) tmpType;
        final Type rawType = ptype.getRawType();
        if (rawType instanceof Class) {
            collectionType = (Class<?>) rawType;
        } else {
            collectionType = Object.class;
        }
    } else {
        collectionType = Object.class;
    }
    builder.collectionType(collectionType);
}

From source file:org.structnetalign.merge.DistanceClusterer.java

/**
 *
 * @param graph//w w  w. j  a  v  a  2 s .c  o m
 * @param roots
 * @return For each root, the set of other roots that are easily reachable, including the parent root
 */
public final Map<V, Set<V>> transform(Graph<V, E> graph, Collection<V> roots) {

    Map<V, Set<V>> reachableMap = new HashMap<V, Set<V>>();

    for (V root : roots) {

        Set<V> reachable = new HashSet<>();
        HashSet<V> unvisited = new HashSet<V>(graph.getVertices());

        // a map from every vertex to the edge used to get to it
        // works because only visit a vertex once
        HashMap<V, E> edgesTaken = new HashMap<V, E>();

        Deque<V> queue = new LinkedList<V>();
        queue.add(root);
        reachable.add(root);

        while (!queue.isEmpty()) {

            V vertex = queue.remove();
            E edge = edgesTaken.get(vertex);
            unvisited.remove(vertex);

            // stop traversing if we're too far
            if (!isWithinRange(root, vertex))
                continue;

            reachable.add(vertex); // not that this is AFTER the within-range check

            if (edge != null)
                visit(vertex, edge); // this is the ONLY place where we "officially" VISIT a vertex

            Collection<V> neighbors = graph.getNeighbors(vertex);
            for (V neighbor : neighbors) {
                if (unvisited.contains(neighbor)) {
                    queue.add(neighbor);
                    E edgeToNeighbor = graph.findEdge(vertex, neighbor);
                    edgesTaken.put(neighbor, edgeToNeighbor);
                }
            }

            unvisit(vertex, edge); // this is the ONLY place where we "officially" UNVISIT a vertex

        }

        reachableMap.put(root, reachable);

    }

    return reachableMap;
}

From source file:com.cinchapi.concourse.lang.Parser.java

/**
 * Convert a valid and well-formed list of {@link Symbol} objects into a
 * an {@link AST}./*from   ww  w.ja  v a 2s  .c  o  m*/
 * <p>
 * NOTE: This method will group non-conjunctive symbols into
 * {@link Expression} objects.
 * </p>
 * 
 * @param symbols
 * @return the symbols in an AST
 */
public static AST toAbstractSyntaxTree(List<Symbol> symbols) {
    Deque<Symbol> operatorStack = new ArrayDeque<Symbol>();
    Deque<AST> operandStack = new ArrayDeque<AST>();
    symbols = groupExpressions(symbols);
    main: for (Symbol symbol : symbols) {
        if (symbol == ParenthesisSymbol.LEFT) {
            operatorStack.push(symbol);
        } else if (symbol == ParenthesisSymbol.RIGHT) {
            while (!operatorStack.isEmpty()) {
                Symbol popped = operatorStack.pop();
                if (popped == ParenthesisSymbol.LEFT) {
                    continue main;
                } else {
                    addASTNode(operandStack, popped);
                }
            }
            throw new SyntaxException(
                    MessageFormat.format("Syntax error in {0}: Mismatched parenthesis", symbols));
        } else if (symbol instanceof Expression) {
            operandStack.add(ExpressionTree.create((Expression) symbol));
        } else {
            operatorStack.push(symbol);
        }
    }
    while (!operatorStack.isEmpty()) {
        addASTNode(operandStack, operatorStack.pop());
    }
    return operandStack.pop();
}

From source file:org.lunarray.model.descriptor.builder.annotation.base.listener.operation.result.collection.SetCollectionTypeListener.java

/** {@inheritDoc} */
@Override//from   w w w  .j ava 2  s.  c om
public void handleEvent(final UpdatedCollectionResultTypeEvent<C, R, E, B> event) throws EventException {
    SetCollectionTypeListener.LOGGER.debug("Handling event {}", event);
    Validate.notNull(event, "Event may not be null.");
    final AnnotationCollectionResultDescriptorBuilder<C, R, E, B> builder = event.getBuilder();
    final Deque<Member> members = new LinkedList<Member>();
    members.addAll(builder.getBuilderContext().getAccessorContext().getDescribedProperties());
    members.add(builder.getOperation());
    final Class<?> collectionType;
    final java.lang.reflect.Type tmpType = GenericsUtil.getPropertyGenericType(Collection.class, 0, members);
    if (tmpType instanceof Class) {
        collectionType = (Class<?>) tmpType;
    } else if (tmpType instanceof ParameterizedType) {
        final ParameterizedType ptype = (ParameterizedType) tmpType;
        final Type rawType = ptype.getRawType();
        if (rawType instanceof Class) {
            collectionType = (Class<?>) rawType;
        } else {
            collectionType = Object.class;
        }
    } else {
        collectionType = Object.class;
    }
    builder.collectionType(collectionType);
}

From source file:org.lunarray.model.descriptor.builder.annotation.resolver.entity.def.DefaultEntityResolver.java

/** {@inheritDoc} */
@Override/*ww w .  j  a  v  a  2s .c o  m*/
public DescribedEntity<?> resolveEntity(final Class<?> entityType) {
    DefaultEntityResolver.LOGGER.debug("Resolving entity {}", entityType);
    Validate.notNull(entityType, "Entity type may not be null.");
    @SuppressWarnings("unchecked")
    final EntityBuilder<?> builder = DescribedEntity.createBuilder().entityType((Class<Object>) entityType);
    final List<Class<?>> hierarchy = new LinkedList<Class<?>>();
    if (this.searchHierarchyResolver) {
        final Deque<Class<?>> types = new LinkedList<Class<?>>();
        final Set<Class<?>> processed = new HashSet<Class<?>>();
        types.add(entityType);
        while (!types.isEmpty()) {
            final Class<?> next = types.pop();
            hierarchy.add(next);
            final Class<?> superType = next.getSuperclass();
            if (!CheckUtil.isNull(superType) && !processed.contains(superType)) {
                types.add(superType);
            }
            for (final Class<?> interfaceType : next.getInterfaces()) {
                if (!processed.contains(interfaceType)) {
                    types.add(interfaceType);
                }
            }
            processed.add(next);
        }
    } else {
        hierarchy.add(entityType);
    }
    for (final Class<?> type : hierarchy) {
        for (final Annotation a : type.getAnnotations()) {
            builder.addAnnotation(a);
        }
    }
    final DescribedEntity<?> result = builder.build();
    DefaultEntityResolver.LOGGER.debug("Resolved entity {} for type {}", result, entityType);
    return result;
}

From source file:org.deeplearning4j.text.corpora.treeparser.BinarizeTreeTransformer.java

@Override
public Tree transform(Tree t) {
    if (t == null)
        return null;
    Deque<Pair<Tree, String>> stack = new ArrayDeque<>();
    stack.add(new Pair<>(t, t.label()));
    String originalLabel = t.label();
    while (!stack.isEmpty()) {
        Pair<Tree, String> curr = stack.pop();
        Tree node = curr.getFirst();/*from w  ww  . j  a  va  2 s .  c om*/

        for (Tree child : node.children())
            stack.add(new Pair<>(child, curr.getSecond()));

        if (node.children().size() > 2) {

            List<String> children = new ArrayList<>();
            for (int i = 0; i < node.children().size(); i++)
                children.add(node.children().get(i).label());

            Tree copy = node.clone();
            //clear out children
            node.children().clear();

            Tree currNode = node;

            for (int i = 1; i < children.size() - 1; i++) {
                if (factor.equals("right")) {
                    Tree newNode = new Tree(currNode);

                    List<String> subChildren = children.subList(i,
                            Math.min(i + horizontonalMarkov, children.size()));

                    newNode.setLabel(originalLabel + "-" + "(" + StringUtils.join(subChildren, "-"));

                    newNode.setParent(currNode);

                    currNode.children().add(copy.children().remove(0));

                    currNode.firstChild().setParent(currNode);

                    currNode.children().add(newNode);

                    currNode = newNode;

                } else {
                    Tree newNode = new Tree(currNode);

                    newNode.setParent(copy.firstChild());

                    List<String> childLabels = children
                            .subList(Math.max(children.size() - i - horizontonalMarkov, 0), i);

                    Collections.reverse(childLabels);
                    newNode.setLabel(originalLabel + "-" + "(" + StringUtils.join(childLabels, "-"));

                    currNode.children().add(newNode);

                    currNode.firstChild().setParent(currNode);

                    currNode.children().add(copy.children().remove(copy.children().size() - 1));
                    currNode.lastChild().setParent(currNode);

                    currNode = newNode;
                }
            }

            currNode.children().addAll(new ArrayList<>(copy.children()));
        }
    }

    addPreTerminal(t);
    return t;
}

From source file:bb.mcmc.analysis.ESSConvergeStat.java

@Override
protected double calculateEachProgress(Double stat, Deque<Double> record) {

    if (!Double.isNaN(stat)) {
        if (record.size() > 0) {
            record.pop();//w ww  .  j av a2s  .com
        }
        record.add(stat);
    }
    stat = record.peekFirst();
    double progress = stat / essThreshold;
    return progress;
}

From source file:org.alfresco.repo.content.transform.TransformerLog.java

@Override
protected void addOrModify(Deque<String> entries, Object message) {
    StringBuilder sb = new StringBuilder();
    sb.append(TransformerLogger.DATE_FORMAT.format(new Date()));
    sb.append(' ');
    sb.append(message);//from w w  w .  j a  va2 s .  c  om

    entries.add(sb.toString());
}

From source file:logicProteinHypernetwork.analysis.reactions.ComplexMultigraph.java

public Set<Integer> bfs() {
    Set<Integer> visited = new HashSet<Integer>();
    Deque<Integer> todo = new ArrayDeque<Integer>();

    todo.add(0);
    while (!todo.isEmpty()) {
        int u = todo.remove();
        visited.add(u);//w  w  w  . j  av a  2 s .  co  m

        for (int v : getNeighbors(u)) {
            todo.add(v);
        }
    }
    return visited;
}