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:io.prestosql.plugin.hive.orc.OrcPageSourceFactory.java

private static Map<String, Integer> buildPhysicalNameOrdinalMap(OrcReader reader) {
    ImmutableMap.Builder<String, Integer> physicalNameOrdinalMap = ImmutableMap.builder();

    int ordinal = 0;
    for (String physicalColumnName : reader.getColumnNames()) {
        physicalNameOrdinalMap.put(physicalColumnName, ordinal);
        ordinal++;/*from  ww w. j a  v a2s  . com*/
    }

    return physicalNameOrdinalMap.build();
}

From source file:com.google.enterprise.connector.db.diffing.JsonDocument.java

/**
 * Copies a string-valued attribute from a JSONObject to a map of SPI
 * Value objects.//from   w w w  .  j a  v a  2s  .com
 */
private static void extractAttribute(JSONObject jo, ImmutableMap.Builder<String, List<Value>> mapBuilder,
        String key) {
    try {
        if (!jo.isNull(key)) {
            mapBuilder.put(key, ImmutableList.of(Value.getStringValue(jo.getString(key))));
        }
    } catch (JSONException e) {
        LOG.log(Level.WARNING, "Exception thrown while extracting key: " + key, e);
    }
}

From source file:garmintools.sections.SectionManager.java

private static Map<Integer, SectionFactory<?>> createSectionFactories() {
    Set<Integer> allIds = new HashSet<>(
            ContiguousSet.create(Range.closed(0, Ids.MAX_SECTION_NUMBER), DiscreteDomain.integers()));

    ImmutableMap.Builder<Integer, SectionFactory<?>> builder = ImmutableMap.builder();
    for (SectionFactory<?> sectionFactory : SECTION_FACTORIES_LIST) {
        builder.put(sectionFactory.getSectionNumber(), sectionFactory);
        allIds.remove(sectionFactory.getSectionNumber());
    }/*from ww  w.  j av a 2s .c  o m*/
    for (int unparsedSectionNumber : UNPARSED_SECTIONS) {
        builder.put(unparsedSectionNumber, new UnparsedSection.Factory(unparsedSectionNumber));
        allIds.remove(unparsedSectionNumber);
    }
    Preconditions.checkState(allIds.isEmpty(), "Unbound section(s): " + allIds);
    return builder.build();
}

From source file:com.opengamma.strata.collect.io.XmlFile.java

private static ImmutableMap<String, String> parseAttributes(XMLStreamReader reader) {
    ImmutableMap<String, String> attrs;
    int attributeCount = reader.getAttributeCount() + reader.getNamespaceCount();
    if (attributeCount == 0) {
        attrs = ImmutableMap.of();//from  w w  w  .ja  v a 2 s .  c  om
    } else {
        ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
        for (int i = 0; i < reader.getAttributeCount(); i++) {
            builder.put(reader.getAttributeLocalName(i), reader.getAttributeValue(i));
        }
        attrs = builder.build();
    }
    return attrs;
}

From source file:com.facebook.buck.core.rules.knowntypes.KnownBuildRuleTypesTestUtil.java

protected static ImmutableMap<ProcessExecutorParams, FakeProcess> getPythonProcessMap(List<String> paths) {
    Set<String> uniquePaths = new HashSet<>(paths);
    ImmutableMap.Builder<ProcessExecutorParams, FakeProcess> processMap = ImmutableMap.builder();
    for (Map.Entry<String, String> python : PYTHONS.entrySet()) {
        for (String path : uniquePaths) {
            for (String extension : new String[] { "", ".exe", ".EXE" }) {
                processMap.put(
                        ProcessExecutorParams.builder()
                                .setCommand(ImmutableList
                                        .of(path + File.separator + python.getKey() + extension, "-"))
                                .build(),
                        new FakeProcess(0, "CPython " + python.getValue(), ""));
            }/*  ww  w  . j  av  a 2  s. c  o m*/
        }
    }
    return processMap.build();
}

From source file:com.spotify.heroic.metric.bigtable.api.Table.java

public static Table fromPb(com.google.bigtable.admin.v2.Table table) {
    final Matcher m = TABLE_NAME_PATTERN.matcher(table.getName());

    if (!m.matches()) {
        throw new IllegalArgumentException("Illegal table URI: " + table.getName());
    }/*from   ww  w  .  j  a  v  a  2 s  .  c  o  m*/

    final String cluster = m.group(1);
    final String tableId = m.group(2);

    final ImmutableMap.Builder<String, ColumnFamily> columnFamilies = ImmutableMap.builder();

    for (final Entry<String, com.google.bigtable.admin.v2.ColumnFamily> e : table.getColumnFamilies()
            .entrySet()) {
        final ColumnFamily columnFamily = new ColumnFamily(cluster, tableId, e.getKey());
        columnFamilies.put(columnFamily.getName(), columnFamily);
    }

    return new Table(cluster, tableId, columnFamilies.build());
}

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

/**
 * Parse a {@link com.google.devtools.build.lib.query2.proto.proto2api.Build.QueryResult} as
 * returned by a bazel query and look for the list of target containing a {@code java_toolchain}
 * rule. These rules are then parsed into {@link JavaToolchainData}'s and returned as map with the
 * name of the target as key and the {@link JavaToolchainData} as value.
 *///ww w.j a  v  a 2s  .  co  m
public static ImmutableMap<String, JavaToolchainData> parse(QueryResult queryResult) {
    ImmutableMap.Builder<String, JavaToolchainData> builder = ImmutableMap.builder();
    for (Build.Target target : queryResult.getTargetList()) {
        Build.Rule rule = target.getRule();
        if (target.hasRule() && rule.getRuleClass().equals("java_toolchain")) {
            builder.put(rule.getName(), parseBuildRuleProto(rule));
        }
    }
    return builder.build();
}

From source file:gobblin.hive.metastore.HiveMetaStoreEventHelper.java

private static Map<String, String> getAdditionalMetadata(HiveTable table, Optional<HivePartition> partition,
        Optional<Exception> error) {
    ImmutableMap.Builder<String, String> builder = ImmutableMap.<String, String>builder()
            .put(DB_NAME, table.getDbName()).put(TABLE_NAME, table.getTableName());

    if (table.getLocation().isPresent()) {
        builder.put("Location", table.getLocation().get());
    }/*from   ww w .  j a  va2s  . c om*/

    if (partition.isPresent()) {
        builder.put("Partition", partition.get().toString());
    }

    if (error.isPresent()) {
        builder.put(ERROR_MESSAGE, error.get().getMessage());
    }

    return builder.build();
}

From source file:org.dishevelled.bio.assembly.gfa2.Fragment.java

/**
 * Parse a fragment GFA 2.0 record from the specified value.
 *
 * @param value value, must not be null//  w  ww . ja v  a2s .  c o m
 * @return a fragment GFA 2.0 record parsed from the specified value
 */
public static Fragment valueOf(final String value) {
    checkNotNull(value);
    checkArgument(value.startsWith("F"), "value must start with F");
    List<String> tokens = Splitter.on("\t").splitToList(value);
    if (tokens.size() < 8) {
        throw new IllegalArgumentException("value must have at least eight tokens, was " + tokens.size());
    }
    String segmentId = tokens.get(1);
    Reference external = Reference.valueOf(tokens.get(2));
    Position segmentStart = Position.valueOf(tokens.get(3));
    Position segmentEnd = Position.valueOf(tokens.get(4));
    Position fragmentStart = Position.valueOf(tokens.get(5));
    Position fragmentEnd = Position.valueOf(tokens.get(6));
    Alignment alignment = Alignment.valueOf(tokens.get(7));

    ImmutableMap.Builder<String, Tag> tags = ImmutableMap.builder();
    for (int i = 8; i < tokens.size(); i++) {
        Tag tag = Tag.valueOf(tokens.get(i));
        tags.put(tag.getName(), tag);
    }

    return new Fragment(segmentId, external, segmentStart, segmentEnd, fragmentStart, fragmentEnd, alignment,
            tags.build());
}

From source file:com.pinterest.pinlater.backends.redis.RedisBackendUtils.java

/**
 * Creates the Redis shard map from config.
 *
 * @param redisConfigStream InputStream containing the Redis config json.
 * @param configuration PropertiesConfiguration object.
 * @return A map shardName -> RedisPools.
 *///  w ww. ja v a 2  s. c om
public static ImmutableMap<String, RedisPools> buildShardMap(InputStream redisConfigStream,
        PropertiesConfiguration configuration) {
    RedisConfigSchema redisConfig;
    try {
        redisConfig = RedisConfigSchema.read(Preconditions.checkNotNull(redisConfigStream));
    } catch (IOException e) {
        LOG.error("Failed to load redis configuration", e);
        throw new RuntimeException(e);
    }

    ImmutableMap.Builder<String, RedisPools> shardMapBuilder = new ImmutableMap.Builder<String, RedisPools>();
    for (RedisConfigSchema.Shard shard : redisConfig.shards) {
        shardMapBuilder.put(shard.name, new RedisPools(configuration, shard.shardConfig.master.host,
                shard.shardConfig.master.port, shard.shardConfig.dequeueOnly));
    }
    return shardMapBuilder.build();
}