Example usage for com.google.common.collect ImmutableMap.Builder put

List of usage examples for com.google.common.collect ImmutableMap.Builder put

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableMap.Builder put.

Prototype

public final V put(K k, V v) 

Source Link

Usage

From source file:com.facebook.presto.benchmark.driver.BenchmarkDriverOptions.java

private static Map<String, String> toProperties(List<ClientSessionProperty> sessionProperties) {
    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
    for (ClientSessionProperty sessionProperty : sessionProperties) {
        String name = sessionProperty.getName();
        if (sessionProperty.getCatalog().isPresent()) {
            name = sessionProperty.getCatalog().get() + "." + name;
        }/*from  w  w  w  .ja v  a 2 s  .  c  o m*/
        builder.put(name, sessionProperty.getValue());
    }
    return builder.build();
}

From source file:org.apache.druid.query.QueryRunnerTestHelper.java

public static Map<String, Object> of(Object... keyvalues) {
    ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
    for (int i = 0; i < keyvalues.length; i += 2) {
        builder.put(String.valueOf(keyvalues[i]), keyvalues[i + 1]);
    }/*w  w w.  ja va 2 s.c  om*/
    return builder.build();
}

From source file:com.facebook.buck.d.DDescriptionUtils.java

private static ImmutableMap<BuildTarget, DLibrary> getTransitiveDLibraryRules(
        Iterable<? extends BuildRule> inputs) {
    final ImmutableMap.Builder<BuildTarget, DLibrary> libraries = ImmutableMap.builder();
    new AbstractBreadthFirstTraversal<BuildRule>(inputs) {
        @Override/*  www.j a v  a 2s. c o m*/
        public ImmutableSet<BuildRule> visit(BuildRule rule) {
            if (rule instanceof DLibrary) {
                libraries.put(rule.getBuildTarget(), (DLibrary) rule);
                return rule.getDeps();
            }
            return ImmutableSet.of();
        }
    }.start();
    return libraries.build();
}

From source file:com.twitter.aurora.scheduler.configuration.ConfigurationManager.java

private static void maybeFillLinks(TaskConfig task) {
    if (task.getTaskLinksSize() == 0) {
        ImmutableMap.Builder<String, String> links = ImmutableMap.builder();
        if (task.getRequestedPorts().contains("health")) {
            links.put("health", "http://%host%:%port:health%");
        }/*from   w w w  .  j  ava  2  s .c o  m*/
        if (task.getRequestedPorts().contains("http")) {
            links.put("http", "http://%host%:%port:http%");
        }
        task.setTaskLinks(links.build());
    }
}

From source file:com.facebook.buck.rules.coercer.CoercedTypeCache.java

@VisibleForTesting
static ImmutableMap<String, ParamInfo> extractForImmutableBuilder(Class<?> coercableType,
        TypeCoercerFactory typeCoercerFactory) {
    Map<String, Set<Method>> foundSetters = new HashMap<>();
    for (Method method : coercableType.getDeclaredMethods()) {
        if (!method.getName().startsWith("set")) {
            continue;
        }/*  w  ww .j av  a 2  s .c o  m*/
        foundSetters.putIfAbsent(method.getName(), new HashSet<>());
        foundSetters.get(method.getName()).add(method);
    }
    ImmutableMap.Builder<String, ParamInfo> allInfo = new ImmutableMap.Builder<>();
    for (Map.Entry<String, Set<Method>> entry : foundSetters.entrySet()) {
        if (entry.getValue().size() == 1) {
            ParamInfo paramInfo = new ParamInfo(typeCoercerFactory, Iterables.getOnlyElement(entry.getValue()));
            allInfo.put(paramInfo.getName(), paramInfo);
            continue;
        }
        if (entry.getValue().size() > 2) {
            throw new IllegalStateException(String.format(
                    "Builder for coercable type %s had %d setters named %s. Don't know how to coerce.",
                    coercableType.getName(), entry.getValue().size(), entry.getKey()));
        }

        Method takesOptional = null;
        Method takesNonOptional = null;
        for (Method m : entry.getValue()) {
            if (OPTIONAL_TYPES.contains(m.getParameterTypes()[0])) {
                takesOptional = m;
            } else {
                takesNonOptional = m;
            }
        }
        if (takesOptional == null || takesNonOptional == null) {
            throw new IllegalStateException(String.format(
                    "Builder for coercable type %s had 2 setters named %s but they were not Optional "
                            + "and non-Optional. Don't know how to coerce.",
                    coercableType.getName(), entry.getKey()));
        }
        ParamInfo paramInfo = new ParamInfo(typeCoercerFactory, takesOptional);
        allInfo.put(paramInfo.getName(), paramInfo);
    }
    return allInfo.build();
}

From source file:org.gradle.caching.configuration.internal.BuildCacheServiceFactoryRegistry.java

private static Map<Class<? extends BuildCache>, BuildCacheServiceFactory<? extends BuildCache>> findFactories(
        DependencyInjectingServiceLoader serviceLoader, ClassLoader classLoader) {
    ImmutableMap.Builder<Class<? extends BuildCache>, BuildCacheServiceFactory<? extends BuildCache>> registryBuilder = ImmutableMap
            .builder();// w  w w.ja  v  a2  s .c  o  m
    Iterable<BuildCacheServiceFactory> serviceFactories = serviceLoader.load(BuildCacheServiceFactory.class,
            classLoader);
    for (BuildCacheServiceFactory<?> serviceFactory : serviceFactories) {
        Class<? extends BuildCache> configurationType = serviceFactory.getConfigurationType();
        registryBuilder.put(configurationType, serviceFactory);
        LOGGER.info("Loaded {} implementation {}", BuildCacheServiceFactory.class.getSimpleName(),
                serviceFactory.getClass().getName());
    }
    return registryBuilder.build();
}

From source file:de.iteratec.iteraplan.businesslogic.exchange.xmi.exporter.ecore.EntityClassStore.java

private static Map<String, Class<? extends IdEntity>> initNameToClassMappings(
        Collection<Class<? extends IdEntity>> classes) {
    com.google.common.collect.ImmutableMap.Builder<String, Class<? extends IdEntity>> builder = ImmutableMap
            .builder();//from   www .j  av a2  s  .  c  o  m

    for (Class<? extends IdEntity> clazz : classes) {
        builder.put(clazz.getSimpleName(), clazz);
    }

    return builder.build();
}

From source file:com.jgaap.generics.NumericTransformationEventDriver.java

protected static ImmutableMap<String, String> getTransformationMap(String filename) {
    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
    BufferedReader reader = new BufferedReader(new InputStreamReader(NumericTransformationEventDriver.class
            .getResourceAsStream(JGAAPConstants.JGAAP_RESOURCE_PACKAGE + filename)));
    String current;/*  w  ww. j  a v  a  2s.  co m*/
    try {
        while ((current = reader.readLine()) != null) {
            if (current.startsWith("/")) {
                String[] pair = current.split("/");
                builder.put(pair[1], pair[2]);
            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return builder.build();
}

From source file:com.facebook.buck.features.d.DDescriptionUtils.java

private static ImmutableMap<BuildTarget, DLibrary> getTransitiveDLibraryRules(
        Iterable<? extends BuildRule> inputs) {
    ImmutableMap.Builder<BuildTarget, DLibrary> libraries = ImmutableMap.builder();
    new AbstractBreadthFirstTraversal<BuildRule>(inputs) {
        @Override/* w  w  w  .  j  a  v  a  2s .  co  m*/
        public Iterable<BuildRule> visit(BuildRule rule) {
            if (rule instanceof DLibrary) {
                libraries.put(rule.getBuildTarget(), (DLibrary) rule);
                return rule.getBuildDeps();
            }
            return ImmutableSet.of();
        }
    }.start();
    return libraries.build();
}

From source file:com.facebook.buck.io.watchman.WatchmanWatcher.java

@VisibleForTesting
static ImmutableMap<Path, WatchmanQuery> createQueries(ImmutableMap<Path, ProjectWatch> projectWatches,
        ImmutableSet<PathMatcher> ignorePaths, Set<Capability> watchmanCapabilities) {
    ImmutableMap.Builder<Path, WatchmanQuery> watchmanQueryBuilder = ImmutableMap.builder();
    for (Map.Entry<Path, ProjectWatch> entry : projectWatches.entrySet()) {
        watchmanQueryBuilder.put(entry.getKey(),
                createQuery(entry.getValue(), ignorePaths, watchmanCapabilities));
    }/*from  ww  w. ja v  a  2 s  .  co  m*/
    return watchmanQueryBuilder.build();
}