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.skyframe.InMemoryGraphImpl.java

@Override
public Map<SkyKey, SkyValue> getDoneValues() {
    return Collections.unmodifiableMap(
            Maps.filterValues(Maps.transformValues(nodeMap, new Function<InMemoryNodeEntry, SkyValue>() {
                @Override// w w w . ja  v a  2 s . c  o  m
                public SkyValue apply(InMemoryNodeEntry entry) {
                    return entry.isDone() ? entry.getValue() : null;
                }
            }), Predicates.notNull()));
}

From source file:com.google.devtools.build.skyframe.InMemoryGraph.java

/**
 * Returns a read-only live view of the done values in the graph. Dirty, changed, and error values
 * are not present in the returned map/*from w w  w.  ja v a 2  s .com*/
 */
Map<SkyKey, SkyValue> getDoneValues() {
    return Collections.unmodifiableMap(
            Maps.filterValues(Maps.transformValues(nodeMap, new Function<NodeEntry, SkyValue>() {
                @Override
                public SkyValue apply(NodeEntry entry) {
                    return entry.isDone() ? entry.getValue() : null;
                }
            }), Predicates.notNull()));
}

From source file:org.jage.communication.common.cache.AddressSet.java

@Override
public void init() {
    // Evictor//from   w  ww . j  av a  2s  .c  om
    service = Executors.newScheduledThreadPool(1);
    service.scheduleWithFixedDelay(new Runnable() {

        @Override
        public void run() {
            synchronized (addresses) {
                Map<INodeAddress, Long> expired = Maps.filterValues(addresses,
                        Ranges.upTo(System.currentTimeMillis(), BoundType.CLOSED));
                for (INodeAddress address : expired.keySet()) {
                    log.debug("Node {} is no longer my neighbour.", address);
                    addresses.remove(address);
                }
                if (!expired.isEmpty()) {
                    informOfCacheChange();
                }
            }
        }
    }, cacheEvictionPeriod, cacheEvictionPeriod, TimeUnit.SECONDS);
}

From source file:org.excalibur.core.compute.monitoring.domain.net.NetworkInterfaces.java

/**
 * Removes a {@link NetworkInterface} that has a given id.
 * /*from  www. j  a  v a 2 s .c  o  m*/
 * @param id
 *            The id of the {@link NetworkInterface} that must be removed.
 * @return the {@link NetworkInterface} removed.
 */
public NetworkInterface remove(String id) {
    NetworkInterface removed = this.interfaces_.remove(id);

    if (primary != null && primary.equals(removed)) {
        Map<String, NetworkInterface> primaries = Maps.filterValues(this.interfaces_,
                new Predicate<NetworkInterface>() {
                    @Override
                    public boolean apply(NetworkInterface input) {
                        return input.isPrimary() || input.isActive();
                    }
                });
        this.primary = (primaries.isEmpty()) ? null : primaries.values().iterator().next();
    }
    return removed;
}

From source file:dagger.android.processor.DuplicateAndroidInjectorsChecker.java

private void validateMapKeyUniqueness(Binding dispatchingAndroidInjector, BindingGraph graph,
        DiagnosticReporter diagnosticReporter) {
    ImmutableSet<Binding> injectorFactories = injectorMapDependencies(dispatchingAndroidInjector, graph)
            .flatMap(injectorFactoryMap -> graph.requestedBindings(injectorFactoryMap).stream())
            .collect(collectingAndThen(toList(), ImmutableSet::copyOf));

    ImmutableListMultimap.Builder<String, Binding> mapKeyIndex = ImmutableListMultimap.builder();
    for (Binding injectorFactory : injectorFactories) {
        AnnotationMirror mapKey = mapKey(injectorFactory).get();
        Optional<String> injectedType = injectedTypeFromMapKey(mapKey);
        if (injectedType.isPresent()) {
            mapKeyIndex.put(injectedType.get(), injectorFactory);
        } else {//from  w  ww. j  a va 2 s .  co  m
            diagnosticReporter.reportBinding(ERROR, injectorFactory, "Unrecognized class: %s", mapKey);
        }
    }

    Map<String, List<Binding>> duplicates = Maps.filterValues(Multimaps.asMap(mapKeyIndex.build()),
            bindings -> bindings.size() > 1);
    if (!duplicates.isEmpty()) {
        StringBuilder errorMessage = new StringBuilder(
                "Multiple injector factories bound for the same type:\n");
        Formatter formatter = new Formatter(errorMessage);
        duplicates.forEach((injectedType, duplicateFactories) -> {
            formatter.format("  %s:\n", injectedType);
            duplicateFactories.forEach(duplicate -> formatter.format("    %s\n", duplicate));
        });
        diagnosticReporter.reportBinding(ERROR, dispatchingAndroidInjector, errorMessage.toString());
    }
}

From source file:com.isotrol.impe3.users.impl.PortalUsersServiceImpl.java

private PortalUserEntity fill(PortalUserEntity entity, PortalUserDTO dto) {
    entity.setName(dto.getUsername());/* w  w w. jav a2  s.  c om*/
    entity.setDisplayName(dto.getDisplayName());
    entity.setEmail(dto.getEmail());
    entity.setActive(dto.isActive());
    final Map<String, String> properties = entity.getProperties();
    properties.clear();
    final Map<String, String> dtop = dto.getProperties();
    if (dtop != null) {
        properties.putAll(Maps.filterKeys(Maps.filterValues(dtop, notNull()), notNull()));

    }
    final Set<String> roles = entity.getRoles();
    roles.clear();
    final Set<String> dtor = dto.getRoles();
    if (dtor != null) {
        roles.addAll(Sets.filter(dtor, notNull()));
    }
    return entity;
}

From source file:com.isotrol.impe3.pms.core.obj.DevicePagesObject.java

/**
 * Filters this collection by page class.
 * @param pageClass Page class./*ww w .j a  v a  2  s .  c om*/
 * @return The filtered collection.
 */
public final Map<UUID, PageObject> byClass(PageClass pageClass) {
    return Maps.filterValues(this, compose(equalTo(pageClass), PAGE_CLASS));
}

From source file:ninja.leaping.permissionsex.backend.sql.SqlSubjectData.java

@Override
public Map<Set<Entry<String, String>>, Map<String, String>> getAllOptions() {
    return Maps.filterValues(
            Maps.transformValues(segments, dataEntry -> dataEntry == null ? null : dataEntry.getOptions()),
            el -> el != null);//  ww  w .j  ava  2  s.  c  o m
}

From source file:org.jage.communication.common.cache.AddressMap.java

@Override
public void init() {
    // Evictor//w ww  .j  a va  2 s  .  c o m
    service = Executors.newScheduledThreadPool(1);
    service.scheduleWithFixedDelay(new Runnable() {

        @Override
        public void run() {
            synchronized (mappingsMutex) {
                Map<INodeAddress, Long> expired = Maps.filterValues(expirations,
                        Ranges.upTo(System.currentTimeMillis(), BoundType.CLOSED));
                for (INodeAddress address : expired.keySet()) {
                    log.debug("Node {} is no longer my neighbour.", address);
                    mappings.remove(address);
                    expirations.remove(address);
                }
                if (!expired.isEmpty()) {
                    informOfCacheChange();
                }
            }
        }
    }, cacheEvictionPeriod, cacheEvictionPeriod, TimeUnit.SECONDS);
}

From source file:no.ssb.vtl.script.expressions.FunctionExpression.java

@VisibleForTesting
static Map<String, VTLExpression> mergeArguments(VTLFunction.Signature signature, List<VTLExpression> arguments,
        Map<String, VTLExpression> namedArguments) {

    // Check unnamed arguments count.
    checkArgument(arguments.size() <= signature.size(), TOO_MANY_ARGUMENTS, signature.size(), arguments.size());

    ImmutableMap.Builder<String, VTLExpression> builder = ImmutableMap.builder();

    // Match the list with the signature names.
    Iterator<String> namesIterator = signature.keySet().iterator();
    for (VTLExpression argument : arguments) {
        builder.put(namesIterator.next(), argument);
    }//from w w w .ja v a  2  s. com

    // Check for duplicates
    Set<String> duplicates = Sets.intersection(namedArguments.keySet(), builder.build().keySet());
    checkArgument(duplicates.isEmpty(), DUPLICATE_ARGUMENTS, String.join(", ", duplicates));

    ImmutableMap<String, VTLExpression> computedArguments = builder.putAll(namedArguments).build();

    // Check for unknown arguments.
    Set<String> unknown = Sets.difference(computedArguments.keySet(), signature.keySet());
    checkArgument(unknown.isEmpty(), UNKNOWN_ARGUMENTS, String.join(", ", unknown));

    // Check for missing arguments
    Set<String> required = Maps.filterValues(signature, VTLFunction.Argument::isRequired).keySet();
    Set<String> missing = Sets.difference(required, computedArguments.keySet());
    checkArgument(missing.isEmpty(), MISSING_ARGUMENTS, String.join(", ", missing));

    return computedArguments;
}