Example usage for com.google.common.collect ImmutableMap builder

List of usage examples for com.google.common.collect ImmutableMap builder

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableMap builder.

Prototype

public static <K, V> Builder<K, V> builder() 

Source Link

Usage

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());
    }/* www  .j  a va2 s  . c  om*/

    return builder.build();
}

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 w w .  j av a2 s.  c  o  m
    return builder.build();
}

From source file:org.androidtransfuse.analysis.AnalysisContext.java

private AnalysisContext(InjectionNode node, AnalysisContext previousContext,
        InjectionNodeBuilderRepository injectionNodeBuilders) {
    ImmutableMap.Builder<ASTType, InjectionNode> dependentsBuilder = ImmutableMap.builder();

    dependentsBuilder.putAll(previousContext.dependents);
    if (!previousContext.dependents.containsKey(node.getASTType())) {
        //avoid adding duplicate keys (result of dependency loops)
        dependentsBuilder.put(node.getASTType(), node);
    }//from ww w .  jav a 2  s  . co m

    this.dependents = dependentsBuilder.build();

    this.injectionNodeBuilders = injectionNodeBuilders;
}

From source file:org.apache.shindig.gadgets.spec.ApplicationManifest.java

public ApplicationManifest(Uri uri, Element xml) throws SpecParserException {
    ImmutableMap.Builder<String, String> versions = ImmutableMap.builder();
    ImmutableMap.Builder<String, Uri> gadgets = ImmutableMap.builder();

    NodeList nodes = xml.getElementsByTagName("gadget");
    for (int i = 0, j = nodes.getLength(); i < j; ++i) {
        Element gadget = (Element) nodes.item(i);
        String version = getVersionString(gadget);
        Uri spec = getSpecUri(uri, gadget);
        gadgets.put(version, spec);/* w  w w .ja  v  a2 s  . co  m*/
        for (String label : getLabels(gadget)) {
            versions.put(label, version);
        }
    }

    this.uri = uri;
    this.versions = versions.build();
    this.gadgets = gadgets.build();
}

From source file:org.elasticsearch.search.lookup.SearchLookup.java

public SearchLookup(MapperService mapperService, IndexFieldDataService fieldDataService,
        @Nullable String[] types) {
    ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
    docMap = new DocLookup(mapperService, fieldDataService, types);
    sourceLookup = new SourceLookup();
    fieldsLookup = new FieldsLookup(mapperService, types);
    indexLookup = new IndexLookup(builder);

    builder.put("doc", docMap);
    builder.put("_doc", docMap);
    builder.put("_source", sourceLookup);
    builder.put("_fields", fieldsLookup);
    builder.put("_index", indexLookup);
    asMap = builder.build();/*w  ww.j a  v  a 2  s .  c  o m*/
}

From source file:io.blobkeeper.common.util.GuavaCollectors.java

public static <T, K, V> Collector<T, ?, ImmutableMap<K, V>> toImmutableMap(
        Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends V> valueMapper) {
    Supplier<ImmutableMap.Builder<K, V>> supplier = ImmutableMap.Builder::new;
    BiConsumer<ImmutableMap.Builder<K, V>, T> accumulator = (b, t) -> b.put(keyMapper.apply(t),
            valueMapper.apply(t));//www . ja  v a 2s  . c om
    BinaryOperator<ImmutableMap.Builder<K, V>> combiner = (l, r) -> l.putAll(r.build());
    Function<ImmutableMap.Builder<K, V>, ImmutableMap<K, V>> finisher = ImmutableMap.Builder::build;

    return Collector.of(supplier, accumulator, combiner, finisher);
}

From source file:org.graylog2.inputs.converters.TokenizerConverter.java

@Override
public Object convert(String value) {
    if (isNullOrEmpty(value)) {
        return value;
    }// w w w  .j  a  v a  2 s  .co  m

    if (value.contains("=")) {
        final ImmutableMap.Builder<String, String> fields = ImmutableMap.builder();

        Matcher m = PATTERN.matcher(value);
        while (m.find()) {
            if (m.groupCount() != 2) {
                continue;
            }

            fields.put(removeQuotes(m.group(1)), removeQuotes(m.group(2)));
        }

        return fields.build();
    } else {
        return Collections.emptyMap();
    }
}

From source file:com.boundary.metrics.vmware.poller.PerformanceCounterMetadata.java

/**
 * Constructore//w  w  w  .  j a  va 2  s .  co m
 * @param infoMap Mapping of performance counter id and {@link PerfCounterInfo}
 * @param nameMap Mapping
 */
public PerformanceCounterMetadata() {
    this.infoMap = ImmutableMap.builder();
    this.nameMap = ImmutableMap.builder();
}

From source file:org.jclouds.elasticstack.functions.CreateDriveRequestToMap.java

@Override
public Map<String, String> apply(Drive from) {
    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
    builder.putAll(baseDriveToMap.apply(from));
    if (from instanceof CreateDriveRequest) {
        CreateDriveRequest create = CreateDriveRequest.class.cast(from);
        if (create.getAvoid().size() != 0)
            builder.put("avoid", Joiner.on(' ').join(create.getAvoid()));
        if (create.getEncryptionCipher() != null)
            builder.put("encryption:cipher", create.getEncryptionCipher());
    }/*w ww. j  ava 2s. co m*/
    return builder.build();
}

From source file:com.querydsl.sql.QBeans.java

@SuppressWarnings("unchecked")
public QBeans(RelationalPath<?>... beanPaths) {
    super(Beans.class);
    try {/*from   w  w w. j a  va 2s.com*/
        final ImmutableList.Builder<Expression<?>> listBuilder = ImmutableList.builder();
        final ImmutableMap.Builder<RelationalPath<?>, QBean<?>> mapBuilder = ImmutableMap.builder();
        for (RelationalPath<?> path : beanPaths) {
            Map<String, Expression<?>> bindings = new LinkedHashMap<String, Expression<?>>();
            for (Path<?> column : path.getColumns()) {
                bindings.put(column.getMetadata().getName(), column);
                listBuilder.add(column);
            }
            mapBuilder.put(path, Projections.bean((Class) path.getType(), bindings));
        }
        expressions = listBuilder.build();
        qBeans = mapBuilder.build();
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}