Example usage for java.util Queue isEmpty

List of usage examples for java.util Queue isEmpty

Introduction

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

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this collection contains no elements.

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());
        }//from  w  ww .j  ava 2  s .c  o m
    }
}

From source file:org.ros.internal.message.new_style.ServiceLoader.java

private void findMessages(File searchPath) {
    CharsetDecoder decoder = Charset.forName("US-ASCII").newDecoder();
    FindServicesFilter filter = new FindServicesFilter();
    Queue<File> childPaths = Lists.newLinkedList();
    childPaths.addAll(listPathEntries(searchPath, filter));
    while (!childPaths.isEmpty()) {
        File servicePath = childPaths.poll();
        if (servicePath.isDirectory()) {
            childPaths.addAll(listPathEntries(servicePath, filter));
        } else {//from w w w.j  a  v  a2  s  . c o m
            try {
                addServiceDefinitionFromPaths(searchPath, servicePath, decoder);
            } catch (IOException e) {
                log.error("Failed to read service: " + servicePath.getAbsolutePath(), e);
            }
        }
    }
}

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

/**
 * Calculates the up time.//from w  w  w.j  av  a2  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.ros.internal.message.new_style.MessageLoader.java

private void findMessages(File searchPath) {
    CharsetDecoder decoder = Charset.forName("US-ASCII").newDecoder();
    FindMessagesFilter filter = new FindMessagesFilter();
    Queue<File> childPaths = Lists.newLinkedList();
    childPaths.addAll(listPathEntries(searchPath, filter));
    while (!childPaths.isEmpty()) {
        File messagePath = childPaths.poll();
        if (messagePath.isDirectory()) {
            childPaths.addAll(listPathEntries(messagePath, filter));
        } else {/*from   www  . j  a  v  a  2 s .c  o m*/
            try {
                addMessageDefinitionFromPaths(searchPath, messagePath, decoder);
            } catch (IOException e) {
                log.error("Failed to read message: " + messagePath.getAbsolutePath(), e);
            }
        }
    }
}

From source file:org.jboss.qa.phaser.Executor.java

public void execute() throws Exception {
    final List<ErrorReport> throwAtEnd = new LinkedList<>();
    invokeJobMethods(BeforeJob.class);

    final Queue<ExecutionNode> nodeQueue = new LinkedList<>(roots);
    boolean finalizeState = false;
    while (!nodeQueue.isEmpty()) {
        final ExecutionNode node = nodeQueue.poll();

        final ExecutionError err = node.execute(finalizeState);

        if (err != null) {
            final ExceptionHandling eh = err.getExceptionHandling();
            final ErrorReport errorReport = new ErrorReport("Exception thrown by phase execution:",
                    err.getThrowable());
            switch (eh.getReport()) {
            case THROW_AT_END:
                throwAtEnd.add(errorReport);
                break;
            case LOG:
                ErrorReporter.report(errorReport);
                break;
            default:
                log.debug("Exception by phase execution, continue.");
            }/*  www.  j  a  va2 s  .co  m*/

            if (eh.getExecution() == ExceptionHandling.Execution.IMMEDIATELY_STOP) {
                break;
            } else if (eh.getExecution() == ExceptionHandling.Execution.FINALIZE) {
                finalizeState = true;
            }
        }
        nodeQueue.addAll(node.getChildNodes());
    }

    invokeJobMethods(AfterJob.class);
    ErrorReporter.finalErrorReport(throwAtEnd);
}

From source file:geotag.example.sbickt.SbicktAPITest.java

@Test
public void testDeleteGeoTag() {
    Queue<GeoTag> listOfGeoTags = new LinkedList<GeoTag>();

    try {//from  www .jav a2  s .  c om
        listOfGeoTags = SbicktAPI.getGeoTags(new Point3D(2.548, 2.548, 0));

        while (!listOfGeoTags.isEmpty()) {
            SbicktAPI.deleteGeoTag(listOfGeoTags.poll().getId());
        }
    } catch (Exception e) {
        fail(e.toString());
    }
}

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

/**
 * Calculates the up time.//from   w  w w . j av 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.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 ww .  j  a v a 2  s.  c  om*/
    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.apache.hadoop.hbase.chaos.actions.RollingBatchRestartRsAction.java

@Override
public void perform() throws Exception {
    LOG.info(String.format("Performing action: Rolling batch restarting %d%% of region servers",
            (int) (ratio * 100)));
    List<ServerName> selectedServers = PolicyBasedChaosMonkey.selectRandomItems(getCurrentServers(), ratio);

    Queue<ServerName> serversToBeKilled = new LinkedList<ServerName>(selectedServers);
    Queue<ServerName> deadServers = new LinkedList<ServerName>();

    ////  w  w w  . j  a v  a  2 s. c o  m
    while (!serversToBeKilled.isEmpty() || !deadServers.isEmpty()) {
        boolean action = true; //action true = kill server, false = start server

        if (serversToBeKilled.isEmpty() || deadServers.isEmpty()) {
            action = deadServers.isEmpty();
        } else {
            action = RandomUtils.nextBoolean();
        }

        if (action) {
            ServerName server = serversToBeKilled.remove();
            try {
                killRs(server);
            } catch (org.apache.hadoop.util.Shell.ExitCodeException e) {
                // We've seen this in test runs where we timeout but the kill went through. HBASE-9743
                // So, add to deadServers even if exception so the start gets called.
                LOG.info("Problem killing but presume successful; code=" + e.getExitCode(), e);
            }
            deadServers.add(server);
        } else {
            try {
                ServerName server = deadServers.remove();
                startRs(server);
            } catch (org.apache.hadoop.util.Shell.ExitCodeException e) {
                // The start may fail but better to just keep going though we may lose server.
                //
                LOG.info("Problem starting, will retry; code=" + e.getExitCode(), e);
            }
        }

        sleep(RandomUtils.nextInt((int) sleepTime));
    }
}

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 .  ja v a  2  s  . c  om
    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());
            }
        }
    }
}