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.smoketurner.notification.application.riak.NotificationListConverter.java

public static Notification convert(@Nonnull final NotificationPB notification) {
    final ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();

    notification.getPropertyList().forEach(property -> builder.put(property.getKey(), property.getValue()));

    return Notification.builder().withId(notification.getId()).withCategory(notification.getCategory())
            .withMessage(notification.getMessage())
            .withCreatedAt(new DateTime(notification.getCreatedAt(), DateTimeZone.UTC))
            .withProperties(builder.build()).build();
}

From source file:com.facebook.buck.jvm.java.BaseCompileToJarStepFactory.java

/**
 * Adds a BashStep for each postprocessClasses command that runs the command followed by the
 * outputDirectory of javac outputs.//from w  w  w.  j  a  v a2s  .  c  om
 *
 * The expectation is that the command will inspect and update the directory by
 * modifying, adding, and deleting the .class files in the directory.
 *
 * The outputDirectory should be a valid java root.  I.e., if outputDirectory
 * is buck-out/bin/java/abc/lib__abc__classes/, then a contained class abc.AbcModule
 * should be at buck-out/bin/java/abc/lib__abc__classes/abc/AbcModule.class
 *
 * @param filesystem the project filesystem.
 * @param postprocessClassesCommands the list of commands to post-process .class files.
 * @param outputDirectory the directory that will contain all the javac output.
 * @param declaredClasspathEntries the list of classpath entries.
 * @param bootClasspath the compilation boot classpath.
 */
@VisibleForTesting
static ImmutableList<Step> addPostprocessClassesCommands(ProjectFilesystem filesystem,
        List<String> postprocessClassesCommands, Path outputDirectory,
        ImmutableSortedSet<Path> declaredClasspathEntries, Optional<String> bootClasspath) {
    if (postprocessClassesCommands.isEmpty()) {
        return ImmutableList.of();
    }

    ImmutableList.Builder<Step> commands = new ImmutableList.Builder<Step>();
    ImmutableMap.Builder<String, String> envVarBuilder = ImmutableMap.builder();
    envVarBuilder.put("COMPILATION_CLASSPATH",
            Joiner.on(':').join(Iterables.transform(declaredClasspathEntries, filesystem::resolve)));

    if (bootClasspath.isPresent()) {
        envVarBuilder.put("COMPILATION_BOOTCLASSPATH", bootClasspath.get());
    }
    ImmutableMap<String, String> envVars = envVarBuilder.build();

    for (final String postprocessClassesCommand : postprocessClassesCommands) {
        BashStep bashStep = new BashStep(filesystem.getRootPath(),
                postprocessClassesCommand + " " + outputDirectory) {
            @Override
            public ImmutableMap<String, String> getEnvironmentVariables(ExecutionContext context) {
                return envVars;
            }
        };
        commands.add(bashStep);
    }
    return commands.build();
}

From source file:com.facebook.presto.connector.system.SystemColumnHandle.java

public static Map<String, ColumnHandle> toSystemColumnHandles(ConnectorTableMetadata tableMetadata) {
    ImmutableMap.Builder<String, ColumnHandle> columnHandles = ImmutableMap.builder();
    for (ColumnMetadata columnMetadata : tableMetadata.getColumns()) {
        columnHandles.put(columnMetadata.getName(), new SystemColumnHandle(columnMetadata.getName()));
    }// w w  w  .j  a v  a 2s .  com

    return columnHandles.build();
}

From source file:com.google.devtools.build.lib.analysis.PlatformConfiguration.java

private static ImmutableMap<Label, Label> convertOverrides(List<ToolchainResolutionOverride> overrides) {
    ImmutableMap.Builder<Label, Label> builder = new ImmutableMap.Builder<>();
    for (ToolchainResolutionOverride override : overrides) {
        builder.put(override.toolchainType(), override.toolchainLabel());
    }/*w w w. ja  v  a  2  s  .  c o m*/

    return builder.build();
}

From source file:org.gradle.api.internal.tasks.compile.incremental.deps.ClassDependentsAccumulator.java

private static <K, V> Map<K, Set<V>> asMap(Multimap<K, V> multimap) {
    ImmutableMap.Builder<K, Set<V>> builder = ImmutableMap.builder();
    for (K key : multimap.keySet()) {
        builder.put(key, ImmutableSet.copyOf(multimap.get(key)));
    }//from   w w w . j a v  a 2  s  .c om
    return builder.build();
}

From source file:com.google.idea.blaze.base.lang.buildfile.language.semantics.RuleDefinition.java

public static RuleDefinition fromProto(Build.RuleDefinition rule) {
    boolean hasNameAttr = false;
    ImmutableMap.Builder<String, AttributeDefinition> map = ImmutableMap.builder();
    for (Build.AttributeDefinition attr : rule.getAttributeList()) {
        map.put(attr.getName(), AttributeDefinition.fromProto(attr));
        hasNameAttr |= "name".equals(attr.getName());
    }// w w w.  jav a 2  s  .c o  m
    if (!hasNameAttr) {
        map.put(NAME_ATTRIBUTE.name, NAME_ATTRIBUTE);
    }
    return new RuleDefinition(rule.getName(), map.build(),
            rule.hasDocumentation() ? rule.getDocumentation() : null);
}

From source file:com.jgaap.backend.AnalysisDrivers.java

private static ImmutableMap<String, AnalysisDriver> loadAnalysisDriversMap() {
    // Load the classifiers dynamically
    ImmutableMap.Builder<String, AnalysisDriver> builder = ImmutableMap.builder();
    for (AnalysisDriver analysisDriver : ANALYSIS_DRIVERS) {
        builder.put(analysisDriver.displayName().toLowerCase(), analysisDriver);
    }/*from w ww.  j  av a  2s .  c  om*/
    return builder.build();
}

From source file:ru.org.linux.comment.CommentList.java

private static void buildIndex(ImmutableMap.Builder<Integer, CommentNode> builder, CommentNode root) {
    if (root.getComment() != null) {
        builder.put(root.getComment().getId(), root);
    }//from  www . ja v a 2  s  .com

    for (CommentNode child : root.childs()) {
        buildIndex(builder, child);
    }
}

From source file:de.metas.ui.web.pporder.PPOrderLinesViewData.java

private static final void indexByIdRecursively(final ImmutableMap.Builder<DocumentId, PPOrderLineRow> collector,
        final PPOrderLineRow row) {
    collector.put(row.getRowId().toDocumentId(), row);
    row.getIncludedRows().forEach(includedRow -> indexByIdRecursively(collector, includedRow));
}

From source file:com.fatboyindustrial.omnium.Maps.java

/**
 * Transforms the given map by applying a function to each of the keys.
 * @param input The input map.//from   w  ww  . java 2s .com
 * @param transform The transformation function to apply to the key.
 * @param <K1> The original key type.
 * @param <V> The map value type.
 * @param <K2> The transformed key type.
 * @return The new map.
 */
public static <K1, V, K2> ImmutableMap<K2, V> keyTransform(final ImmutableMap<K1, V> input,
        final Function<K1, K2> transform) {
    final ImmutableMap.Builder<K2, V> builder = ImmutableMap.builder();
    input.forEach((key, value) -> builder.put(transform.apply(key), value));
    return builder.build();
}