Example usage for com.google.common.collect Multimaps filterKeys

List of usage examples for com.google.common.collect Multimaps filterKeys

Introduction

In this page you can find the example usage for com.google.common.collect Multimaps filterKeys.

Prototype

@CheckReturnValue
public static <K, V> ListMultimap<K, V> filterKeys(ListMultimap<K, V> unfiltered,
        final Predicate<? super K> keyPredicate) 

Source Link

Document

Returns a multimap containing the mappings in unfiltered whose keys satisfy a predicate.

Usage

From source file:org.jclouds.digitalocean2.exceptions.DigitalOcean2RateLimitExceededException.java

private static Multimap<String, String> rateLimitHeaders(HttpResponse response) {
    return Multimaps.filterKeys(response.getHeaders(), new Predicate<String>() {
        @Override//from  ww  w .j av  a  2s  .co m
        public boolean apply(String input) {
            return input.startsWith(RATE_LIMIT_HEADER_PREFIX);
        }
    });
}

From source file:fr.ippon.wip.http.request.AbstractRequestBuilder.java

/**
 * Copy parameters and exclude those prefixed by
 * WIPortlet.WIP_REQUEST_PARAMS_PREFIX_KEY
 * //from   www.j  av  a2  s  .  c  om
 * @param parameterMap
 */
private void copyParameters(Multimap<String, String> parameterMap) {
    if (parameterMap == null || parameterMap.size() == 0)
        return;

    this.parameterMap = Multimaps.filterKeys(parameterMap, filterMapPredicate);
}

From source file:org.pentaho.di.trans.dataservice.optimization.paramgen.SourceLineageMap.java

public SourceLineageMap filterKeys(Predicate<String> predicate) {
    return new SourceLineageMap(Multimaps.filterKeys(storage, predicate));
}

From source file:name.marcelomorales.siqisiqi.configuration.ConfigProvider.java

public Iterable<String> possibleConfigFilePositions() {

    // Filter out when APPDATA or HOME or anything else is missing
    final Multimap<String, String> applicableTemplates = Multimaps.filterKeys(TEMPLATES,
            new Predicate<String>() {

                @Override/* w  w w  .ja  v a2s .co  m*/
                public boolean apply(@Nullable String input) {
                    return Strings.isNullOrEmpty(input) || !Strings.isNullOrEmpty(System.getenv(input));
                }
            });

    final Iterable<String> transform = Iterables.transform(applicableTemplates.entries(),
            new Function<Map.Entry<String, String>, String>() {

                @Override
                public String apply(Map.Entry<String, String> input) {
                    return MessageFormat.format(input.getValue(), System.getenv(input.getKey()), vendorName,
                            applicationName);
                }
            });

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Will check all these paths in order {}", Iterables.toString(transform));
    }

    return transform;
}

From source file:co.cask.cdap.data.tools.HBaseQueueDebugger.java

/**
 * Only works for {@link co.cask.cdap.data2.transaction.queue.hbase.ShardedHBaseQueueStrategy}.
 *///from   w  w w .  ja  va 2 s. c  o  m
public QueueStatistics scanQueue(final QueueName queueName, @Nullable Long consumerGroupId) throws Exception {
    HBaseConsumerStateStore stateStore;
    try {
        stateStore = queueAdmin.getConsumerStateStore(queueName);
    } catch (IllegalStateException e) {
        throw new NotFoundException(queueName);
    }

    TransactionExecutor txExecutor = Transactions.createTransactionExecutor(txExecutorFactory, stateStore);
    Multimap<Long, QueueBarrier> barriers = txExecutor
            .execute(new TransactionExecutor.Function<HBaseConsumerStateStore, Multimap<Long, QueueBarrier>>() {
                @Override
                public Multimap<Long, QueueBarrier> apply(HBaseConsumerStateStore input) throws Exception {
                    return input.getAllBarriers();
                }
            }, stateStore);
    System.out.printf("Got %d barriers\n", barriers.size());

    QueueStatistics stats = new QueueStatistics();

    if (consumerGroupId != null) {
        barriers = Multimaps.filterKeys(barriers, Predicates.equalTo(consumerGroupId));
    }

    for (Map.Entry<Long, Collection<QueueBarrier>> entry : barriers.asMap().entrySet()) {
        long groupId = entry.getKey();
        Collection<QueueBarrier> groupBarriers = entry.getValue();

        System.out.printf("Scanning barriers for group %d\n", groupId);

        int currentSection = 1;
        PeekingIterator<QueueBarrier> barrierIterator = Iterators.peekingIterator(groupBarriers.iterator());
        while (barrierIterator.hasNext()) {
            QueueBarrier start = barrierIterator.next();
            QueueBarrier end = barrierIterator.hasNext() ? barrierIterator.peek() : null;

            System.out.printf("Scanning section %d/%d...\n", currentSection, groupBarriers.size());
            scanQueue(txExecutor, stateStore, queueName, start, end, stats);
            System.out.printf("Current results: %s\n", stats.getReport());
            currentSection++;
        }
        System.out.println("Scanning complete");
    }

    System.out.printf("Total results: %s\n", stats.getReport());
    return stats;
}

From source file:dagger.internal.codegen.ComponentProcessingStep.java

private ImmutableSet<Element> getElementsFromAnnotations(
        final SetMultimap<Class<? extends Annotation>, Element> elementsByAnnotation,
        ImmutableSet<? extends Class<? extends Annotation>> annotations) {
    return ImmutableSet.copyOf(Multimaps.filterKeys(elementsByAnnotation, Predicates.in(annotations)).values());
}

From source file:com.opengamma.integration.tool.portfolio.xml.TradePositionResolver.java

private Multimap<String, String> determineDuplicatedTrades() {
    return Multimaps.filterKeys(_invertedPositions, new Predicate<String>() {
        @Override/* ww w  . j a  v a 2  s  .  c  o  m*/
        public boolean apply(String s) {
            return _invertedPositions.get(s).size() > 1;
        }
    });
}