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:com.spotify.metrics.remote.SemanticAggregator.java
public static Map<String, String> buildAttributes(MetricId id, String type) { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); builder.putAll(id.getTags()); builder.put("metric_type", type); return builder.build(); }
From source file:com.wrmsr.neurosis.util.ImmutableCollectors.java
public static <I, K, V> Collector<I, ImmutableMap.Builder<K, V>, ImmutableMap<K, V>> toImmutableMap( Function<I, K> keyMapper, Function<I, V> valueMapper) { return Collector.of(ImmutableMap::builder, (builder, in) -> builder.put(keyMapper.apply(in), valueMapper.apply(in)), (ImmutableMap.Builder<K, V> left, ImmutableMap.Builder<K, V> right) -> left.putAll(right.build()), ImmutableMap.Builder<K, V>::build); }
From source file:org.tenidwa.collections.utils.AugmentedMap.java
/** * Creates map delegate.//from ww w. j a va 2 s . c o m * @param base Base map to augment. * @param keys Keys to the augmented map. * @param augmentation Function used to generate the new values. * @param <K> Key * @param <V> Value * @return A copy of the {@code base} map augmented with new values. */ private static <K, V> ImmutableMap<K, V> createDelegate(final Map<K, V> base, final Set<? extends K> keys, final Function<K, V> augmentation) { final ImmutableMap.Builder<K, V> builder = ImmutableMap.builder(); builder.putAll(base); keys.stream().filter(key -> !base.containsKey(key)) .forEach(key -> builder.put(key, augmentation.apply(key))); return builder.build(); }
From source file:com.google.javascript.jscomp.parsing.Config.java
/** * Create the annotation names from the user-specified * annotation whitelist.// w w w . jav a2s.c o m */ private static Map<String, Annotation> buildAnnotationNames(Set<String> annotationWhitelist) { ImmutableMap.Builder<String, Annotation> annotationBuilder = ImmutableMap.builder(); annotationBuilder.putAll(Annotation.recognizedAnnotations); for (String unrecognizedAnnotation : annotationWhitelist) { if (!Annotation.recognizedAnnotations.containsKey(unrecognizedAnnotation)) { annotationBuilder.put(unrecognizedAnnotation, Annotation.NOT_IMPLEMENTED); } } return annotationBuilder.build(); }
From source file:io.prestosql.sql.planner.iterative.rule.PushTableWriteThroughUnion.java
private static TableWriterNode rewriteSource(TableWriterNode writerNode, UnionNode unionNode, int source, List<Map<Symbol, Symbol>> sourceMappings, Context context) { Map<Symbol, Symbol> inputMappings = getInputSymbolMapping(unionNode, source); ImmutableMap.Builder<Symbol, Symbol> mappings = ImmutableMap.builder(); mappings.putAll(inputMappings); ImmutableMap.Builder<Symbol, Symbol> outputMappings = ImmutableMap.builder(); for (Symbol outputSymbol : writerNode.getOutputSymbols()) { if (inputMappings.containsKey(outputSymbol)) { outputMappings.put(outputSymbol, inputMappings.get(outputSymbol)); } else {//from w ww. j a v a 2 s .c o m Symbol newSymbol = context.getSymbolAllocator().newSymbol(outputSymbol); outputMappings.put(outputSymbol, newSymbol); mappings.put(outputSymbol, newSymbol); } } sourceMappings.add(outputMappings.build()); SymbolMapper symbolMapper = new SymbolMapper(mappings.build()); return symbolMapper.map(writerNode, unionNode.getSources().get(source), context.getIdAllocator().getNextId()); }
From source file:com.google.cloud.bigtable.dataflowimport.HBaseImportIO.java
private static ImmutableMap<String, String> createSerializationProperties(HBaseImportOptions options) { ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); builder.putAll(CONST_FILE_READER_PROPERTIES); if (!Strings.isNullOrEmpty(options.getProject())) { builder.put(FS_GS_PROJECT_ID, options.getProject()); }/*from w ww .j a v a 2 s .c o m*/ if (options.isHBase094DataFormat()) { builder.put(IMPORT_FORMAT_VER, VERSION_094_STRING); } return builder.build(); }
From source file:blusunrize.immersiveengineering.client.models.ModelData.java
public static ModelData fromJson(JsonObject customData, Collection<String> knownKeys, String modelKey, ImmutableMap<String, String> texReplacements) { String baseLocStr = customData.get(modelKey).getAsString(); ResourceLocation baseLoc = new ResourceLocation(baseLocStr); JsonObject customBase = new JsonObject(); if (customData.has("custom")) customBase = customData.get("custom").getAsJsonObject(); for (Entry<String, JsonElement> e : customData.entrySet()) if (!knownKeys.contains(e.getKey()) && !customBase.has(e.getKey())) customBase.add(e.getKey(), e.getValue()); if (customData.has("textures")) { JsonObject obj = customData.get("textures").getAsJsonObject(); ImmutableMap.Builder<String, String> b = ImmutableMap.builder(); b.putAll(texReplacements); b.putAll(asMap(obj, true));/*from ww w . java 2 s . co m*/ texReplacements = b.build(); } return new ModelData(baseLoc, customBase, texReplacements); }
From source file:com.google.devtools.build.lib.analysis.SkylarkProviders.java
private static <K, V> ImmutableMap<K, V> mergeMaps(List<SkylarkProviders> providers, Function<SkylarkProviders, Map<K, V>> mapGetter, Map<K, V> premerged) throws DuplicateException { Set<K> seenKeys = new HashSet<>(); ImmutableMap.Builder<K, V> resultBuilder = ImmutableMap.builder(); resultBuilder.putAll(premerged); for (SkylarkProviders provider : providers) { Map<K, V> map = mapGetter.apply(provider); for (K key : map.keySet()) { if (premerged.containsKey(key)) { continue; }/* w ww .j a v a 2 s. c o m*/ if (!seenKeys.add(key)) { // TODO(dslomov): add better diagnostics. throw new DuplicateException("Provider " + key + " provided twice"); } resultBuilder.put(key, map.get(key)); } } return resultBuilder.build(); }
From source file:org.springframework.ide.eclipse.boot.templates.BootJavaContext.java
private static <T> Map<String, Predicate<T>> negate(ImmutableMap<String, Predicate<T>> base) { ImmutableMap.Builder<String, Predicate<T>> builder = ImmutableMap.builder(); builder.putAll(base); for (Entry<String, Predicate<T>> e : base.entrySet()) { String name = e.getKey(); if (!name.startsWith("!")) { builder.put("!" + name, e.getValue().negate()); }/*from ww w . j a v a 2 s . c o m*/ } return builder.build(); }
From source file:com.wrmsr.kleist.util.collect.MoreCollectors.java
public static <I, K, V> Collector<I, ImmutableMap.Builder<K, V>, ImmutableMap<K, V>> toImmutableMap( Function<I, K> keyMapper, Function<I, V> valueMapper) { return Collector.of(ImmutableMap::builder, (builder, in) -> builder.put(keyMapper.apply(in), valueMapper.apply(in)), (ImmutableMap.Builder<K, V> left, ImmutableMap.Builder<K, V> right) -> left.putAll(right.build()), ImmutableMap.Builder::build); }