List of usage examples for com.google.common.collect ImmutableMap builder
public static <K, V> Builder<K, V> builder()
From source file:com.android.assetstudiolib.AssetStudio.java
@NonNull @VisibleForTesting/*from ww w .ja v a 2 s. c o m*/ static Map<String, String> getBasenameToPathMap(@NonNull Generator generator) { ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<>(); int dotXmlLength = DOT_XML.length(); for (String category : MATERIAL_DESIGN_ICON_CATEGORIES) { String path = MATERIAL_DESIGN_ICONS_PATH + category + '/'; for (Iterator<String> i = generator.getResourceNames(path); i.hasNext();) { String name = i.next(); builder.put(name.substring(0, name.length() - dotXmlLength), path + name); } } return builder.build(); }
From source file:com.isotrol.impe3.pms.core.obj.Builders.java
static <K, V> ImmutableMap<K, V> build(ImmutableMap.Builder<K, V> builder) { if (builder == null) { return ImmutableMap.of(); }//from ww w . jav a2 s . co m return builder.build(); }
From source file:org.apache.beam.runners.dataflow.util.CloudObjects.java
private static Map<Class<? extends Coder>, CloudObjectTranslator<? extends Coder>> populateCoderTranslators() { ImmutableMap.Builder<Class<? extends Coder>, CloudObjectTranslator<? extends Coder>> builder = ImmutableMap .builder();/*from w ww . ja v a2s .co m*/ for (CoderCloudObjectTranslatorRegistrar coderRegistrar : ServiceLoader .load(CoderCloudObjectTranslatorRegistrar.class)) { builder.putAll(coderRegistrar.classesToTranslators()); } return builder.build(); }
From source file:com.facebook.buck.jvm.java.DirectToJarOutputSettingsSerializer.java
public static ImmutableMap<String, Object> serialize(DirectToJarOutputSettings settings) { ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); builder.put(OUTPUT_PATH, settings.getDirectToJarOutputPath().toString()); ImmutableList.Builder<ImmutableMap<String, Object>> serializedPatterns = ImmutableList.builder(); for (Pattern pattern : settings.getClassesToRemoveFromJar()) { serializedPatterns.add(ImmutableMap.<String, Object>of(CLASSES_TO_REMOVE_PATTERN, pattern.pattern(), CLASSES_TO_REMOVE_PATTERN_FLAGS, pattern.flags())); }/*from ww w . ja v a 2s .c o m*/ builder.put(CLASSES_TO_REMOVE, serializedPatterns.build()); ImmutableList.Builder<String> serializedEntries = ImmutableList.builder(); for (Path entry : settings.getEntriesToJar()) { serializedEntries.add(entry.toString()); } builder.put(ENTRIES, serializedEntries.build()); if (settings.getMainClass().isPresent()) { builder.put(MAIN_CLASS, settings.getMainClass().get()); } if (settings.getManifestFile().isPresent()) { builder.put(MANIFEST_FILE, settings.getManifestFile().get().toString()); } return builder.build(); }
From source file:com.facebook.presto.atop.LocalAtopQueryRunner.java
public static LocalQueryRunner createQueryRunner(Map<String, String> catalogProperties, Class<? extends AtopFactory> factoryClass) throws Exception { Session session = testSessionBuilder().setCatalog("atop").setSchema("default") .setTimeZoneKey(TimeZoneKey.getTimeZoneKey(TimeZone.getDefault().getID())).build(); LocalQueryRunner queryRunner = new LocalQueryRunner(session); try {// ww w .jav a 2 s . c o m AtopConnectorFactory connectorFactory = new AtopConnectorFactory(factoryClass, LocalAtopQueryRunner.class.getClassLoader()); ImmutableMap.Builder<String, String> properties = ImmutableMap.<String, String>builder() .putAll(catalogProperties).put("atop.max-history-days", "1"); queryRunner.createCatalog("atop", connectorFactory, properties.build()); return queryRunner; } catch (Exception e) { closeAllSuppress(e, queryRunner); throw e; } }
From source file:io.druid.segment.realtime.appenderator.Committed.java
public static Committed create(Map<SegmentIdentifier, Integer> hydrants0, Object metadata) { final ImmutableMap.Builder<String, Integer> hydrants = ImmutableMap.builder(); for (Map.Entry<SegmentIdentifier, Integer> entry : hydrants0.entrySet()) { hydrants.put(entry.getKey().getIdentifierAsString(), entry.getValue()); }/*from ww w . jav a 2 s.c om*/ return new Committed(hydrants.build(), metadata); }
From source file:com.yahoo.yqlplus.engine.java.SourceMultibindingModule.java
@SuppressWarnings("unchecked") public SourceMultibindingModule(Object... kvPairs) { ImmutableMap.Builder<String, Class<? extends Source>> sources = ImmutableMap.builder(); for (int i = 0; i < kvPairs.length; i += 2) { sources.put((String) kvPairs[i], (Class<? extends Source>) kvPairs[i + 1]); }//from w w w . j a v a 2s .c om this.sources = sources.build(); }
From source file:de.maxikg.messenger.publisher.AmqpPublisher.java
private static Map<String, Object> headers(String type) { ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder(); if (type != null) builder.put(AmqpUtils.HEADER_TYPE, LongStringHelper.asLongString(type)); return builder.build(); }
From source file:com.google.idea.blaze.base.io.FileAttributeScanner.java
public static <T> ImmutableMap<File, T> readAttributes(Iterable<File> fileList, AttributeReader<T> attributeReader, BlazeExecutor executor) throws Exception { List<ListenableFuture<FilePair<T>>> futures = Lists.newArrayList(); for (File file : fileList) { futures.add(executor.submit(() -> { T attribute = attributeReader.getAttribute(file); if (attributeReader.isValid(attribute)) { return new FilePair<>(file, attribute); }//from ww w . j av a 2 s . c o m return null; })); } ImmutableMap.Builder<File, T> result = ImmutableMap.builder(); for (FilePair<T> filePair : Futures.allAsList(futures).get()) { if (filePair != null) { result.put(filePair.file, filePair.attribute); } } return result.build(); }
From source file:co.cask.cdap.cli.util.ArgumentParser.java
/** * Parses a map in the format: "key1=a key2=b .." * * @param mapString {@link String} representation of the map * @return the map/*ww w . j a v a 2s . c om*/ */ public static Map<String, String> parseMap(String mapString) { if (mapString == null || mapString.isEmpty()) { return ImmutableMap.of(); } ImmutableMap.Builder<String, String> result = ImmutableMap.builder(); List<String> tokens = Parser.parseInput(mapString); for (String token : tokens) { int firstEquals = token.indexOf('='); if (firstEquals > 0) { String key = token.substring(0, firstEquals); String value = token.substring(firstEquals + 1, token.length()); result.put(extractValue(key), extractValue(value)); } } return result.build(); }