Example usage for com.google.common.collect ImmutableList isEmpty

List of usage examples for com.google.common.collect ImmutableList isEmpty

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableList isEmpty.

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this list contains no elements.

Usage

From source file:org.zanata.rest.client.GlossaryClient.java

public Response downloadFile(String fileType, ImmutableList<String> transLang, String qualifiedName) {
    if (transLang != null && !transLang.isEmpty()) {
        return webResource().path("file").queryParam("fileType", fileType)
                .queryParam("locales", Joiner.on(",").join(transLang))
                .queryParam("qualifiedName", qualifiedName).request(MediaType.APPLICATION_OCTET_STREAM_TYPE)
                .get();// ww w.  java 2 s.c  o  m
    }
    return webResource().path("file").queryParam("fileType", fileType)
            .queryParam("qualifiedName", qualifiedName).request(MediaType.APPLICATION_OCTET_STREAM_TYPE).get();
}

From source file:com.facebook.buck.rules.coercer.VersionMatchedCollection.java

/**
 * @return the only item that matches the given version map, or throw.
 *///from   www .j  a v a  2s. c om
public T getOnlyMatchingValue(ImmutableMap<BuildTarget, Version> selected) {
    ImmutableList<T> matching = getMatchingValues(selected);
    Preconditions.checkState(!matching.isEmpty(), "no matches for %s found", selected);
    Preconditions.checkState(matching.size() < 2, "multiple matches for %s found: %s", selected, matching);
    return matching.get(0);
}

From source file:eu.redzoo.article.javaworld.stability.service.payment.SyncPaymentService.java

@Path("paymentmethods")
@GET//from  ww w . j  a  va  2 s  .c o  m
@Produces(MediaType.APPLICATION_JSON)
public ImmutableSet<PaymentMethod> getPaymentMethods(@QueryParam("addr") String address) {
    Score score = NEUTRAL;
    try {
        ImmutableList<Payment> pmts = paymentDao.getPayments(address, 50);
        score = pmts.isEmpty()
                ? client.target(creditScoreURI).queryParam("addr", address).request().get(Score.class)
                : (pmts.stream().filter(pmt -> pmt.isDelayed()).count() >= 1) ? NEGATIVE : POSITIVE;
    } catch (RuntimeException rt) {
        LOG.fine("error occurred by calculating score. Fallback to " + score + " " + rt.toString());
    }

    return SCORE_TO_PAYMENTMETHOD.apply(score);
}

From source file:com.facebook.buck.rage.DefaultExtraInfoCollector.java

@Override
public Optional<ExtraInfoResult> run() throws IOException, InterruptedException, ExtraInfoExecutionException {
    ImmutableList<String> extraInfoCommand = rageConfig.getExtraInfoCommand();
    if (extraInfoCommand.isEmpty()) {
        return Optional.empty();
    }//from   ww w  .j a  v  a  2  s  . c o  m

    // TODO(ruibm): Potentially add the initial static launch dir here as well as any launch-*
    // logs buck is currently generating.
    Path rageExtraFilesDir = projectFilesystem.getBuckPaths().getLogDir().resolve("rage-extra-info");
    projectFilesystem.deleteRecursivelyIfExists(rageExtraFilesDir);
    projectFilesystem.mkdirs(rageExtraFilesDir);

    String extraInfoCommandOutput = runCommandAndGetStdout(
            Iterables.concat(extraInfoCommand,
                    ImmutableList.of("--output-dir", projectFilesystem.resolve(rageExtraFilesDir).toString())),
            projectFilesystem, processExecutor);

    ImmutableSet<Path> rageExtraFiles = projectFilesystem.getFilesUnderPath(rageExtraFilesDir);

    return Optional.of(
            ExtraInfoResult.builder().setExtraFiles(rageExtraFiles).setOutput(extraInfoCommandOutput).build());
}

From source file:com.facebook.buck.doctor.DefaultExtraInfoCollector.java

@Override
public Optional<ExtraInfoResult> run() throws IOException, InterruptedException, ExtraInfoExecutionException {
    ImmutableList<String> extraInfoCommand = doctorConfig.getExtraInfoCommand();
    if (extraInfoCommand.isEmpty()) {
        return Optional.empty();
    }//from w  w  w. j  a  v  a 2  s  . c o  m

    // TODO(ruibm): Potentially add the initial static launch dir here as well as any launch-*
    // logs buck is currently generating.
    Path rageExtraFilesDir = projectFilesystem.getBuckPaths().getLogDir().resolve("rage-extra-info");
    projectFilesystem.deleteRecursivelyIfExists(rageExtraFilesDir);
    projectFilesystem.mkdirs(rageExtraFilesDir);

    String extraInfoCommandOutput = runCommandAndGetStdout(
            Iterables.concat(extraInfoCommand,
                    ImmutableList.of("--output-dir", projectFilesystem.resolve(rageExtraFilesDir).toString())),
            projectFilesystem, processExecutor);

    ImmutableSet<Path> rageExtraFiles = projectFilesystem.getFilesUnderPath(rageExtraFilesDir);

    return Optional.of(
            ExtraInfoResult.builder().setExtraFiles(rageExtraFiles).setOutput(extraInfoCommandOutput).build());
}

From source file:org.apache.james.transport.mailets.ContactExtractor.java

private boolean hasRecipient(ImmutableList<String> allRecipients) {
    return !allRecipients.isEmpty();
}

From source file:com.forerunnergames.tools.common.Strings.java

/**
 * Converts a collection of list elements to a string list, separated by separator, in case letterCase.
 *
 * @param <T>/*w  w w.j  a v a 2  s .  co  m*/
 *          The type of the list elements.
 * @param listElements
 *          The collection of list elements to convert, must not be null, must not contain any null elements.
 * @param separator
 *          The separator that should be added between list elements, must not be null.
 * @param letterCase
 *          The desired letter case of the list elements, must not be null, choose LetterCase.NONE to leave the list
 *          elements as-is.
 * @param hasAnd
 *          Whether or not to insert the word 'and ' between the last two elements in the list, one space after the
 *          last separator.
 *
 * @return A string list of listElements, separated by separator, in case letterCase, with an optional 'and '
 *         occurring between the last two elements of the list.
 */
public static <T> String toStringList(final Collection<T> listElements, final String separator,
        final LetterCase letterCase, final boolean hasAnd) {
    Arguments.checkIsNotNull(listElements, "listElements");
    Arguments.checkHasNoNullElements(listElements, "listElements");
    Arguments.checkIsNotNull(separator, "separator");
    Arguments.checkIsNotNull(letterCase, "letterCase");

    final ImmutableList.Builder<T> printableListElementsBuilder = ImmutableList.builder();

    for (final T element : listElements) {
        if (isPrintable(element.toString()))
            printableListElementsBuilder.add(element);
    }

    final ImmutableList<T> printableListElements = printableListElementsBuilder.build();

    // Handle the first three special cases
    if (printableListElements.isEmpty()) {
        return "";
    } else if (printableListElements.size() == 1) {
        return toCase(Iterables.getOnlyElement(printableListElements).toString(), letterCase);
    } else if (printableListElements.size() == 2) {
        final Iterator<T> iterator = printableListElements.iterator();

        // Here, if the separator is a comma, for example, it's either:
        // "item1 and item2" or "item1,item2" (if no "and" is desired)
        // because "item1, and item2" doesn't make sense grammatically, which is
        // what would happen if we didn't treat this as a special case
        return toCase(iterator.next().toString() + (hasAnd ? " and " : separator) + iterator.next().toString(),
                letterCase);
    }

    final StringBuilder s = new StringBuilder();

    for (final T element : printableListElements) {
        final String elementString = toCase(element.toString(), letterCase);

        s.append(elementString).append(separator);
    }

    try {
        // Delete the extra comma at the end of the last element in the list.
        s.delete(s.length() - separator.length(), s.length());

        if (hasAnd && s.lastIndexOf(separator) >= 0) {
            // Insert the word 'and' between the last two elements in the list,
            // after the last comma.
            s.insert(s.lastIndexOf(separator) + 1, "and ");
        }
    } catch (final StringIndexOutOfBoundsException ignored) {
    }

    return s.toString();
}

From source file:org.gradle.plugin.use.internal.PluginResolverFactory.java

/**
 * Returns the default PluginResolvers used by Gradle.
 * <p>/* w ww.j  av  a 2 s  .  com*/
 * The plugins will be searched in a chain from the first to the last until a plugin is found.
 * So, order matters.
 * <p>
 * <ol>
 *     <li>{@link NoopPluginResolver} - Only used in tests.</li>
 *     <li>{@link CorePluginResolver} - distributed with Gradle</li>
 *     <li>{@link InjectedClasspathPluginResolver} - from a TestKit test's ClassPath</li>
 *     <li>Resolvers based on the entries of the `pluginRepositories` block</li>
 *     <li>{@link PluginResolutionServiceResolver} - from Gradle Plugin Portal if no `pluginRepositories` were defined</li>
 * </ol>
 * <p>
 * This order is optimized for both performance and to allow resolvers earlier in the order
 * to mask plugins which would have been found later in the order.
 */
private void addDefaultResolvers(List<PluginResolver> resolvers) {
    resolvers.add(new NoopPluginResolver(pluginRegistry));
    resolvers.add(new CorePluginResolver(documentationRegistry, pluginRegistry));

    if (!injectedClasspathPluginResolver.isClasspathEmpty()) {
        resolvers.add(injectedClasspathPluginResolver);
    }

    ImmutableList<PluginRepository> pluginRepositories = getPluginRepositories();
    if (pluginRepositories.isEmpty()) {
        resolvers.add(pluginResolutionServiceResolver);
    } else {
        addPluginRepositoryResolvers(resolvers, pluginRepositories);
    }
}

From source file:com.google.errorprone.bugpatterns.threadsafety.AbstractLockMethodChecker.java

@Override
public Description matchMethod(MethodTree tree, final VisitorState state) {

    ImmutableList<String> lockExpressions = getLockExpressions(tree);
    if (lockExpressions.isEmpty()) {
        return Description.NO_MATCH;
    }//from   w w w . j  a v a 2  s. co  m

    Optional<ImmutableSet<GuardedByExpression>> expected = parseLockExpressions(lockExpressions, tree, state);
    if (!expected.isPresent()) {
        return buildDescription(tree).setMessage("Could not resolve lock expression.").build();
    }

    Set<GuardedByExpression> unwanted = getUnwanted(tree, state);
    SetView<GuardedByExpression> mishandled = Sets.intersection(expected.get(), unwanted);
    if (!mishandled.isEmpty()) {
        String message = buildMessage(formatLockString(mishandled));
        return buildDescription(tree).setMessage(message).build();
    }

    Set<GuardedByExpression> actual = getActual(tree, state);
    SetView<GuardedByExpression> unhandled = Sets.difference(expected.get(), actual);
    if (!unhandled.isEmpty()) {
        String message = buildMessage(formatLockString(unhandled));
        return buildDescription(tree).setMessage(message).build();
    }

    return Description.NO_MATCH;
}

From source file:org.cyclop.service.importer.intern.ParallelQueryImporter.java

@Override
void execImport(Scanner scanner, ResultWriter resultWriter, StatsCollector status, ImportConfig iconfig) {
    ImmutableList<CqlQuery> queries = parse(scanner);
    if (queries.isEmpty()) {
        LOG.debug("No data to import");
        return;/*from  w  ww  .  j ava 2 s  .  c o m*/
    }

    QueryHistory history = historyService.read();

    List<Future<Void>> futures = startWorkers(queries, resultWriter, status, iconfig, history);
    waitForImport(futures);

    if (iconfig.isUpdateHistory()) {
        historyService.store(history);
    }
}