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.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);
            }/*www  .  j  av a  2s. c om*/
            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:grakn.core.graql.executor.property.DataTypeExecutor.java

private static ImmutableMap<Graql.Token.DataType, AttributeType.DataType<?>> dataTypes() {
    ImmutableMap.Builder<Graql.Token.DataType, AttributeType.DataType<?>> dataTypes = new ImmutableMap.Builder<>();
    dataTypes.put(Graql.Token.DataType.BOOLEAN, AttributeType.DataType.BOOLEAN);
    dataTypes.put(Graql.Token.DataType.DATE, AttributeType.DataType.DATE);
    dataTypes.put(Graql.Token.DataType.DOUBLE, AttributeType.DataType.DOUBLE);
    dataTypes.put(Graql.Token.DataType.LONG, AttributeType.DataType.LONG);
    dataTypes.put(Graql.Token.DataType.STRING, AttributeType.DataType.STRING);

    return dataTypes.build();
}

From source file:com.google.cloud.PageImpl.java

/**
 * Utility method to construct the options map for the next page request.
 *
 * @param <T> the value type that the page holds. Instances of {@code T} should be
 *     {@code Serializable}/*w  w w.j a va 2  s. c o m*/
 * @param pageTokenOption the key for the next page cursor option in the options map
 * @param cursor the cursor for the next page
 * @param optionMap the previous options map
 * @return the options map for the next page request
 */
public static <T> Map<T, Object> nextRequestOptions(T pageTokenOption, String cursor, Map<T, ?> optionMap) {
    ImmutableMap.Builder<T, Object> builder = ImmutableMap.builder();
    if (cursor != null) {
        builder.put(pageTokenOption, cursor);
    }
    for (Map.Entry<T, ?> option : optionMap.entrySet()) {
        if (!Objects.equals(option.getKey(), pageTokenOption)) {
            builder.put(option.getKey(), option.getValue());
        }
    }
    return builder.build();
}

From source file:org.tenidwa.collections.utils.AugmentedMap.java

/**
 * Creates map delegate.//from   w ww.  ja  va2  s.  co 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:org.obm.imap.archive.dto.DomainConfigurationDto.java

private static Map<String, String> toMap(List<ScopeUser> scopeUsers) {
    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
    for (ScopeUser scopeUser : scopeUsers) {
        builder.put(scopeUser.serializeId(), scopeUser.getLogin());
    }/* www .j  a  va  2 s.  c  om*/
    return builder.build();
}

From source file:com.opengamma.strata.basics.index.FloatingRateNameIniLookup.java

private static void parseSection(PropertySet section, String indexNameSuffix, FloatingRateType type,
        ImmutableMap.Builder<String, FloatingRateName> builder) {

    // find our names from the RHS of the key/value pairs
    for (String key : section.keys()) {
        builder.put(key, ImmutableFloatingRateName.of(key, section.value(key) + indexNameSuffix, type));
    }/*w  w w  .  java 2 s .  c  om*/
}

From source file:com.google.devtools.build.lib.rules.apple.XcodeVersionProperties.java

private static Map<String, Object> getSkylarkFields(@Nullable DottedVersion xcodeVersion) {
    ImmutableMap.Builder<String, Object> skylarkFields = new ImmutableMap.Builder<>();
    if (xcodeVersion != null) {
        skylarkFields.put("xcode_version", xcodeVersion.toString());
    }// w  w w.j a  va 2 s.  co  m
    return skylarkFields.build();
}

From source file:com.spectralogic.ds3client.helpers.ChunkTransferrer.java

private static ImmutableMap<UUID, JobNode> buildNodeMap(final Iterable<JobNode> nodes) {
    final ImmutableMap.Builder<UUID, JobNode> nodeMap = ImmutableMap.builder();
    for (final JobNode node : nodes) {
        nodeMap.put(node.getId(), node);
    }//from w  ww  .java2s .  c om
    return nodeMap.build();
}

From source file:edu.uci.ics.jung.algorithms.metrics.Metrics.java

/**
 * Returns a <code>Map</code> of nodes to their clustering coefficients. The clustering
 * coefficient cc(v) of a node v is defined as follows:
 *
 * <ul>/* w  ww  . j av a 2s . com*/
 *   <li><code>degree(v) == {0,1}</code>: 0
 *   <li><code>degree(v) == n, n &gt;= 2</code>: given S, the set of neighbors of <code>v</code>:
 *       cc(v) = (the sum over all w in S of the number of other elements of w that are neighbors
 *       of w) / ((|S| * (|S| - 1) / 2). Less formally, the fraction of <code>v</code>'s neighbors
 *       that are also neighbors of each other.
 * </ul>
 *
 * <p><b>Note</b>: This algorithm treats its argument as an undirected graph; edge direction is
 * ignored.
 *
 * @param graph the graph whose clustering coefficients are to be calculated
 * @param <N> the node type
 * @param <E> the edge type
 * @return the clustering coefficient for each node
 * @see "The structure and function of complex networks, M.E.J. Newman,
 *     aps.arxiv.org/abs/cond-mat/0303516"
 */
public static <N> ImmutableMap<N, Double> clusteringCoefficients(Graph<N> graph) {
    ImmutableMap.Builder<N, Double> coefficients = ImmutableMap.builder();

    for (N v : graph.nodes()) {
        int n = graph.degree(v);
        if (n < 2) {
            coefficients.put(v, new Double(0));
        } else {
            int edgeCount = 0;
            for (N w : graph.adjacentNodes(v)) {
                if (!w.equals(v)) {
                    for (N x : graph.adjacentNodes(v)) {
                        // TODO: replace with hasEdge() once it's ready
                        if (!w.equals(x) && graph.adjacentNodes(w).contains(x)) {
                            edgeCount++;
                        }
                    }
                }
            }
            double possible_edges = (n * (n - 1)) / 2.0;
            coefficients.put(v, new Double(edgeCount / possible_edges));
        }
    }

    return coefficients.build();
}

From source file:com.google.devtools.common.options.OptionFilterDescriptions.java

static ImmutableMap<OptionDocumentationCategory, String> getOptionCategoriesEnumDescription(
        String productName) {/*w  w w .  j  a v a  2 s  .  c o m*/
    ImmutableMap.Builder<OptionDocumentationCategory, String> optionCategoriesBuilder = ImmutableMap.builder();
    optionCategoriesBuilder
            .put(OptionDocumentationCategory.UNCATEGORIZED, "Miscellaneous options, not otherwise categorized.")
            .put( // Here for completeness, the help output should not include this option.
                    OptionDocumentationCategory.UNDOCUMENTED,
                    "This feature should not be documented, as it is not meant for general use")
            .put(OptionDocumentationCategory.BAZEL_CLIENT_OPTIONS,
                    "Options that appear before the command and are parsed by the client")
            .put(OptionDocumentationCategory.LOGGING,
                    "Options that affect the verbosity, format or location of logging")
            .put(OptionDocumentationCategory.EXECUTION_STRATEGY, "Options that control build execution")
            .put(OptionDocumentationCategory.BUILD_TIME_OPTIMIZATION,
                    "Options that trigger optimizations of the build time")
            .put(OptionDocumentationCategory.OUTPUT_SELECTION, "Options that control the output of the command")
            .put(OptionDocumentationCategory.OUTPUT_PARAMETERS,
                    "Options that let the user configure the intended output, affecting its value, as "
                            + "opposed to its existence")
            .put(OptionDocumentationCategory.INPUT_STRICTNESS,
                    "Options that affect how strictly Bazel enforces valid build inputs (rule definitions, "
                            + " flag combinations, etc.)")
            .put(OptionDocumentationCategory.SIGNING, "Options that affect the signing outputs of a build")
            .put(OptionDocumentationCategory.TESTING,
                    "Options that govern the behavior of the test environment or test runner")
            .put(OptionDocumentationCategory.TOOLCHAIN,
                    "Options that configure the toolchain used for action execution")
            .put(OptionDocumentationCategory.QUERY, "Options relating to query output and semantics")
            .put(OptionDocumentationCategory.GENERIC_INPUTS,
                    "Options specifying or altering a generic input to a Bazel command that does not fall "
                            + "into other categories.");
    return optionCategoriesBuilder.build();
}