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:io.fabric8.process.manager.support.ApplyConfigurationTask.java

@Override
public void install(InstallContext installContext, ProcessConfig config, String id, File installDir)
        throws Exception {
    Map<String, String> templates = Maps.filterKeys(configuration, isTemplate);
    Map<String, String> plainFiles = Maps.difference(configuration, templates).entriesOnlyOnLeft();
    ProcessManagerService.substituteEnvironmentVariableExpressions((Map) variables, config.getEnvironment());
    Map<String, String> renderedTemplates = Maps.transformValues(templates,
            new MvelTemplateRendering(variables));
    File baseDir = ProcessUtils.findInstallDir(installDir);
    applyTemplates(installContext, renderedTemplates, baseDir);
    applyPlainConfiguration(installContext, plainFiles, baseDir);

}

From source file:org.jclouds.atmos.functions.ParseUserMetadataFromHeaders.java

public UserMetadata apply(HttpResponse from) {
    checkNotNull(from, "http response");

    Map<String, String> meta = Maps.filterKeys(
            getMetaMap(checkNotNull(from.getFirstHeaderOrNull(AtmosHeaders.META), AtmosHeaders.META)),
            Predicates.not(Predicates.in(SYS_KEYS)));

    Map<String, String> listableMeta = (from.getFirstHeaderOrNull(AtmosHeaders.LISTABLE_META) != null)
            ? getMetaMap(from.getFirstHeaderOrNull(AtmosHeaders.LISTABLE_META))
            : ImmutableMap.<String, String>of();

    Iterable<String> tags = (from.getFirstHeaderOrNull(AtmosHeaders.TAGS) != null)
            ? Splitter.on(", ").split(from.getFirstHeaderOrNull(AtmosHeaders.TAGS))
            : ImmutableSet.<String>of();

    Iterable<String> listableTags = (from.getFirstHeaderOrNull(AtmosHeaders.LISTABLE_TAGS) != null)
            ? Splitter.on(", ").split(from.getFirstHeaderOrNull(AtmosHeaders.LISTABLE_TAGS))
            : ImmutableSet.<String>of();

    return new UserMetadata(meta, listableMeta, tags, listableTags);
}

From source file:com.google.devtools.build.lib.exec.local.PosixLocalEnvProvider.java

/**
 * Compute an environment map for local actions on Unix-like platforms (e.g. Linux, macOS).
 *
 * <p>Returns a map with the same keys and values as {@code env}. Overrides the value of TMPDIR
 * (or adds it if not present in {@code env}) by the value of {@code clientEnv.get("TMPDIR")}, or
 * if that's empty or null, then by "/tmp".
 *//*from w  w w. j a  v a 2 s  .  c  o  m*/
@Override
public Map<String, String> rewriteLocalEnv(Map<String, String> env, Path execRoot, String fallbackTmpDir) {
    ImmutableMap.Builder<String, String> result = ImmutableMap.builder();
    result.putAll(Maps.filterKeys(env, k -> !k.equals("TMPDIR")));
    String p = clientEnv.get("TMPDIR");
    if (Strings.isNullOrEmpty(p)) {
        // Do not use `fallbackTmpDir`, use `/tmp` instead. This way if the user didn't export TMPDIR
        // in their environment, Bazel will still set a TMPDIR that's Posixy enough and plays well
        // with heavily path-length-limited scenarios, such as the socket creation scenario that
        // motivated https://github.com/bazelbuild/bazel/issues/4376.
        p = "/tmp";
    }
    result.put("TMPDIR", p);
    return result.build();
}

From source file:com.google.caliper.runner.Instrument.java

@Inject
void setOptions(@InstrumentOptions ImmutableMap<String, String> options) {
    this.options = ImmutableMap.copyOf(Maps.filterKeys(options, Predicates.in(instrumentOptions())));
}

From source file:org.apache.brooklyn.util.executor.HttpExecutorFactoryImpl.java

@Override
public HttpExecutor getHttpExecutor(Map<?, ?> props) {
    HttpExecutor httpExecutor;//w  w  w.jav  a2  s.  c  om

    String httpExecutorClass = (String) props.get(HTTP_EXECUTOR_CLASS_CONFIG);
    if (httpExecutorClass != null) {
        Map<String, Object> httpExecutorProps = MutableMap.of();
        Map<?, ?> executorProps = Maps.filterKeys(props,
                StringPredicates.isStringStartingWith(HTTP_EXECUTOR_CLASS_CONFIG_PREFIX));
        if (executorProps.size() > 0) {
            for (Entry<?, ?> entry : executorProps.entrySet()) {
                String keyName = Strings.removeFromStart((String) entry.getKey(),
                        HTTP_EXECUTOR_CLASS_CONFIG_PREFIX);
                httpExecutorProps.put(keyName, entry.getValue());
            }
        }
        try {
            httpExecutor = (HttpExecutor) new ClassLoaderUtils(getClass()).loadClass(httpExecutorClass)
                    .getConstructor(Map.class).newInstance(httpExecutorProps);
        } catch (Exception e) {
            throw Exceptions.propagate(e);
        }

    } else {
        LOG.info(HTTP_EXECUTOR_CLASS_CONFIG + " parameter not provided. Using the default implementation "
                + HttpExecutorImpl.class.getName());
        httpExecutor = HttpExecutorImpl.newInstance();
    }

    return httpExecutor;
}

From source file:org.jclouds.ec2.suppliers.DescribeRegionsForConfiguredRegions.java

@Singleton
@Region/*from   w ww  .j a va2  s.c  om*/
@Override
public Map<String, Supplier<URI>> get() {
    Set<String> regionWhiteList = regions.get();
    Map<String, URI> regionToUris = client.describeRegions();
    if (regionWhiteList.size() > 0)
        regionToUris = Maps.filterKeys(regionToUris, Predicates.in(regionWhiteList));
    return Maps.transformValues(regionToUris, Suppliers2.<URI>ofInstanceFunction());
}

From source file:com.datastax.driver.core.PrimitiveTypeSamples.java

private static Map<DataType, Object> generateAll() {
    try {/*  w  w w .  j a v a 2  s  .  c o  m*/
        final Collection<DataType> primitiveTypes = DataType
                .allPrimitiveTypes(TestUtils.getDesiredProtocolVersion());
        ImmutableMap<DataType, Object> data = ImmutableMap.<DataType, Object>builder()
                .put(DataType.ascii(), "ascii").put(DataType.bigint(), Long.MAX_VALUE)
                .put(DataType.blob(), Bytes.fromHexString("0xCAFE")).put(DataType.cboolean(), Boolean.TRUE)
                .put(DataType.decimal(), new BigDecimal("12.3E+7")).put(DataType.cdouble(), Double.MAX_VALUE)
                .put(DataType.cfloat(), Float.MAX_VALUE)
                .put(DataType.inet(), InetAddress.getByName("123.123.123.123"))
                .put(DataType.tinyint(), Byte.MAX_VALUE).put(DataType.smallint(), Short.MAX_VALUE)
                .put(DataType.cint(), Integer.MAX_VALUE).put(DataType.text(), "text")
                .put(DataType.timestamp(), new Date(872835240000L))
                .put(DataType.date(), LocalDate.fromDaysSinceEpoch(16071)).put(DataType.time(), 54012123450000L)
                .put(DataType.timeuuid(), UUID.fromString("FE2B4360-28C6-11E2-81C1-0800200C9A66"))
                .put(DataType.uuid(), UUID.fromString("067e6162-3b6f-4ae2-a171-2470b63dff00"))
                .put(DataType.varint(), new BigInteger(Integer.toString(Integer.MAX_VALUE) + "000")).build();

        // Only include data types that support the desired protocol version.
        Map<DataType, Object> result = Maps.filterKeys(data, new Predicate<DataType>() {
            @Override
            public boolean apply(DataType input) {
                return primitiveTypes.contains(input);
            }
        });

        // Check that we cover all types (except counter)
        List<DataType> tmp = Lists.newArrayList(primitiveTypes);
        tmp.removeAll(result.keySet());
        assertThat(tmp).as("new datatype not covered in test").containsOnly(DataType.counter());

        return result;
    } catch (UnknownHostException e) {
        throw new AssertionError(e);
    }
}

From source file:io.fabric8.docker.provider.customizer.ApplyConfigurationStep.java

public void install() throws Exception {
    Map<String, String> templates = Maps.filterKeys(configuration, isTemplate);
    Map<String, String> plainFiles = Maps.difference(configuration, templates).entriesOnlyOnLeft();
    Map<String, String> renderedTemplates = Maps.transformValues(templates,
            new MvelTemplateRendering(variables));

    applyTemplates(renderedTemplates, baseDir);
    applyPlainConfiguration(plainFiles, baseDir);
}

From source file:eu.lp0.cursus.xml.data.entity.DataXMLRace.java

public DataXMLRace(Race race, Set<Pilot> pilots) {
    super(race);/* www  .  ja  va2s  .com*/

    name = race.getName();
    description = race.getDescription();

    if (!race.getAttendees().isEmpty()) {
        attendees = new ArrayList<DataXMLRaceAttendee>(race.getAttendees().size());
        for (RaceAttendee attendee : Maps.filterKeys(race.getAttendees(), Predicates.in(pilots)).values()) {
            attendees.add(new DataXMLRaceAttendee(attendee));
        }
    }
    Collections.sort(attendees);
}

From source file:com.google.devtools.build.lib.exec.local.WindowsLocalEnvProvider.java

/**
 * Compute an environment map for local actions on Windows.
 *
 * <p>Returns a map with the same keys and values as {@code env}. Overrides the value of TMP and
 * TEMP (or adds them if not present in {@code env}) by the same value, which is:
 *
 * <ul>/*from   w  ww  . j  a va2 s .co m*/
 *   <li>the value of {@code clientEnv.get("TMP")}, or if that's empty or null, then
 *   <li>the value of {@code clientEnv.get("TEMP")}, or if that's empty or null, then
 *   <li>the value of {@code fallbackTmpDir}.
 * </ul>
 *
 * <p>The values for TMP and TEMP will use backslashes as directory separators.
 */
@Override
public Map<String, String> rewriteLocalEnv(Map<String, String> env, Path execRoot, String fallbackTmpDir) {
    ImmutableMap.Builder<String, String> result = ImmutableMap.builder();
    result.putAll(Maps.filterKeys(env, k -> !k.equals("TMP") && !k.equals("TEMP")));
    String p = clientEnv.get("TMP");
    if (Strings.isNullOrEmpty(p)) {
        p = clientEnv.get("TEMP");
        if (Strings.isNullOrEmpty(p)) {
            p = fallbackTmpDir;
        }
    }
    p = p.replace('/', '\\');
    result.put("TMP", p);
    result.put("TEMP", p);
    return result.build();
}