Example usage for com.google.common.collect ImmutableMap.Builder putAll

List of usage examples for com.google.common.collect ImmutableMap.Builder putAll

Introduction

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

Prototype

public final void putAll(Map<? extends K, ? extends V> map) 

Source Link

Usage

From source file:com.googlesource.gerrit.plugins.lfs.LfsGlobalConfig.java

public Map<String, LfsBackend> getBackends() {
    ImmutableMap.Builder<String, LfsBackend> builder = ImmutableMap.builder();
    for (LfsBackendType type : LfsBackendType.values()) {
        Map<String, LfsBackend> backendsOfType = cfg.getSubsections(type.name()).stream()
                .collect(toMap(name -> name, name -> LfsBackend.create(name, type)));
        builder.putAll(backendsOfType);
    }//from  w w  w.  j  a v a2  s  . co  m

    return builder.build();
}

From source file:com.facebook.presto.orc.writer.MapColumnWriter.java

@Override
public Map<Integer, ColumnStatistics> finishRowGroup() {
    checkState(!closed);/*from   w w  w  .  j  av  a 2s  . c o  m*/

    ColumnStatistics statistics = new ColumnStatistics((long) nonNullValueCount, 0, null, null, null, null,
            null, null, null, null);
    rowGroupColumnStatistics.add(statistics);
    nonNullValueCount = 0;

    ImmutableMap.Builder<Integer, ColumnStatistics> columnStatistics = ImmutableMap.builder();
    columnStatistics.put(column, statistics);
    columnStatistics.putAll(keyWriter.finishRowGroup());
    columnStatistics.putAll(valueWriter.finishRowGroup());
    return columnStatistics.build();
}

From source file:com.google.api.codegen.packagegen.py.PythonGrpcPackageGenerator.java

@Override
public Map<String, GeneratedResult<Doc>> generate() throws IOException {
    ImmutableMap.Builder<String, GeneratedResult<Doc>> results = new ImmutableMap.Builder<>();
    ArrayList<PackageMetadataView> metadataViews = new ArrayList<>();

    PythonPackageCopier copier = new PythonPackageCopier();
    PythonPackageCopierResult copierResult = copier.run(options, config);

    results.putAll(copierResult.results());
    PythonGrpcPackageTransformer pythonTransformer = new PythonGrpcPackageTransformer(copierResult);
    ProtoApiModel apiModel = new ProtoApiModel(model);
    metadataViews.addAll(pythonTransformer.transform(apiModel, config));

    for (PackageMetadataView view : metadataViews) {
        CommonSnippetSetRunner runner = new CommonSnippetSetRunner(view, false);
        results.putAll(runner.generate(view));
    }// w  ww .  j a  v a 2 s . co m
    return results.build();
}

From source file:com.facebook.presto.Session.java

public ClientSession toClientSession(URI server, boolean debug) {
    ImmutableMap.Builder<String, String> properties = ImmutableMap.builder();
    properties.putAll(systemProperties);
    for (Entry<String, Map<String, String>> catalogProperties : this.catalogProperties.entrySet()) {
        String catalog = catalogProperties.getKey();
        for (Entry<String, String> entry : catalogProperties.getValue().entrySet()) {
            properties.put(catalog + "." + entry.getKey(), entry.getValue());
        }/* w  w w .  j  a v a2s .  co  m*/
    }

    return new ClientSession(requireNonNull(server, "server is null"), identity.getUser(), source.orElse(null),
            catalog.orElse(null), schema.orElse(null), timeZoneKey.getId(), locale, properties.build(), debug);
}

From source file:org.jclouds.googlecomputeengine.compute.functions.BuildInstanceMetadata.java

@Override
public ImmutableMap.Builder apply(TemplateOptions input) {
    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
    if (input.getPublicKey() != null) {
        builder.put("sshKeys",
                format("%s:%s %s@localhost", checkNotNull(input.getLoginUser(), "loginUser cannot be null"),
                        input.getPublicKey(), input.getLoginUser()));
    }/* w  ww .  j a  v  a  2s.c om*/
    builder.putAll(input.getUserMetadata());
    return builder;
}

From source file:com.android.tools.idea.model.ManifestPlaceholderResolver.java

public ManifestPlaceholderResolver(@NotNull Module module) {
    AndroidModuleModel model = AndroidModuleModel.get(module);

    if (model != null) {
        ImmutableMap.Builder<String, Object> placeholdersBuilder = ImmutableMap.builder();

        Variant selectedVariant = model.getSelectedVariant();
        BuildTypeContainer buildType = model.findBuildType(selectedVariant.getBuildType());
        if (buildType != null) {
            placeholdersBuilder.putAll(buildType.getBuildType().getManifestPlaceholders());
        }/* www.  ja  va 2s  . co m*/
        // flavors and default config
        placeholdersBuilder.putAll(selectedVariant.getMergedFlavor().getManifestPlaceholders());

        myPlaceholders = placeholdersBuilder.build();
    } else {
        myPlaceholders = ImmutableMap.of();
    }
}

From source file:org.voltdb.AdmissionControlGroup.java

public void logTransactionCompleted(long connectionId, String connectionHostname, String procedureName,
        int delta, byte status) {
    //Allocate enough space to store the proc name + 8 characters of connection id
    final StringBuilder key = new StringBuilder(procedureName.length() + 9);
    key.append(procedureName).append('$').append(connectionId);
    //StringBuilder.toString(), why you gotta make a copy?
    final String keyString = key.toString();
    InvocationInfo info = m_connectionStats.get(keyString);
    if (info == null) {
        info = new InvocationInfo(connectionHostname);
        ImmutableMap.Builder<String, InitiatorStats.InvocationInfo> builder = ImmutableMap.builder();
        builder.putAll(m_connectionStats);
        builder.put(keyString, info);/* w  ww.  j a  va 2  s .  com*/
        m_connectionStats = builder.build();
    }
    info.processInvocation(delta, status);
}

From source file:io.prestosql.orc.AbstractOrcDataSource.java

@Override
public final <K> Map<K, OrcDataSourceInput> readFully(Map<K, DiskRange> diskRanges) throws IOException {
    requireNonNull(diskRanges, "diskRanges is null");

    if (diskRanges.isEmpty()) {
        return ImmutableMap.of();
    }/*from w  w  w .  ja va 2s  . c o m*/

    //
    // Note: this code does not use the Java 8 stream APIs to avoid any extra object allocation
    //

    // split disk ranges into "big" and "small"
    long maxReadSizeBytes = maxBufferSize.toBytes();
    ImmutableMap.Builder<K, DiskRange> smallRangesBuilder = ImmutableMap.builder();
    ImmutableMap.Builder<K, DiskRange> largeRangesBuilder = ImmutableMap.builder();
    for (Entry<K, DiskRange> entry : diskRanges.entrySet()) {
        if (entry.getValue().getLength() <= maxReadSizeBytes) {
            smallRangesBuilder.put(entry);
        } else {
            largeRangesBuilder.put(entry);
        }
    }
    Map<K, DiskRange> smallRanges = smallRangesBuilder.build();
    Map<K, DiskRange> largeRanges = largeRangesBuilder.build();

    // read ranges
    ImmutableMap.Builder<K, OrcDataSourceInput> slices = ImmutableMap.builder();
    slices.putAll(readSmallDiskRanges(smallRanges));
    slices.putAll(readLargeDiskRanges(largeRanges));

    return slices.build();
}

From source file:org.attribyte.essem.sysmon.linux.SystemMonitor.java

/**
 * Creates a system monitor.//  www  .  j  a v a  2s.c  om
 * @param pollFrequencySeconds The poll frequency in seconds.
 * @param meminfoKeys The instrumented keys for memory info.
 * @param storageTypeFilter Filters only instrumented storage types.
 * @param networkDeviceFilter Filters only instrumented network devices.
 * @param logger A logger. May be <code>null</code>.
 */
public SystemMonitor(final int pollFrequencySeconds, final Collection<String> meminfoKeys,
        final KeyFilter storageTypeFilter, final KeyFilter networkDeviceFilter, final Logger logger) {

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

    try {
        LoadAverage loadAverage = new LoadAverage();
        builder.putAll(loadAverage.getMetrics());
        scheduler.scheduleAtFixedRate(loadAverage, 0, pollFrequencySeconds, TimeUnit.SECONDS);
    } catch (IOException ioe) {
        if (logger != null)
            logger.error("Unable to instrument load averages", ioe);
    }

    try {
        MemoryInfo meminfo = new MemoryInfo(meminfoKeys);
        builder.put("memory", meminfo);
        scheduler.scheduleAtFixedRate(meminfo, 0, pollFrequencySeconds, TimeUnit.SECONDS);
    } catch (IOException ioe) {
        if (logger != null)
            logger.error("Unable to instrument memory", ioe);
    }

    try {
        NetworkDevices networkDevices = new NetworkDevices();
        Set<String> names = Sets.newHashSet();
        for (NetworkDevices.Interface iface : networkDevices.interfaces.values()) {
            if (networkDeviceFilter.accept(iface.name)) {
                if (!names.contains(iface.name)) {
                    builder.put("iface." + iface.name, iface);
                    names.add(iface.name);
                } else if (logger != null) {
                    logger.warn("Duplicate interface name: '" + iface.name + "'");
                }
            }
        }
        scheduler.scheduleAtFixedRate(networkDevices, 0, pollFrequencySeconds, TimeUnit.SECONDS);
    } catch (IOException ioe) {
        if (logger != null)
            logger.error("Unable to instrument network devices", ioe);
    }

    Set<String> acceptedDevices = Sets.newHashSet();

    try {
        Storage storage = new Storage();
        Set<String> names = Sets.newHashSet();
        for (Storage.Filesystem filesystem : storage.filesystems) {
            if (storageTypeFilter.accept(filesystem.type)) {
                if (!names.contains(filesystem.name)) {
                    builder.put(filesystem.name, filesystem);
                    names.add(filesystem.name);
                    String[] dev_name = filesystem.name.split("/");
                    if (dev_name.length == 2) {
                        acceptedDevices.add(dev_name[1]);
                    } else {
                        acceptedDevices.add(filesystem.name);
                    }
                } else if (logger != null) {
                    logger.warn("Duplicate filesystem name: '" + filesystem.name + "'");
                }
            }
        }
    } catch (IOException ioe) {
        if (logger != null)
            logger.error("Unable to instrument storage devices", ioe);
    }

    try {
        BlockDevices blockDevices = new BlockDevices();
        scheduler.scheduleAtFixedRate(blockDevices, 0, pollFrequencySeconds, TimeUnit.SECONDS);
        for (BlockDevices.BlockDevice device : blockDevices.devices) {
            if (acceptedDevices.contains(device.name)) {
                builder.put("blockdev." + device.name, device);
            }
        }
    } catch (IOException ioe) {
        if (logger != null)
            logger.error("Unable to instrument block devices", ioe);
    }

    this.metrics = builder.build();
}

From source file:io.prestosql.orc.writer.ListColumnWriter.java

@Override
public Map<Integer, ColumnStatistics> getColumnStripeStatistics() {
    checkState(closed);//w w w. j  av a2  s . com
    ImmutableMap.Builder<Integer, ColumnStatistics> columnStatistics = ImmutableMap.builder();
    columnStatistics.put(column, ColumnStatistics.mergeColumnStatistics(rowGroupColumnStatistics));
    columnStatistics.putAll(elementWriter.getColumnStripeStatistics());
    return columnStatistics.build();
}