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:bb.mcmc.analysis.GewekeConvergeStat.java

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

    if (!Double.isNaN(stat)) {
        if (record.size() > 2) {
            record.pop();/*ww  w  .  ja  v a 2s  . com*/
        }
        record.add(stat);
    }
    double avgStat = 0;
    for (double d : record) {
        avgStat += d;
    }
    avgStat /= record.size();

    //      final double progress = Math.exp( rafteryThreshold - avgStat );

    //      return progress;

    final double progress = (1 - nd.cumulativeProbability(Math.abs(avgStat))) / gewekeProgressThreshold;
    //         final double tempP = (1-nd.cumulativeProbability(Math.abs(gewekeStat)-gewekeThreshold))/0.5;
    //         R Code
    //         data<- seq(1.96,4,by=0.01)
    //         plot(data, 1-(pnorm(abs(data))-pnorm(1.96))/0.025, type="l", col=2)
    //         plot(data, (1-pnorm(data-1.96))/0.5, type="l", col=2)

    return progress;
}

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

private void subtract(Set<Interaction> impossible, int vertex) throws NotConnectedException {
    Set<Integer> visited = new HashSet<Integer>();
    Deque<Integer> todo = new ArrayDeque<Integer>();

    todo.add(vertex);
    while (!todo.isEmpty()) {
        int u = todo.remove();
        visited.add(u);// w  ww.  j a  v a2s  .  co m

        for (int e : getIncidentEdges(u)) {
            Interaction i = edgesToInteractions.get(e);
            if (impossible.contains(i)) {
                removeEdge(e);
                edgesToInteractions.remove(e);
                interactionToEdges.remove(i, e);
                impossible.remove(i);
            }
        }

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

    if (visited.size() < getVertexCount()) {
        throw new NotConnectedException();
    }
}

From source file:au.com.cybersearch2.classyfy.ClassyfyLogic.java

public NodeDetailsBean getNodeDetails(Node data) {
    NodeDetailsBean nodeDetailsBean = new NodeDetailsBean();
    // Collect children, distinguishing between folders and categories
    for (Node child : data.getChildren()) {
        String title = child.getTitle();
        long id = (long) child.getId();
        ListItem item = new ListItem("Title", title, id);
        if (RecordModel.getModel(child.getModel()) == RecordModel.recordFolder)
            nodeDetailsBean.getFolderTitles().add(item);
        else/*from  www  .ja v a 2 s  .c  o m*/
            nodeDetailsBean.getCategoryTitles().add(item);
    }
    // Collect node hierarchy up to root node
    Node node = data.getParent();
    Deque<Node> nodeDeque = new ArrayDeque<Node>();
    // Walk up to top node
    while (node.getModel() != NodeType.ROOT)// Top of tree
    {
        nodeDeque.add(node);
        node = node.getParent();
    }
    Iterator<Node> nodeIterator = nodeDeque.descendingIterator();
    while (nodeIterator.hasNext()) {
        node = nodeIterator.next();
        String title = node.getTitle();
        long id = (long) node.getId();
        ListItem item = new ListItem("Title", title, id);
        nodeDetailsBean.getHierarchy().add(item);
    }
    // Build heading from Title and record type
    StringBuilder builder = new StringBuilder();
    builder.append(RecordModel.getNameByNode(data)).append(": ");
    if ((data.getTitle() != null) && (data.getTitle().length() > 0))
        builder.append(data.getTitle());
    else
        builder.append('?'); // This is an error. Handle gracefully.
    nodeDetailsBean.setHeading(builder.toString());
    // Collect details in FieldDescripter order
    Map<String, Object> valueMap = data.getProperties();
    Set<FieldDescriptor> fieldSet = FieldDescriptorSetFactory.instance(data);
    for (FieldDescriptor descriptor : fieldSet) {
        Object value = valueMap.get(descriptor.getName());
        if (value == null)
            continue;
        nodeDetailsBean.getFieldList().add(new ListItem(descriptor.getTitle(), value.toString()));
    }
    return nodeDetailsBean;
}

From source file:org.lunarray.model.descriptor.accessor.reference.ReferenceBuilder.java

/**
 * Gets the properties.// ww w.  ja v  a 2  s  . c om
 * 
 * @return The properties.
 */
public Deque<Property<?>> getProperties() {
    final Deque<Property<?>> result = new LinkedList<Property<?>>();
    for (final PropertyBuilder<?> property : this.properties) {
        result.add(property.build());
    }
    return result;
}

From source file:org.talend.dataquality.semantic.recognizer.DefaultCategoryRecognizer.java

/**
 * For the discovery, if a category c matches with the data,
 * it means all the ancestor categories of c have to match too.
 * This method increments the ancestor categories of c.
 * //from   w  w  w . ja v a2s  . c  om
 * @param categories, the category result
 * @param id, the category ID of the matched category c
 * 
 */
private void incrementAncestorsCategories(Set<String> categories, String id) {
    Deque<Pair<String, Integer>> catToSee = new ArrayDeque<>();
    Set<String> catAlreadySeen = new HashSet<>();
    catToSee.add(Pair.of(id, 0));
    Pair<String, Integer> currentCategory;
    while (!catToSee.isEmpty()) {
        currentCategory = catToSee.pop();
        DQCategory dqCategory = crm.getCategoryMetadataById(currentCategory.getLeft());
        if (dqCategory != null && !CollectionUtils.isEmpty(dqCategory.getParents())) {
            int parentLevel = currentCategory.getRight() + 1;
            for (DQCategory parent : dqCategory.getParents()) {
                if (!catAlreadySeen.contains(parent.getId())) {
                    catAlreadySeen.add(parent.getId());
                    catToSee.add(Pair.of(parent.getId(), parentLevel));
                    DQCategory meta = crm.getCategoryMetadataById(parent.getId());
                    if (meta != null) {
                        incrementCategory(meta.getName(), meta.getLabel(), parentLevel);
                        categories.add(meta.getName());
                    }
                }
            }
        }
    }
}

From source file:eu.openanalytics.rsb.rservi.CircularRServiUriSelector.java

private URI getCircular(final Deque<URI> applicationRserviPoolUris) {
    if (applicationRserviPoolUris.size() == 1) {
        return applicationRserviPoolUris.peek();
    }//ww  w .j a  va2  s .c  o m

    synchronized (applicationRserviPoolUris) {
        final URI uri = applicationRserviPoolUris.poll();
        applicationRserviPoolUris.add(uri);
        return uri;
    }
}

From source file:org.lunarray.model.descriptor.accessor.reference.ReferenceBuilder.java

/**
 * Gets the properties./*from  ww  w .j a  va2 s . c om*/
 * 
 * @return The properties.
 */
public Deque<DescribedProperty<?>> getDescribedProperties() {
    final Deque<DescribedProperty<?>> result = new LinkedList<DescribedProperty<?>>();
    for (final PropertyBuilder<?> property : this.properties) {
        result.add(property.buildDescribed());
    }
    return result;
}

From source file:net.jadler.JadlerMocker.java

private Deque<StubRule> createRules() {
    final Deque<StubRule> rules = new LinkedList<StubRule>();
    for (final Stubbing stub : stubbings) {
        rules.add(stub.createRule());
    }//from   ww  w . j  a  v a 2s . c  om
    return rules;
}

From source file:org.nuxeo.ecm.platform.routing.core.impl.GraphRouteImpl.java

/**
 * Finds which transitions are re-looping (feedback arc set).
 *//*from   www .  j a  v  a2s  .c om*/
protected void computeLoopTransitions(String startNodeId) throws DocumentRouteException {
    if (startNodeId == null) {
        // incomplete graph
        return;
    }
    /*
     * Depth-first search. In the todo stack, each element records a list of the siblings left to visit at that
     * depth. After visiting the last sibling, we go back to the parent and at this point mark it as visited in
     * post-traversal order.
     */
    List<String> postOrder = new LinkedList<String>();
    Deque<Deque<String>> stack = new LinkedList<Deque<String>>();
    Deque<String> first = new LinkedList<String>();
    first.add(startNodeId);
    stack.push(first);
    Set<String> done = new HashSet<String>();
    for (;;) {
        // find next sibling
        String nodeId = stack.peek().peek();
        if (nodeId == null) {
            // last sibling done
            // go back up one level and mark post-traversal order
            stack.pop(); // pop empty children
            if (stack.isEmpty()) {
                // we are done
                break;
            }
            nodeId = stack.peek().pop(); // pop parent
            postOrder.add(nodeId); // mark post-traversal order
        } else if (done.add(nodeId)) {
            // traverse the next sibling
            Deque<String> children = new LinkedList<String>();
            for (Transition t : getNode(nodeId).getOutputTransitions()) {
                children.add(t.target);
            }
            // add children to stack and recurse
            stack.push(children);
        } else {
            // already traversed
            stack.peek().pop(); // skip it
        }
    }

    // reverse the post-order to find the topological ordering
    Collections.reverse(postOrder);
    Map<String, Integer> ordering = new HashMap<String, Integer>();
    int i = 1;
    for (String nodeId : postOrder) {
        ordering.put(nodeId, Integer.valueOf(i++));
    }

    // walk the graph and all transitions again
    // and mark as looping the transitions pointing to a node
    // with a smaller order that the source
    done.clear();
    Deque<String> todo = new LinkedList<String>();
    todo.add(startNodeId);
    while (!todo.isEmpty()) {
        String nodeId = todo.pop();
        if (done.add(nodeId)) {
            int source = ordering.get(nodeId).intValue();
            for (Transition t : getNode(nodeId).getOutputTransitions()) {
                todo.push(t.target);
                // compare orders to detected feeback arcs
                int target = ordering.get(t.target).intValue();
                if (target <= source) {
                    t.loop = true;
                }
            }
        }
    }
}

From source file:io.undertow.server.handlers.proxy.LoadBalancingProxyHTTP2TestCase.java

@Test
public void testHttp2ClientMultipleStreamsThreadSafety()
        throws IOException, URISyntaxException, ExecutionException, InterruptedException, TimeoutException {
    //not actually a proxy test
    //but convent to put it here
    UndertowXnioSsl ssl = new UndertowXnioSsl(DefaultServer.getWorker().getXnio(), OptionMap.EMPTY,
            DefaultServer.SSL_BUFFER_POOL, DefaultServer.createClientSslContext());
    final UndertowClient client = UndertowClient.getInstance();
    final ClientConnection connection = client.connect(
            new URI("https", null, DefaultServer.getHostAddress(), DefaultServer.getHostPort() + 1, "/", null,
                    null),//  w  ww.  j a  v a2  s  . c om
            DefaultServer.getWorker(), ssl, DefaultServer.getBufferPool(),
            OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)).get();
    final ExecutorService service = Executors.newFixedThreadPool(10);
    try {
        Deque<FutureResult<String>> futures = new ArrayDeque<>();
        for (int i = 0; i < 100; ++i) {
            final FutureResult<String> future = new FutureResult<>();
            futures.add(future);
            service.submit(new Callable<String>() {

                @Override
                public String call() throws Exception {
                    ClientRequest cr = new ClientRequest().setMethod(Methods.GET).setPath("/path")
                            .setProtocol(Protocols.HTTP_1_1);
                    connection.sendRequest(cr, new ClientCallback<ClientExchange>() {
                        @Override
                        public void completed(ClientExchange result) {
                            result.setResponseListener(new ClientCallback<ClientExchange>() {
                                @Override
                                public void completed(ClientExchange result) {
                                    new StringReadChannelListener(DefaultServer.getBufferPool()) {
                                        @Override
                                        protected void stringDone(String string) {
                                            future.setResult(string);
                                        }

                                        @Override
                                        protected void error(IOException e) {
                                            future.setException(e);
                                        }
                                    }.setup(result.getResponseChannel());
                                }

                                @Override
                                public void failed(IOException e) {
                                    future.setException(e);
                                }
                            });
                        }

                        @Override
                        public void failed(IOException e) {
                            future.setException(e);
                        }
                    });
                    return null;
                }
            });
        }
        while (!futures.isEmpty()) {
            FutureResult<String> future = futures.poll();
            Assert.assertNotEquals(IoFuture.Status.WAITING,
                    future.getIoFuture().awaitInterruptibly(10, TimeUnit.SECONDS));
            Assert.assertEquals("/path", future.getIoFuture().get());
        }
    } finally {
        service.shutdownNow();
    }
}