List of usage examples for com.google.common.collect ImmutableMap.Builder put
public final V put(K k, V v)
From source file:com.google.template.soy.internal.proto.Field.java
/** Returns the set of fields indexed by soy accessor name for the given type. */ public static <T extends Field> ImmutableMap<String, T> getFieldsForType(Descriptor descriptor, Set<FieldDescriptor> extensions, Factory<T> factory) { ImmutableMap.Builder<String, T> fields = ImmutableMap.builder(); for (FieldDescriptor fieldDescriptor : descriptor.getFields()) { if (ProtoUtils.shouldJsIgnoreField(fieldDescriptor)) { continue; }// w w w . j a va 2 s. c o m T field = factory.create(fieldDescriptor); fields.put(field.getName(), field); } SetMultimap<String, T> extensionsBySoyName = MultimapBuilder.hashKeys().hashSetValues().build(); for (FieldDescriptor extension : extensions) { T field = factory.create(extension); extensionsBySoyName.put(field.getName(), field); } for (Map.Entry<String, Set<T>> group : Multimaps.asMap(extensionsBySoyName).entrySet()) { Set<T> ambiguousFields = group.getValue(); String fieldName = group.getKey(); if (ambiguousFields.size() == 1) { fields.put(fieldName, Iterables.getOnlyElement(ambiguousFields)); } else { T value = factory.createAmbiguousFieldSet(ambiguousFields); logger.severe("Proto " + descriptor.getFullName() + " has multiple extensions with the name \"" + fieldName + "\": " + fullFieldNames(ambiguousFields) + "\nThis field will not be accessible from soy"); fields.put(fieldName, value); } } return fields.build(); }
From source file:com.google.devtools.build.lib.bazel.BazelMain.java
/** * Builds the standard build info map from the loaded properties. The returned value is the list * of "build.*" properties from the build-data.properties file. The final key is the original one * striped, dot replaced with a space and with first letter capitalized. If the file fails to * load the returned map is empty.// w ww. ja v a 2 s .c o m */ private static ImmutableMap<String, String> tryGetBuildInfo() { try (InputStream in = BazelMain.class.getResourceAsStream(BUILD_DATA_PROPERTIES)) { if (in == null) { return ImmutableMap.of(); } Properties props = new Properties(); props.load(in); ImmutableMap.Builder<String, String> buildData = ImmutableMap.builder(); for (Object key : props.keySet()) { String stringKey = key.toString(); if (stringKey.startsWith("build.")) { // build.label -> Build label, build.timestamp.as.int -> Build timestamp as int String buildDataKey = "B" + stringKey.substring(1).replace('.', ' '); buildData.put(buildDataKey, props.getProperty(stringKey, "")); } } return buildData.build(); } catch (IOException ignored) { return ImmutableMap.of(); } }
From source file:com.facebook.buck.cxx.toolchain.CxxPlatformsProviderFactory.java
private static CxxPlatformsProvider createProvider(BuckConfig config, ImmutableMap<Flavor, UnresolvedCxxPlatform> cxxSystemPlatforms) { Platform platform = Platform.detect(); CxxBuckConfig cxxBuckConfig = new CxxBuckConfig(config); // Create a map of system platforms. ImmutableMap.Builder<Flavor, UnresolvedCxxPlatform> cxxSystemPlatformsBuilder = ImmutableMap.builder(); cxxSystemPlatformsBuilder.putAll(cxxSystemPlatforms); CxxPlatform defaultHostCxxPlatform = DefaultCxxPlatforms.build(platform, cxxBuckConfig); cxxSystemPlatformsBuilder.put(defaultHostCxxPlatform.getFlavor(), new StaticUnresolvedCxxPlatform(defaultHostCxxPlatform)); ImmutableMap<Flavor, UnresolvedCxxPlatform> cxxSystemPlatformsMap = cxxSystemPlatformsBuilder.build(); cxxSystemPlatformsMap = appendHostPlatformIfNeeded(defaultHostCxxPlatform, cxxSystemPlatformsMap); Map<Flavor, UnresolvedCxxPlatform> cxxOverridePlatformsMap = updateCxxPlatformsWithOptionsFromBuckConfig( platform, config, cxxSystemPlatformsMap, defaultHostCxxPlatform); UnresolvedCxxPlatform hostCxxPlatform = getHostCxxPlatform(cxxBuckConfig, cxxOverridePlatformsMap); cxxOverridePlatformsMap.put(hostCxxPlatform.getFlavor(), hostCxxPlatform); ImmutableMap<Flavor, UnresolvedCxxPlatform> cxxPlatformsMap = ImmutableMap .<Flavor, UnresolvedCxxPlatform>builder().putAll(cxxOverridePlatformsMap).build(); // Build up the final list of C/C++ platforms. FlavorDomain<UnresolvedCxxPlatform> cxxPlatforms = new FlavorDomain<>("C/C++ platform", cxxPlatformsMap); // Get the default target platform from config. UnresolvedCxxPlatform defaultCxxPlatform = CxxPlatforms.getConfigDefaultCxxPlatform(cxxBuckConfig, cxxPlatformsMap, hostCxxPlatform); return CxxPlatformsProvider.of(defaultCxxPlatform, cxxPlatforms); }
From source file:ru.org.linux.search.SearchController.java
@ModelAttribute("sorts") public static Map<SearchViewer.SearchOrder, String> getSorts() { ImmutableMap.Builder<SearchViewer.SearchOrder, String> builder = ImmutableSortedMap.naturalOrder(); for (SearchViewer.SearchOrder value : SearchViewer.SearchOrder.values()) { builder.put(value, value.getName()); }// w w w . j a v a 2s . c o m return builder.build(); }
From source file:ru.org.linux.search.SearchController.java
@ModelAttribute("ranges") public static Map<SearchViewer.SearchRange, String> getRanges() { ImmutableMap.Builder<SearchViewer.SearchRange, String> builder = ImmutableSortedMap.naturalOrder(); for (SearchViewer.SearchRange value : SearchViewer.SearchRange.values()) { builder.put(value, value.getTitle()); }/*w ww . j a va2 s. co m*/ return builder.build(); }
From source file:eu.eubrazilcc.lvl.core.util.QueryUtils.java
public static ImmutableMap<String, String> parseQuery(final String query, final boolean deduplicate) { final ImmutableMap.Builder<String, String> builder = ImmutableMap.builder(); if (isNotBlank(query)) { String fullText = query;//from ww w .j a v a 2 s .co m final Matcher matcher = KEYWORD_PATTERN.matcher(query); while (matcher.find()) { final String[] keyword = extractKeyword(matcher.group()); builder.put(keyword[0], remove(keyword[1], QUOTES)); fullText = strikethrough(fullText, matcher.start(), matcher.end()); } fullText = deduplicate ? normalize(fullText) : normalizeSpace(fullText); if (isNotBlank(fullText)) { builder.put(TEXT_FIELD, remove(fullText, QUOTES)); } } return builder.build(); }
From source file:com.eucalyptus.tags.Filters.java
private static Map<String, Set<String>> toMap(final Iterable<edu.ucsb.eucalyptus.msgs.Filter> filters) { final ImmutableMap.Builder<String, Set<String>> filterMapBuilder = ImmutableMap.builder(); for (final edu.ucsb.eucalyptus.msgs.Filter filter : filters) { final Set<String> values = ImmutableSet .copyOf(Iterables.transform(filter.getValueSet(), NullToEmptyString.INSTANCE)); filterMapBuilder.put(filter.getName(), values); }//from w w w . j ava 2 s . c o m return filterMapBuilder.build(); }
From source file:org.sonar.java.checks.StandardCharsetsConstantsCheck.java
private static Map<String, String> createAliasToConstantNameMap() { ImmutableMap.Builder<String, String> constantNames = ImmutableMap.builder(); for (Charset charset : STANDARD_CHARSETS) { String constantName = charset.name().replaceAll("-", "_"); constantNames.put(charset.name(), constantName); for (String alias : charset.aliases()) { constantNames.put(alias, constantName); }// www .j ava 2 s.co m } return constantNames.build(); }
From source file:com.spectralogic.dsbrowser.gui.services.tasks.Ds3GetJob.java
public static ImmutableMap<String, Path> getFileMap(final List<Ds3TreeTableValueCustom> selectedItems) { final ImmutableList<Ds3TreeTableValueCustom> fileList = selectedItems.stream() .filter(value -> value.getType().equals(Ds3TreeTableValue.Type.File)) .collect(GuavaCollectors.immutableList()); final ImmutableMap.Builder<String, Path> fileMap = ImmutableMap.builder(); fileList.forEach(file -> {/* w w w . j a v a 2 s . co m*/ fileMap.put(file.getFullName(), Paths.get(StringConstants.FORWARD_SLASH)); }); return fileMap.build(); }
From source file:google.registry.util.TypeUtils.java
/** * Aggregates enum "values" in a typesafe enum pattern into a string->field map. *///from w w w .j a v a 2 s .c om @SuppressWarnings("unchecked") public static <T> ImmutableMap<String, T> getTypesafeEnumMapping(Class<T> clazz) { ImmutableMap.Builder<String, T> builder = new ImmutableMap.Builder<>(); for (Field field : clazz.getFields()) { if (isFinal(field.getModifiers()) && isStatic(field.getModifiers()) && clazz.isAssignableFrom(field.getType())) { try { T enumField = (T) field.get(null); builder.put(field.getName(), enumField); } catch (IllegalArgumentException | IllegalAccessException e) { throw new RuntimeException( String.format("Could not retrieve static final field mapping for %s", clazz.getName()), e); } } } return builder.build(); }