List of usage examples for com.google.common.collect ImmutableMap.Builder putAll
public final void putAll(Map<? extends K, ? extends V> map)
From source file:org.jooby.internal.RouteChain.java
private static Route attrs(final Route route, final List<Route> routes, final int i) { ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); for (int t = i; t < routes.size(); t++) { builder.putAll(routes.get(t).attributes()); }/* w ww . j av a2 s .c o m*/ Map<String, Object> attrs = builder.build(); return new Route.Forwarding(route) { @Override public Map<String, Object> attributes() { return attrs; } }; }
From source file:edu.mit.streamjit.util.CollectionUtils.java
/** * Returns the union of the given maps with disjoint key sets. * @param <K> the key type of the returned map * @param <V> the value type of the returned map * @param first the first map/*from w w w . j a va 2 s. co m*/ * @param more more maps * @return a map containing all the entries in the given maps */ @SafeVarargs public static <K, V> ImmutableMap<K, V> union(Map<? extends K, ? extends V> first, Map<? extends K, ? extends V>... more) { ImmutableMap.Builder<K, V> builder = ImmutableMap.builder(); builder.putAll(first); for (Map<? extends K, ? extends V> m : more) builder.putAll(m); return builder.build(); }
From source file:org.bin01.db.verifier.DbVerifier.java
public static <T> T loadConfig(Class<T> clazz, Optional<String> path) throws IOException { ImmutableMap.Builder<String, String> map = ImmutableMap.builder(); ConfigurationLoader loader = new ConfigurationLoader(); if (path.isPresent()) { map.putAll(loader.loadPropertiesFrom(path.get())); }// w ww . j a v a 2 s .co m map.putAll(loader.getSystemProperties()); return new ConfigurationFactory(map.build()).build(clazz); }
From source file:org.apache.beam.runners.dataflow.worker.SinkRegistry.java
/** * A {@link SinkRegistry} with each {@link SinkFactory} known to the Dataflow worker already * registered./*from ww w . j a v a 2 s . c om*/ * * <p>Uses {@link ServiceLoader} to dynamically bind well known types to sink factories via {@link * SinkFactory.Registrar}. */ public static SinkRegistry defaultRegistry() { Set<SinkFactory.Registrar> readerFactoryRegistrars = Sets .newTreeSet(ReflectHelpers.ObjectsClassComparator.INSTANCE); readerFactoryRegistrars.addAll(Lists .newArrayList(ServiceLoader.load(SinkFactory.Registrar.class, ReflectHelpers.findClassLoader()))); ImmutableMap.Builder<String, SinkFactory> factories = ImmutableMap.builder(); for (SinkFactory.Registrar registrar : readerFactoryRegistrars) { factories.putAll(registrar.factories()); } return new SinkRegistry(factories.build()); }
From source file:codecrafter47.bungeetablistplus.common.network.TypeAdapterRegistry.java
public static TypeAdapterRegistry of(TypeAdapterRegistry... registries) { ImmutableMap.Builder<TypeToken<?>, TypeAdapter<?>> builder = ImmutableMap.builder(); for (TypeAdapterRegistry registry : registries) { builder.putAll(registry.map); }//from ww w. j a v a2 s .c o m return new TypeAdapterRegistry(builder.build()); }
From source file:org.apache.beam.runners.dataflow.worker.ReaderRegistry.java
/** * A {@link ReaderRegistry} with each {@link ReaderFactory} known to the Dataflow worker already * registered.//from w ww . ja va 2s. c o m * * <p>Uses {@link ServiceLoader} to dynamically bind well known types to reader factories via a * {@link ReaderFactory.Registrar}. */ public static ReaderRegistry defaultRegistry() { Set<ReaderFactory.Registrar> readerFactoryRegistrars = Sets .newTreeSet(ReflectHelpers.ObjectsClassComparator.INSTANCE); readerFactoryRegistrars.addAll(Lists .newArrayList(ServiceLoader.load(ReaderFactory.Registrar.class, ReflectHelpers.findClassLoader()))); ImmutableMap.Builder<String, ReaderFactory> factories = ImmutableMap.builder(); for (ReaderFactory.Registrar registrar : readerFactoryRegistrars) { factories.putAll(registrar.factories()); } return new ReaderRegistry(factories.build()); }
From source file:io.prestosql.tests.AbstractTestingPrestoClient.java
private static ClientSession toClientSession(Session session, URI server, Duration clientRequestTimeout) { ImmutableMap.Builder<String, String> properties = ImmutableMap.builder(); properties.putAll(session.getSystemProperties()); for (Entry<String, Map<String, String>> connectorProperties : session.getUnprocessedCatalogProperties() .entrySet()) {//w ww .j av a 2 s .c o m for (Entry<String, String> entry : connectorProperties.getValue().entrySet()) { properties.put(connectorProperties.getKey() + "." + entry.getKey(), entry.getValue()); } } ImmutableMap.Builder<String, String> resourceEstimates = ImmutableMap.builder(); ResourceEstimates estimates = session.getResourceEstimates(); estimates.getExecutionTime().ifPresent(e -> resourceEstimates.put(EXECUTION_TIME, e.toString())); estimates.getCpuTime().ifPresent(e -> resourceEstimates.put(CPU_TIME, e.toString())); estimates.getPeakMemory().ifPresent(e -> resourceEstimates.put(PEAK_MEMORY, e.toString())); return new ClientSession(server, session.getIdentity().getUser(), session.getSource().orElse(null), session.getTraceToken(), session.getClientTags(), session.getClientInfo().orElse(null), session.getCatalog().orElse(null), session.getSchema().orElse(null), session.getPath().toString(), ZoneId.of(session.getTimeZoneKey().getId()), session.getLocale(), resourceEstimates.build(), properties.build(), session.getPreparedStatements(), session.getIdentity().getRoles().entrySet().stream() .collect(toImmutableMap(Entry::getKey, entry -> new ClientSelectedRole( ClientSelectedRole.Type.valueOf(entry.getValue().getType().toString()), entry.getValue().getRole()))), session.getIdentity().getExtraCredentials(), session.getTransactionId().map(Object::toString).orElse(null), clientRequestTimeout); }
From source file:com.google.devtools.build.lib.standalone.StandaloneSpawnStrategy.java
/** * Adds to the given environment all variables that are dependent on system state of the host * machine.//from w w w .ja v a 2s .c o m * * <p>Admittedly, hermeticity is "best effort" in such cases; these environment values should be * as tied to configuration parameters as possible. * * <p>For example, underlying iOS toolchains require that SDKROOT resolve to an absolute system * path, but, when selecting which SDK to resolve, the version number comes from build * configuration. * * @return the new environment, comprised of the old environment plus any new variables * @throws UserExecException if any variables dependent on system state could not be resolved */ public static ImmutableMap<String, String> locallyDeterminedEnv(Path execRoot, String productName, ImmutableMap<String, String> env) throws UserExecException { // TODO(bazel-team): Remove apple-specific logic from this class. ImmutableMap.Builder<String, String> newEnvBuilder = ImmutableMap.builder(); newEnvBuilder.putAll(env); // Empty developer dir indicates to use the system default. // TODO(bazel-team): Bazel's view of the xcode version and developer dir // should be explicitly set for build hermiticity. String developerDir = ""; if (env.containsKey(AppleConfiguration.XCODE_VERSION_ENV_NAME)) { developerDir = getDeveloperDir(execRoot, productName, env.get(AppleConfiguration.XCODE_VERSION_ENV_NAME)); newEnvBuilder.put("DEVELOPER_DIR", developerDir); } if (env.containsKey(AppleConfiguration.APPLE_SDK_VERSION_ENV_NAME)) { // The Apple platform is needed to select the appropriate SDK. if (!env.containsKey(AppleConfiguration.APPLE_SDK_PLATFORM_ENV_NAME)) { throw new UserExecException("Could not resolve apple platform for determining SDK"); } String iosSdkVersion = env.get(AppleConfiguration.APPLE_SDK_VERSION_ENV_NAME); String appleSdkPlatform = env.get(AppleConfiguration.APPLE_SDK_PLATFORM_ENV_NAME); newEnvBuilder.put("SDKROOT", getSdkRootEnv(execRoot, productName, developerDir, iosSdkVersion, appleSdkPlatform)); } return newEnvBuilder.build(); }
From source file:com.opengamma.strata.loader.csv.FixingSeriesCsvLoader.java
/** * Parses one or more CSV format fixing series files. * <p>/* ww w . j a v a 2 s . c om*/ * If the files contain a duplicate entry an exception will be thrown. * * @param charSources the fixing series CSV character sources * @return the loaded fixing series, mapped by {@linkplain ObservableId observable ID} * @throws IllegalArgumentException if the files contain a duplicate entry */ public static ImmutableMap<ObservableId, LocalDateDoubleTimeSeries> parse(Collection<CharSource> charSources) { // builder ensures keys can only be seen once ImmutableMap.Builder<ObservableId, LocalDateDoubleTimeSeries> builder = ImmutableMap.builder(); for (CharSource charSource : charSources) { builder.putAll(parseSingle(charSource)); } return builder.build(); }
From source file:com.google.template.soy.shared.internal.ModuleUtils.java
/** * Given the set of all Soy function implementations, a specific Soy function type (subtype of * SoyFunction) to look for, another Soy function type to look for that is an equivalent * deprecated version of the specific Soy function type, and an adapt function for adapting the * deprecated type to the specific type, finds the Soy functions that implement either type and * returns them in the form of a map from function name to function, where the functions with * the deprecated type have been adapted using the adapt function. * * @param <T> The specific Soy function type to look for. * @param <D> The equivalent deprecated Soy function type to also look for. * @param soyFunctionsSet The set of all Soy functions. * @param specificSoyFunctionType The class of the specific Soy function type to look for. * @param equivDeprecatedSoyFunctionType The class of the equivalent deprecated Soy function * type to also look for./*from w w w .ja v a2 s . c om*/ * @param adaptFn The adapt function that adapts the deprecated type to the specific type. * @return A map of the relevant specific Soy functions (name to function). */ public static <T extends SoyFunction, D extends SoyFunction> ImmutableMap<String, T> buildSpecificSoyFunctionsMapWithAdaptation( Set<SoyFunction> soyFunctionsSet, Class<T> specificSoyFunctionType, Class<D> equivDeprecatedSoyFunctionType, Function<D, T> adaptFn) { ImmutableMap<String, T> tMap = buildSpecificSoyFunctionsMap(soyFunctionsSet, specificSoyFunctionType); ImmutableMap<String, D> dMap = buildSpecificSoyFunctionsMap(soyFunctionsSet, equivDeprecatedSoyFunctionType); ImmutableMap.Builder<String, T> resultMapBuilder = ImmutableMap.builder(); resultMapBuilder.putAll(tMap); for (String functionName : dMap.keySet()) { if (tMap.containsKey(functionName)) { if (tMap.get(functionName).equals(dMap.get(functionName))) { throw new IllegalStateException(String.format( "Found function named '%s' that implements both %s and" + " %s -- please remove the latter deprecated interface.", functionName, specificSoyFunctionType.getSimpleName(), equivDeprecatedSoyFunctionType.getSimpleName())); } else { throw new IllegalStateException(String.format( "Found two functions with the same name '%s', one implementing %s and the" + " other implementing %s", functionName, specificSoyFunctionType.getSimpleName(), equivDeprecatedSoyFunctionType.getSimpleName())); } } resultMapBuilder.put(functionName, adaptFn.apply(dMap.get(functionName))); } return resultMapBuilder.build(); }