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.palantir.typescript.TypeScriptBuilder.java

private static Map<String, Object> createTaskMarkerAttributes(TodoCommentEx todo) {
    ImmutableMap.Builder<String, Object> attributes = ImmutableMap.builder();

    attributes.put(IMarker.CHAR_START, todo.getStart());
    attributes.put(IMarker.CHAR_END, todo.getStart() + todo.getText().length());
    attributes.put(IMarker.LINE_NUMBER, todo.getLine());
    attributes.put(IMarker.MESSAGE, todo.getText());
    attributes.put(IMarker.PRIORITY, todo.getPriority());
    attributes.put(IMarker.SEVERITY, IMarker.SEVERITY_INFO);

    return attributes.build();
}

From source file:com.facebook.presto.sql.planner.optimizations.HashGenerationOptimizer.java

private static ProjectNode getHashProjectNode(PlanNodeIdAllocator idAllocator, PlanNode source,
        Symbol hashSymbol, List<Symbol> partitioningSymbols) {
    checkArgument(!partitioningSymbols.isEmpty(), "partitioningSymbols is empty");
    ImmutableMap.Builder<Symbol, Expression> outputSymbols = ImmutableMap.builder();
    for (Symbol symbol : source.getOutputSymbols()) {
        Expression expression = new QualifiedNameReference(symbol.toQualifiedName());
        outputSymbols.put(symbol, expression);
    }//from   w  ww. ja v  a 2 s  .co m

    Expression hashExpression = getHashExpression(partitioningSymbols);
    outputSymbols.put(hashSymbol, hashExpression);
    return new ProjectNode(idAllocator.getNextId(), source, outputSymbols.build());
}

From source file:gg.uhc.uhc.util.TimeUtil.java

public static Map<TimeUnit, Long> getUnits(String timeString) {
    ImmutableMap.Builder<TimeUnit, Long> map = ImmutableMap.builder();

    Matcher matcher = PART_PATTERN.matcher(timeString);

    while (matcher.find()) {
        String unit = matcher.group("unit").toLowerCase();
        String size = matcher.group("size");

        TimeUnit type = UNIT_MAP.get(unit.charAt(0));

        if (type == null)
            continue;

        map.put(type, Long.parseLong(size));
    }/* w w w  . java 2 s  .c  om*/

    return map.build();
}

From source file:io.prestosql.geospatial.KdbTree.java

private static void addLeaves(Node node, ImmutableMap.Builder<Integer, Rectangle> leaves,
        Predicate<Node> predicate) {
    if (!predicate.apply(node)) {
        return;/* w  w  w. ja va 2  s  .c  o  m*/
    }

    if (node.leafId.isPresent()) {
        leaves.put(node.leafId.getAsInt(), node.extent);
    } else {
        addLeaves(node.left.get(), leaves, predicate);
        addLeaves(node.right.get(), leaves, predicate);
    }
}

From source file:io.prestosql.cli.ClientOptions.java

public static Map<String, String> toResourceEstimates(List<ClientResourceEstimate> estimates) {
    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
    for (ClientResourceEstimate estimate : estimates) {
        builder.put(estimate.getResource(), estimate.getEstimate());
    }/*from w  ww .  j a v a 2  s  .  c  o  m*/
    return builder.build();
}

From source file:org.openqa.selenium.remote.server.NewSessionPayload.java

public static NewSessionPayload create(Capabilities caps) throws IOException {
    // We need to convert the capabilities into a new session payload. At this point we're dealing
    // with references, so I'm Just Sure This Will Be Fine.

    ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();

    // OSS/*w ww  .  j a  v  a 2  s  .  co m*/
    builder.put("desiredCapabilities", caps.asMap());

    // W3C Spec.
    // TODO(simons): There's some serious overlap between ProtocolHandshake and this class.
    ImmutableMap.Builder<String, Object> w3cCaps = ImmutableMap.builder();
    caps.asMap().entrySet().stream().filter(e -> ACCEPTED_W3C_PATTERNS.test(e.getKey()))
            .filter(e -> e.getValue() != null).forEach(e -> w3cCaps.put(e.getKey(), e.getValue()));
    builder.put("capabilities", ImmutableMap.of("firstMatch", ImmutableList.of(w3cCaps.build())));

    return new NewSessionPayload(builder.build());
}

From source file:com.google.caliper.util.ShortDuration.java

private static Map<String, TimeUnit> createAbbrevToUnitMap() {
    ImmutableMap.Builder<String, TimeUnit> builder = ImmutableMap.builder();
    for (Map.Entry<TimeUnit, String> entry : ABBREVIATIONS.entries()) {
        builder.put(entry.getValue(), entry.getKey());
    }//from ww  w .  j  av  a  2s.c  o  m
    return builder.build();
}

From source file:org.apache.beam.runners.core.ReplacementOutputs.java

public static Map<PValue, ReplacementOutput> ordered(List<TaggedPValue> original, POutput replacement) {
    ImmutableMap.Builder<PValue, ReplacementOutput> result = ImmutableMap.builder();
    List<TaggedPValue> replacements = replacement.expand();
    checkArgument(original.size() == replacements.size(),
            "Original and Replacements must be the same size. Original: %s Replacement: %s", original.size(),
            replacements.size());//  ww  w . j ava  2  s. co m
    int i = 0;
    for (TaggedPValue replacementPvalue : replacements) {
        result.put(replacementPvalue.getValue(), ReplacementOutput.of(original.get(i), replacementPvalue));
        i++;
    }
    return result.build();
}

From source file:io.prestosql.sql.planner.iterative.rule.AddIntermediateAggregations.java

/**
 * Rewrite assignments so that outputs are in terms of the input symbols.
 * This operation only reliably applies to aggregation steps that take partial inputs (e.g. INTERMEDIATE and split FINALs),
 * which are guaranteed to have exactly one input and one output.
 * <p>//from   w ww  . j  av a2 s  . c om
 * Example:
 * 'a' := sum('b') => 'b' := sum('b')
 */
private static Map<Symbol, AggregationNode.Aggregation> inputsAsOutputs(
        Map<Symbol, AggregationNode.Aggregation> assignments) {
    ImmutableMap.Builder<Symbol, AggregationNode.Aggregation> builder = ImmutableMap.builder();
    for (Map.Entry<Symbol, AggregationNode.Aggregation> entry : assignments.entrySet()) {
        // Should only have one input symbol
        Symbol input = getOnlyElement(SymbolsExtractor.extractAll(entry.getValue().getCall()));
        builder.put(input, entry.getValue());
    }
    return builder.build();
}

From source file:org.jmingo.parser.xml.dom.util.DomUtil.java

/**
 * Transform node attributes to map.//from   ww w .j a v  a2s .  c o m
 *
 * @param node the node {@link Node}
 * @return map : key - attribute name; value - attribute value
 */
public static Map<String, String> getAttributes(Node node) {
    Map<String, String> attributes = ImmutableMap.of();
    if (node.hasAttributes()) {
        ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
        // get attributes names and values
        NamedNodeMap nodeMap = node.getAttributes();
        for (int i = 0; i < nodeMap.getLength(); i++) {
            Node currentNode = nodeMap.item(i);
            builder.put(currentNode.getNodeName(), currentNode.getNodeValue());
        }
        attributes = builder.build();
    }
    return attributes;
}