Example usage for com.google.common.collect Iterables frequency

List of usage examples for com.google.common.collect Iterables frequency

Introduction

In this page you can find the example usage for com.google.common.collect Iterables frequency.

Prototype

public static int frequency(Iterable<?> iterable, @Nullable Object element) 

Source Link

Document

Returns the number of elements in the specified iterable that equal the specified object.

Usage

From source file:com.palantir.common.collect.IterableView.java

public int frequency(@Nullable Object element) {
    return Iterables.frequency(delegate(), element);
}

From source file:com.github.nethad.clustermeister.provisioning.ec2.commands.AbstractAmazonExecutableCommand.java

/**
 * Wait for a list of futures to complete.
 * //  w w w  . j  av a  2s. c  o  m
 * <p>
 * The futures are considered as failed when they return null or fail to return.
 * </p>
 * @param futures the futures to wait for.
 * @param interruptedMessage 
 *      Log this message when the thread waiting for the futures to return 
 *      is interrupted. The exception's stack trace is appended to this message.
 * @param executionExceptionMessage 
 *      Log this message when the thread waiting for the futures throws an 
 *      exception while waiting. The exception's stack trace is appended to 
 *      this message.
 * @param unsuccessfulFuturesMessage 
 *      Log this message when at least one future failed (or returned null).
 *      Can be a formatted string where '{}' is replaced with the number of 
 *      failed futures.
 * 
 */
protected void waitForFuturesToComplete(List<ListenableFuture<? extends Object>> futures,
        String interruptedMessage, String executionExceptionMessage, String unsuccessfulFuturesMessage) {
    try {
        List<Object> startedNodes = Futures.successfulAsList(futures).get();
        int failedNodes = Iterables.frequency(startedNodes, null);
        if (failedNodes > 0) {
            logger.warn(unsuccessfulFuturesMessage, failedNodes);
        }
    } catch (InterruptedException ex) {
        logger.warn(interruptedMessage, ex);
    } catch (ExecutionException ex) {
        logger.warn(executionExceptionMessage, ex);
    }
}

From source file:org.opendaylight.yangtools.yang.parser.repo.SharedSchemaContextFactory.java

/**
 * @return set (preserving ordering) from the input collection
 *///from  w  w w  .  j av  a  2  s . c  om
private static List<SourceIdentifier> deDuplicateSources(final Collection<SourceIdentifier> requiredSources) {
    final Set<SourceIdentifier> uniqueSourceIdentifiers = new LinkedHashSet<>(requiredSources);
    if (uniqueSourceIdentifiers.size() == requiredSources.size()) {
        // Can potentially reuse input
        return ImmutableList.copyOf(requiredSources);
    }

    LOG.warn("Duplicate sources requested for schema context, removed duplicate sources: {}", Collections2
            .filter(uniqueSourceIdentifiers, input -> Iterables.frequency(requiredSources, input) > 1));
    return ImmutableList.copyOf(uniqueSourceIdentifiers);
}

From source file:org.onos.yangtools.yang.parser.repo.SharedSchemaContextFactory.java

/**
 * @return set (preserving ordering) from the input collection
 *///  w  w  w . j  a va  2 s .  c o  m
private List<SourceIdentifier> deDuplicateSources(final Collection<SourceIdentifier> requiredSources) {
    final Set<SourceIdentifier> uniqueSourceIdentifiers = Collections
            .unmodifiableSet(Sets.newLinkedHashSet(requiredSources));
    if (uniqueSourceIdentifiers.size() != requiredSources.size()) {
        LOG.warn("Duplicate sources requested for schema context, removed duplicate sources: {}",
                Collections2.filter(uniqueSourceIdentifiers, new Predicate<SourceIdentifier>() {
                    @Override
                    public boolean apply(@Nullable final SourceIdentifier input) {
                        return Iterables.frequency(requiredSources, input) > 1;
                    }
                }));
    }
    return Lists.newArrayList(uniqueSourceIdentifiers);
}