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

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

Introduction

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

Prototype

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

Source Link

Document

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

Usage

From source file:org.geogit.storage.memory.HeapRefDatabase.java

@Override
public Map<String, String> removeAll(final String namespace) {

    Predicate<String> keyPredicate = new Predicate<String>() {

        @Override/*www. ja  v  a2 s. co  m*/
        public boolean apply(String refName) {
            return refName.startsWith(namespace);
        }
    };
    Map<String, String> removed = Maps.filterKeys(ImmutableMap.copyOf(this.refs), keyPredicate);
    for (String key : removed.keySet()) {
        refs.remove(key);
    }
    return null;
}

From source file:com.enablens.dfa.datastructures.Node.java

/**
 * Gets the identity./* w ww . j ava2s .  c o  m*/
 * 
 * @return the identity
 */
public final Map<String, String> getId() {
    return Maps.filterKeys(data, Predicates.in(type.getIdentityAttributes()));
}

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

/**
 * Returns all configured targets currently in the graph.
 *///from   w w w .j a v a2s .co  m
public static Iterable<ConfiguredTarget> getAllExistingConfiguredTargets(SkyframeExecutor skyframeExecutor) {
    Collection<SkyValue> values = Maps.filterKeys(skyframeExecutor.getEvaluatorForTesting().getValues(),
            SkyFunctions.isSkyFunction(SkyFunctions.CONFIGURED_TARGET)).values();
    List<ConfiguredTarget> cts = Lists.newArrayList();
    for (SkyValue value : values) {
        if (value != null) {
            cts.add(((ConfiguredTargetValue) value).getConfiguredTarget());
        }
    }
    return cts;
}

From source file:org.opendaylight.controller.sal.binding.impl.DataBrokerImpl.java

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override/*from   w  w  w.j  av a 2  s .com*/
protected Map<InstanceIdentifier<? extends DataObject>, DataObject> deepGetBySubpath(
        final Map<InstanceIdentifier<? extends DataObject>, DataObject> dataSet,
        final InstanceIdentifier<? extends DataObject> path) {
    Builder<InstanceIdentifier<? extends DataObject>, DataObject> builder = ImmutableMap.builder();
    Map<InstanceIdentifier<? extends DataObject>, DataObject> potential = Maps.filterKeys(dataSet,
            createIsContainedPredicate(path));
    for (Entry<InstanceIdentifier<? extends DataObject>, DataObject> entry : potential.entrySet()) {
        try {
            builder.putAll(DataObjectReadingUtil.readData(entry.getValue(), (InstanceIdentifier) entry.getKey(),
                    path));
        } catch (Exception e) {
            // FIXME : Log exception;
        }
    }
    return builder.build();

}

From source file:org.locationtech.geogig.storage.memory.HeapRefDatabase.java

@Override
public Map<String, String> getAll(final String prefix) {
    Preconditions.checkNotNull(prefix);/* w ww  . j a v a 2 s .com*/
    Predicate<String> filter = new RefPrefixPredicate(prefix);
    return Maps.filterKeys(ImmutableMap.copyOf(this.refs), filter);
}

From source file:com.google.enterprise.connector.importexport.ExportConnectors.java

/**
 * Removes properties whose names start with "google" from the Configuration.
 *
 * @param configMap a Map of configuration properties.
 * @return configMap with "google*" properties filtered out.
 *//*  w  ww  .j av a 2 s . com*/
private Map<String, String> removeGoogleProperties(Map<String, String> configMap) {
    // We don't bother making a copy, since encryptSensitiveProperties
    // makes a copy first thing.
    return Maps.filterKeys(configMap, new Predicate<String>() {
        public boolean apply(String input) {
            return !input.startsWith("google");
        }
    });
}

From source file:org.openflexo.foundation.dm.JarLoader.java

public Map<String, Class<?>> getContainedClasses() {
    return Maps.filterKeys(classLoader.getClassForClassName(), new Predicate<String>() {
        @Override/*  w  ww.j ava  2s .c  o m*/
        public boolean apply(String input) {
            return classNames.contains(input);
        }
    });
}

From source file:com.enablens.dfa.datastructures.Node.java

/**
 * Gets the parent id./*w  ww.  ja v a  2  s. c o  m*/
 * 
 * @param topologyName
 *            the topology name
 * @return the parent id
 */
public Map<String, String> getParentId() {
    if (type == NodeType.TOPOLOGY) {
        return null;
    }
    return Maps.filterKeys(data, Predicates.in(type.getParentType().getIdentityAttributes()));
}

From source file:com.facebook.buck.command.config.AbstractConfigIgnoredByDaemon.java

@Value.Lazy
public ImmutableMap<String, ImmutableMap<String, String>> getRawConfigForParser() {
    ImmutableMap<String, ImmutableSet<String>> ignoredFields = getIgnoreFieldsForDaemonRestart();
    ImmutableMap<String, ImmutableMap<String, String>> rawSections = getDelegate().getConfig()
            .getSectionToEntries();/*from   w w  w  . j  a  va  2  s  .  c  o m*/

    // If the raw config doesn't have sections which have ignored fields, then just return it as-is.
    ImmutableSet<String> sectionsWithIgnoredFields = ignoredFields.keySet();
    if (Sets.intersection(rawSections.keySet(), sectionsWithIgnoredFields).isEmpty()) {
        return rawSections;
    }

    // Otherwise, iterate through the config to do finer-grain filtering.
    ImmutableMap.Builder<String, ImmutableMap<String, String>> filtered = ImmutableMap.builder();
    for (Map.Entry<String, ImmutableMap<String, String>> sectionEnt : rawSections.entrySet()) {
        String sectionName = sectionEnt.getKey();

        // If this section doesn't have a corresponding ignored section, then just add it as-is.
        if (!sectionsWithIgnoredFields.contains(sectionName)) {
            filtered.put(sectionEnt);
            continue;
        }

        // If none of this section's entries are ignored, then add it as-is.
        ImmutableMap<String, String> fields = sectionEnt.getValue();
        ImmutableSet<String> ignoredFieldNames = ignoredFields.getOrDefault(sectionName, ImmutableSet.of());
        if (Sets.intersection(fields.keySet(), ignoredFieldNames).isEmpty()) {
            filtered.put(sectionEnt);
            continue;
        }

        // Otherwise, filter out the ignored fields.
        ImmutableMap<String, String> remainingKeys = ImmutableMap
                .copyOf(Maps.filterKeys(fields, Predicates.not(ignoredFieldNames::contains)));
        filtered.put(sectionName, remainingKeys);
    }

    return MoreMaps.filterValues(filtered.build(), Predicates.not(Map::isEmpty));
}

From source file:org.apache.brooklyn.location.jclouds.BlobStoreContextFactoryImpl.java

@Override
public BlobStoreContext newBlobStoreContext(Location location) {
    String rawProvider = checkNotNull(location.getConfig(LocationConfigKeys.CLOUD_PROVIDER),
            "provider must not be null");
    String provider = DeserializingJcloudsRenamesProvider.INSTANCE.applyJcloudsRenames(rawProvider);
    String identity = checkNotNull(location.getConfig(LocationConfigKeys.ACCESS_IDENTITY),
            "identity must not be null");
    String credential = checkNotNull(location.getConfig(LocationConfigKeys.ACCESS_CREDENTIAL),
            "credential must not be null");
    String endpoint = location.getConfig(CloudLocationConfig.CLOUD_ENDPOINT);

    Properties overrides = new Properties();
    // * Java 7,8 bug workaround - sockets closed by GC break the internal bookkeeping
    //   of HttpUrlConnection, leading to invalid handling of the "HTTP/1.1 100 Continue"
    //   response. Coupled with a bug when using SSL sockets reads will block
    //   indefinitely even though a read timeout is explicitly set.
    // * Java 6 ignores the header anyways as it is included in its restricted headers black list.
    // * Also there's a bug in SL object store which still expects Content-Length bytes
    //   even when it responds with a 408 timeout response, leading to incorrectly
    //   interpreting the next request (triggered by above problem).
    overrides.setProperty(Constants.PROPERTY_STRIP_EXPECT_HEADER, "true");

    // Add extra jclouds-specific configuration
    Map<String, Object> extra = Maps.filterKeys(((LocationInternal) location).config().getBag().getAllConfig(),
            Predicates.containsPattern("^jclouds\\."));
    if (extra.size() > 0) {
        LOG.debug("Configuring custom jclouds property overrides for {}: {}", provider,
                Sanitizer.sanitize(extra));
    }//from   ww w. j  a v a 2  s .c  o  m
    overrides.putAll(Maps.filterValues(extra, Predicates.notNull()));

    ContextBuilder contextBuilder = ContextBuilder.newBuilder(provider).credentials(identity, credential);
    contextBuilder.modules(MutableList.copyOf(getCommonModules()));
    if (!org.apache.brooklyn.util.text.Strings.isBlank(endpoint)) {
        contextBuilder.endpoint(endpoint);
    }
    contextBuilder.overrides(overrides);
    BlobStoreContext context = contextBuilder.buildView(BlobStoreContext.class);
    return context;
}