Example usage for com.google.common.collect Maps filterValues

List of usage examples for com.google.common.collect Maps filterValues

Introduction

In this page you can find the example usage for com.google.common.collect Maps filterValues.

Prototype

@CheckReturnValue
public static <K, V> BiMap<K, V> filterValues(BiMap<K, V> unfiltered,
        final Predicate<? super V> valuePredicate) 

Source Link

Document

Returns a bimap containing the mappings in unfiltered whose values satisfy a predicate.

Usage

From source file:com.google.devtools.build.lib.skyframe.SkyframeExecutor.java

@SuppressWarnings({ "unchecked", "rawtypes" })
Map<SkyKey, ActionLookupValue> getActionLookupValueMap() {
    return (Map) Maps.filterValues(memoizingEvaluator.getDoneValues(),
            Predicates.instanceOf(ActionLookupValue.class));
}

From source file:com.pinterest.pinlater.backends.redis.PinLaterRedisBackend.java

@VisibleForTesting
public static Map.Entry<String, RedisPools> getRandomShard(final ImmutableMap<String, RedisPools> shardMap,
        final HealthChecker healthChecker, final Random random, final boolean healthyOnly) {
    Map<String, RedisPools> filteredShardMap;
    if (healthyOnly) {
        filteredShardMap = Maps.filterValues(shardMap, new Predicate<RedisPools>() {
            @Override// w  w  w  .j  a  va2 s  .com
            public boolean apply(@Nullable RedisPools redisPools) {
                return healthChecker.isServerLive(redisPools.getHost(), redisPools.getPort());
            }
        });
        if (filteredShardMap.size() == 0) {
            return null;
        }
    } else {
        filteredShardMap = shardMap;
    }
    return (Map.Entry) filteredShardMap.entrySet().toArray()[random.nextInt(filteredShardMap.size())];
}

From source file:com.oodrive.nuage.dtx.DtxManager.java

/**
 * Gets a map of target nodes and last tx IDs for synchronization.
 * //  w  w w.  jav a2 s . c o m
 * @param resId
 *            the target resource manager's ID
 * @param lowerLimit
 *            the lower limit above which to return last transaction IDs
 * @return a possibly empty {@link Map} with node IDs mapped to last complete transaction IDs
 */
final Map<DtxNode, Long> getClusterMapInfo(final UUID resId, final Long lowerLimit) {
    try {
        mapLock.readLock().lockInterruptibly();
    } catch (final InterruptedException e) {
        throw new IllegalStateException("Interrupted on waiting for lock", e);
    }
    try {
        final Map<DtxNode, Long> resUpdateMap = Maps.filterValues(clusterUpdateMap.row(resId),
                Range.openClosed(lowerLimit, Long.valueOf(Long.MAX_VALUE)));
        // returns a defensive copy to avoid any concurrent modification exceptions
        return new HashMap<DtxNode, Long>(resUpdateMap);
    } finally {
        mapLock.readLock().unlock();
    }
}