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:org.janusgraph.graphdb.olap.computer.FulgoraVertexMemory.java

public static <K> Map<K, Integer> getIdMap(Iterable<K> elements) {
    ImmutableMap.Builder<K, Integer> b = ImmutableMap.builder();
    int size = 0;
    for (K key : elements) {
        b.put(key, size++);
    }/*  w  w  w. j  a va  2 s.  co m*/
    return b.build();
}

From source file:org.apache.drill.common.map.CaseInsensitiveMap.java

/**
 * Returns a new instance of {@link ImmutableMap} with key case-insensitivity. This map is built from the given
 * map. See {@link ImmutableMap}.//from   w  w w  .  jav  a2s .  c  o  m
 *
 * @param map map to copy from
 * @param <VALUE> type of values to be stored in the map
 * @return key case-insensitive immutable map
 */
public static <VALUE> CaseInsensitiveMap<VALUE> newImmutableMap(
        final Map<? extends String, ? extends VALUE> map) {
    final ImmutableMap.Builder<String, VALUE> builder = ImmutableMap.builder();
    for (final Entry<? extends String, ? extends VALUE> entry : map.entrySet()) {
        builder.put(entry.getKey().toLowerCase(), entry.getValue());
    }
    return new CaseInsensitiveMap<>(builder.build());
}

From source file:com.yahoo.yqlplus.engine.internal.plan.types.Conversions.java

static void registerNoop(ImmutableMap.Builder<String, BytecodeSequence> m, Class from, Class to) {
    m.put(key(from, to), BytecodeSequence.NOOP);
}

From source file:dagger.internal.codegen.SubcomponentNames.java

private static ImmutableMap<ComponentDescriptor, Namer> qualifiedNames(
        Iterable<ComponentDescriptor> componentDescriptors) {
    ImmutableMap.Builder<ComponentDescriptor, Namer> builder = ImmutableMap.builder();
    for (ComponentDescriptor component : componentDescriptors) {
        builder.put(component, new Namer(component.typeElement()));
    }/*from  w  w w .j  a v a 2 s .  c om*/
    return builder.build();
}

From source file:com.opengamma.strata.basics.currency.CurrencyDataLoader.java

/**
 * Loads the priority order of currencies, used to determine the base currency of the market convention pair
 * for pairs that aren't explicitly configured.
 *
 * @return a map of currency to order//w w  w  . java 2 s .co  m
 */
static ImmutableMap<Currency, Integer> loadOrdering() {
    try {
        IniFile ini = ResourceConfig.combinedIniFile(ResourceConfig.orderedResources(CURRENCY_DATA_INI));
        PropertySet section = ini.section("marketConventionPriority");
        String list = section.value("ordering");
        // The currency ordering is defined as a comma-separated list
        List<Currency> currencies = Arrays.stream(list.split(",")).map(String::trim).map(Currency::of)
                .collect(toImmutableList());

        ImmutableMap.Builder<Currency, Integer> orderBuilder = ImmutableMap.builder();

        for (int i = 0; i < currencies.size(); i++) {
            orderBuilder.put(currencies.get(i), i + 1);
        }
        return orderBuilder.build();
    } catch (Exception ex) {
        // logging used because this is loaded in a static variable
        log.severe(Throwables.getStackTraceAsString(ex));
        // return an empty instance to avoid ExceptionInInitializerError
        return ImmutableMap.of();
    }
}

From source file:com.facebook.buck.swift.toolchain.impl.SwiftPlatformsProviderFactory.java

private static FlavorDomain<SwiftPlatform> createSwiftPlatforms(
        AppleCxxPlatformsProvider appleCxxPlatformsProvider) {

    FlavorDomain<AppleCxxPlatform> appleCxxPlatforms = appleCxxPlatformsProvider.getAppleCxxPlatforms();

    ImmutableMap.Builder<Flavor, SwiftPlatform> swiftPlatforms = ImmutableMap.builder();
    for (Flavor flavor : appleCxxPlatforms.getFlavors()) {
        appleCxxPlatforms.getValue(flavor).getSwiftPlatform()
                .ifPresent(swiftPlatform -> swiftPlatforms.put(flavor, swiftPlatform));
    }/*from  w  w  w.  j  a  v a  2  s  .  com*/

    return new FlavorDomain<>("Swift Platform", swiftPlatforms.build());
}

From source file:io.prestosql.cost.StatsAndCosts.java

public static StatsAndCosts create(PlanNode root, StatsProvider statsProvider, CostProvider costProvider) {
    Iterable<PlanNode> planIterator = Traverser.forTree(PlanNode::getSources).depthFirstPreOrder(root);
    ImmutableMap.Builder<PlanNodeId, PlanNodeStatsEstimate> stats = ImmutableMap.builder();
    ImmutableMap.Builder<PlanNodeId, PlanNodeCostEstimate> costs = ImmutableMap.builder();
    for (PlanNode node : planIterator) {
        stats.put(node.getId(), statsProvider.getStats(node));
        costs.put(node.getId(), costProvider.getCumulativeCost(node));
    }/*from  w w  w. j a v a2 s. c  om*/
    return new StatsAndCosts(stats.build(), costs.build());
}

From source file:google.registry.ui.server.SoyTemplateUtils.java

/**
 * Extract class name rewrites from a {@code .css.js} mapping file.
 *
 * <p>This is the file created when you pass {@code --css_renaming_output_file} to the Closure
 * Stylesheets compiler. In order for this to work, {@code --output_renaming_map_format} should
 * be {@code CLOSURE_COMPILED} or {@code CLOSURE_UNCOMPILED}.
 *
 * <p>Here's an example of what the {@code .css.js} file looks like:<pre>
 *
 *   goog.setCssNameMapping({//from  w w  w.j  a  v a  2 s  . co m
 *     "nonLatin": "a",
 *     "secondary": "b",
 *     "mobile": "c"
 *   });</pre>
 *
 * <p>This is a burden that's only necessary for tofu, since the closure compiler is smart enough
 * to substitute CSS class names when soy is compiled to JavaScript.
 */
private static ImmutableMap<String, String> extractCssRenames(String json) {
    ImmutableMap.Builder<String, String> builder = new ImmutableMap.Builder<>();
    Matcher matcher = KEY_VALUE_PATTERN.matcher(json);
    while (matcher.find()) {
        builder.put(matcher.group(1), matcher.group(2));
    }
    return builder.build();
}

From source file:edu.cmu.lti.oaqa.baseqa.answer.yesno.scorers.ConceptOverlapYesNoScorer.java

private static void addAvgMaxMinFeatures(double[] values, ImmutableMap.Builder<String, Double> features,
        Multimap<String, Double> keyword2values, String keyword, String ctype) {
    double avg = DoubleStream.of(values).average().orElse(0);
    features.put(keyword + "-avg@" + ctype, avg);
    keyword2values.put(keyword + "-avg", avg);
    double max = DoubleStream.of(values).max().orElse(0);
    features.put(keyword + "-max@" + ctype, max);
    keyword2values.put(keyword + "-max", max);
    double min = DoubleStream.of(values).min().orElse(0);
    features.put(keyword + "-min@" + ctype, min);
    keyword2values.put(keyword + "-min", min);
}

From source file:org.eclipse.tracecompass.internal.lttng2.ust.core.analysis.memory.UstMemoryStateProvider.java

private static @NonNull Map<String, Integer> buildEventNames(ILttngUstEventLayout layout) {
    ImmutableMap.Builder<String, Integer> builder = ImmutableMap.builder();
    builder.put(layout.eventLibcMalloc(), MALLOC_INDEX);
    builder.put(layout.eventLibcFree(), FREE_INDEX);
    builder.put(layout.eventLibcCalloc(), CALLOC_INDEX);
    builder.put(layout.eventLibcRealloc(), REALLOC_INDEX);
    builder.put(layout.eventLibcMemalign(), MEMALIGN_INDEX);
    builder.put(layout.eventLibcPosixMemalign(), POSIX_MEMALIGN_INDEX);
    return builder.build();
}