Example usage for java.util Queue remove

List of usage examples for java.util Queue remove

Introduction

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

Prototype

E remove();

Source Link

Document

Retrieves and removes the head of this queue.

Usage

From source file:org.jboss.qa.brms.performance.examples.projectjobscheduling.domain.solver.PredecessorsDoneDateUpdatingVariableListener.java

protected void updateAllocation(ScoreDirector scoreDirector, Allocation originalAllocation) {
    Queue<Allocation> uncheckedSuccessorQueue = new ArrayDeque<Allocation>();
    uncheckedSuccessorQueue.addAll(originalAllocation.getSuccessorAllocationList());
    while (!uncheckedSuccessorQueue.isEmpty()) {
        Allocation allocation = uncheckedSuccessorQueue.remove();
        boolean updated = updatePredecessorsDoneDate(scoreDirector, allocation);
        if (updated) {
            uncheckedSuccessorQueue.addAll(allocation.getSuccessorAllocationList());
        }// w  w w  .  j  a v a  2  s . c  om
    }
}

From source file:org.apache.http2.client.protocol.RequestAuthenticationBase.java

void process(final AuthState authState, final HttpRequest request, final HttpContext context)
        throws HttpException, IOException {
    AuthScheme authScheme = authState.getAuthScheme();
    Credentials creds = authState.getCredentials();
    switch (authState.getState()) {
    case FAILURE:
        return;//from   w w w .  j  a v a2s . c o m
    case SUCCESS:
        ensureAuthScheme(authScheme);
        if (authScheme.isConnectionBased()) {
            return;
        }
        break;
    case CHALLENGED:
        Queue<AuthOption> authOptions = authState.getAuthOptions();
        if (authOptions != null) {
            while (!authOptions.isEmpty()) {
                AuthOption authOption = authOptions.remove();
                authScheme = authOption.getAuthScheme();
                creds = authOption.getCredentials();
                authState.update(authScheme, creds);
                if (this.log.isDebugEnabled()) {
                    this.log.debug("Generating response to an authentication challenge using "
                            + authScheme.getSchemeName() + " scheme");
                }
                try {
                    Header header = authenticate(authScheme, creds, request, context);
                    request.addHeader(header);
                    break;
                } catch (AuthenticationException ex) {
                    if (this.log.isWarnEnabled()) {
                        this.log.warn(authScheme + " authentication error: " + ex.getMessage());
                    }
                }
            }
            return;
        } else {
            ensureAuthScheme(authScheme);
        }
    }
    if (authScheme != null) {
        try {
            Header header = authenticate(authScheme, creds, request, context);
            request.addHeader(header);
        } catch (AuthenticationException ex) {
            if (this.log.isErrorEnabled()) {
                this.log.error(authScheme + " authentication error: " + ex.getMessage());
            }
        }
    }
}

From source file:org.jasig.cas.web.StatisticsController.java

/**
 * Calculates the up time./*from  w  w  w.j  a va  2  s  . co  m*/
 *
 * @param difference the difference
 * @param calculations the calculations
 * @param labels the labels
 * @return the uptime as a string.
 */
protected String calculateUptime(final double difference, final Queue<Integer> calculations,
        final Queue<String> labels) {
    if (calculations.isEmpty()) {
        return "";
    }

    final int value = calculations.remove();
    final double time = Math.floor(difference / value);
    final double newDifference = difference - time * value;
    final String currentLabel = labels.remove();
    final String label = time == 0 || time > 1 ? currentLabel + "s" : currentLabel;

    return Integer.toString((int) time) + " " + label + " "
            + calculateUptime(newDifference, calculations, labels);
}

From source file:org.apache.http.client.protocol.RequestAuthenticationBase.java

void process(final AuthState authState, final HttpRequest request, final HttpContext context) {
    AuthScheme authScheme = authState.getAuthScheme();
    Credentials creds = authState.getCredentials();
    switch (authState.getState()) {
    case FAILURE:
        return;//from  w w  w.j  a v a 2 s  . co m
    case SUCCESS:
        ensureAuthScheme(authScheme);
        if (authScheme.isConnectionBased()) {
            return;
        }
        break;
    case CHALLENGED:
        final Queue<AuthOption> authOptions = authState.getAuthOptions();
        if (authOptions != null) {
            while (!authOptions.isEmpty()) {
                final AuthOption authOption = authOptions.remove();
                authScheme = authOption.getAuthScheme();
                creds = authOption.getCredentials();
                authState.update(authScheme, creds);
                if (this.log.isDebugEnabled()) {
                    this.log.debug("Generating response to an authentication challenge using "
                            + authScheme.getSchemeName() + " scheme");
                }
                try {
                    final Header header = authenticate(authScheme, creds, request, context);
                    request.addHeader(header);
                    break;
                } catch (final AuthenticationException ex) {
                    if (this.log.isWarnEnabled()) {
                        this.log.warn(authScheme + " authentication error: " + ex.getMessage());
                    }
                }
            }
            return;
        } else {
            ensureAuthScheme(authScheme);
        }
    }
    if (authScheme != null) {
        try {
            final Header header = authenticate(authScheme, creds, request, context);
            request.addHeader(header);
        } catch (final AuthenticationException ex) {
            if (this.log.isErrorEnabled()) {
                this.log.error(authScheme + " authentication error: " + ex.getMessage());
            }
        }
    }
}

From source file:org.jasig.cas.web.report.StatisticsController.java

/**
 * Calculates the up time.//from w w w . j a  v  a 2  s.c  o m
 *
 * @param difference the difference
 * @param calculations the calculations
 * @param labels the labels
 * @return the uptime as a string.
 */
protected String calculateUptime(final double difference, final Queue<Integer> calculations,
        final Queue<String> labels) {
    if (calculations.isEmpty()) {
        return "";
    }

    final int value = calculations.remove();
    final double time = Math.floor(difference / value);
    final double newDifference = difference - time * value;
    final String currentLabel = labels.remove();
    final String label = time == 0 || time > 1 ? currentLabel + 's' : currentLabel;

    return Integer.toString((int) time) + ' ' + label + ' '
            + calculateUptime(newDifference, calculations, labels);
}

From source file:org.opentestsystem.airose.docprocessors.ConventionsQualityDocProcessor.java

private ConventionsDocumentQualityHolder evaluateSyntax(Parse parse) {

    double overallPunctScore = 0.0;
    double minSyntaxScore = 1.0;
    double overallSyntaxScore = 0.0;

    double numOfNoms = 0;
    double numLongNominals = 0;
    double syntaxCount = 0;

    int countPunct = 0;

    Queue<Parse> parseTree = new LinkedList<Parse>();
    parseTree.add(parse);/* ww w  .ja  v  a2 s  .c o  m*/
    double rootProb = parse.getProb();

    while (parseTree.size() > 0) {
        Parse p = parseTree.remove();
        if ((p.getChildCount() == 1) && (p.getProb() < 1)) {
            double prob = p.getProb();
            String pType = p.getType();
            if (StringUtils.equals(pType, ",") || StringUtils.equals(pType, ".")
                    || StringUtils.equals(pType, "!") || StringUtils.equals(pType, "?")
                    || StringUtils.equals(pType, ";") || StringUtils.equals(pType, ":")) {
                overallPunctScore += prob;
                countPunct++;
            } else {
                if (!StringUtils.equals(pType, "TOP") && !StringUtils.equals(pType, "S")) {
                    // string s = sentText_;
                    if ((pType.startsWith("NN")))// || p.Type.StartsWith("JJ"))
                    {
                        numOfNoms++;
                    } else {
                        if ((numOfNoms > 2) && (rootProb > -25.5))
                            numLongNominals++;
                        // _numOfNoms = 0;
                    }

                    if (prob < minSyntaxScore)
                        minSyntaxScore = prob;

                    overallSyntaxScore += prob;
                    syntaxCount++;
                }
            }
        }

        Parse[] children = p.getChildren();
        for (Parse pc : children)
            parseTree.add(pc);
    }
    overallPunctScore = (countPunct == 0) ? 0.0 : overallPunctScore / countPunct;

    ConventionsDocumentQualityHolder values = new ConventionsDocumentQualityHolder();
    values.setOverallPunctScore(overallPunctScore);
    values.setMinSyntaxScore(minSyntaxScore);
    values.setOverallSyntaxScore(overallSyntaxScore);
    values.setNumOfNoms(numOfNoms);
    values.setNumLongNominals(numLongNominals);
    values.setSyntaxCount(syntaxCount);

    return values;
}

From source file:org.bigwiv.blastgraph.SubSetCluster.java

@Override
public Set<Set<V>> transform(UndirectedGraph<V, E> theGraph) {
    Set<Set<V>> subSets = new LinkedHashSet<Set<V>>();

    if (theGraph.getVertices().isEmpty())
        return subSets;

    isVisited = new HashMap<V, Number>();
    for (V v : theGraph.getVertices()) {
        isVisited.put(v, 0);//w w w. j av  a 2 s.  c o m
    }

    for (V v : theGraph.getVertices()) {
        if (isVisited.get(v).intValue() == 0) {
            Set<V> subSet = new HashSet<V>();
            subSet.add(v);

            //            Stack<V> toVisitStack = new Stack<V>();//stack for DFS
            //            toVisitStack.push(v);
            //
            //            while (toVisitStack.size() != 0) {
            //               V curV = toVisitStack.pop();
            //               isVisited.put(curV, 1);
            //               for (V w : theGraph.getNeighbors(curV)) {
            //                  if (isVisited.get(w).intValue() == 0) // w hasn't yet
            //                                                // been visited
            //                  {
            //                     subSet.add(w);
            //                     toVisitStack.push(w);
            //                  }
            //               }
            //
            //            }

            Queue<V> toVisitQueue = new LinkedList<V>();//Queue for BFS
            toVisitQueue.add(v);

            while (toVisitQueue.size() != 0) {
                V curV = toVisitQueue.remove();
                isVisited.put(curV, 1);
                for (V w : theGraph.getNeighbors(curV)) {
                    if (isVisited.get(w).intValue() == 0) // w hasn't yet
                    // been visited
                    {
                        subSet.add(w);
                        toVisitQueue.add(w);
                    }
                }

            }

            subSets.add(subSet);
        }
    }
    return subSets;
}

From source file:com.android.pwdhashandroid.pwdhash.PasswordHasher.java

private char[] rotate(char[] arr, int amount) {
    //      Log.d(tag, amount + "x:\t");

    Queue<Character> q = CreateQueue(arr);

    while (amount-- != 0) {
        q.add(q.remove());
        Log.d(tag, q.toString());/*from   www. ja  va2  s .c  o m*/
    }

    Character[] chars = (Character[]) q.toArray(new Character[0]);
    return CharacterToCharArray(chars);

    //      return new char[10]; 

    //      CSQueue q = new CSQueue(arr);
    //      while (amount-- != 0) {
    //         q.put(q.get());
    //         Log.d(tag, new String(q.toArray()));
    //      }
    //
    //      return q.toArray();
}

From source file:info.magnolia.test.mock.jcr.MockSession.java

@Override
public Node getNodeByIdentifier(String id) throws RepositoryException {
    Queue<Node> queue = new LinkedList<Node>();
    queue.add(rootNode);//from ww w.  ja  va 2s  .  co  m
    while (!queue.isEmpty()) {
        Node node = queue.remove();
        // null safe equals check
        if (StringUtils.equals(id, node.getIdentifier()))
            return node;
        // add children to stack
        NodeIterator iterator = node.getNodes();
        while (iterator.hasNext())
            queue.add(iterator.nextNode());

    }
    throw new ItemNotFoundException("No node found with identifier/uuid [" + id + "]");
}

From source file:org.kuali.kfs.module.purap.document.validation.impl.PurchasingAccountsPayableObjectCodeOverrideBranchingValidation.java

/**
 * Recursively refreshes a property given by the queue path
 * @param bo the business object to refresh
 * @param path the path, in Queue form, of properties to refresh
 *///from ww  w  . j  a  va 2  s  .c o  m
protected void refreshByQueue(PersistableBusinessObject bo, Queue<String> path) {
    if (path.size() > 1) { // we know that the last thing on our list is a code. why refresh that?
        String currentProperty = path.remove();
        bo.refreshReferenceObject(currentProperty);
        PersistableBusinessObject childBO = (PersistableBusinessObject) ObjectUtils.getPropertyValue(bo,
                currentProperty);
        if (!ObjectUtils.isNull(childBO)) {
            refreshByQueue(childBO, path);
        }
    }
}