Java Code Examples for com.google.common.collect.Multimaps#asMap()

The following examples show how to use com.google.common.collect.Multimaps#asMap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RuleContext.java    From bazel with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the prerequisites keyed by their transition keys. If the split transition is not active
 * (e.g. split() returned an empty list), the key is an empty Optional.
 */
public Map<Optional<String>, List<ConfiguredTargetAndData>>
    getSplitPrerequisiteConfiguredTargetAndTargets(String attributeName) {
  checkAttribute(attributeName, TransitionMode.SPLIT);
  // Use an ImmutableListMultimap.Builder here to preserve ordering.
  ImmutableListMultimap.Builder<Optional<String>, ConfiguredTargetAndData> result =
      ImmutableListMultimap.builder();
  List<ConfiguredTargetAndData> deps = getConfiguredTargetAndTargetDeps(attributeName);
  for (ConfiguredTargetAndData t : deps) {
    ImmutableList<String> transitionKeys = t.getTransitionKeys();
    if (transitionKeys.isEmpty()) {
      // The split transition is not active, i.e. does not change build configurations.
      // TODO(jungjw): Investigate if we need to do a sanity check here.
      return ImmutableMap.of(Optional.absent(), deps);
    }
    for (String key : transitionKeys) {
      result.put(Optional.of(key), t);
    }
  }
  return Multimaps.asMap(result.build());
}
 
Example 2
Source File: RaptorMetadata.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public Map<SchemaTableName, List<ColumnMetadata>> listTableColumns(ConnectorSession session, SchemaTablePrefix prefix)
{
    requireNonNull(prefix, "prefix is null");

    ImmutableListMultimap.Builder<SchemaTableName, ColumnMetadata> columns = ImmutableListMultimap.builder();
    for (TableColumn tableColumn : dao.listTableColumns(prefix.getSchema().orElse(null), prefix.getTable().orElse(null))) {
        ColumnMetadata columnMetadata = new ColumnMetadata(tableColumn.getColumnName(), tableColumn.getDataType());
        columns.put(tableColumn.getTable(), columnMetadata);
    }
    return Multimaps.asMap(columns.build());
}
 
Example 3
Source File: SimpleMetaCache.java    From LuckPerms with MIT License 5 votes vote down vote up
public void loadMeta(MetaAccumulator meta) {
    this.meta = Multimaps.asMap(ImmutableListMultimap.copyOf(meta.getMeta()));

    MetaValueSelector metaValueSelector = this.queryOptions.option(MetaValueSelector.KEY)
            .orElseGet(() -> this.plugin.getConfiguration().get(ConfigKeys.META_VALUE_SELECTOR));

    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
    for (Map.Entry<String, List<String>> e : this.meta.entrySet()) {
        if (e.getValue().isEmpty()) {
            continue;
        }

        String selected = metaValueSelector.selectValue(e.getKey(), e.getValue());
        if (selected == null) {
            throw new NullPointerException(metaValueSelector + " returned null");
        }

        builder.put(e.getKey(), selected);
    }
    this.flattenedMeta = builder.build();

    this.prefixes = ImmutableSortedMap.copyOfSorted(meta.getPrefixes());
    this.suffixes = ImmutableSortedMap.copyOfSorted(meta.getSuffixes());
    this.weight = meta.getWeight();
    this.primaryGroup = meta.getPrimaryGroup();
    this.prefixDefinition = meta.getPrefixDefinition();
    this.suffixDefinition = meta.getSuffixDefinition();
    this.prefix = meta.getPrefix();
    this.suffix = meta.getSuffix();
}
 
Example 4
Source File: THttpServiceBuilder.java    From armeria with Apache License 2.0 5 votes vote down vote up
/**
 * Builds a new instance of {@link THttpService}.
 */
public THttpService build() {
    @SuppressWarnings("UnstableApiUsage")
    final Map<String, List<Object>> implementations = Multimaps.asMap(implementationsBuilder.build());

    final ThriftCallService tcs = ThriftCallService.of(implementations);
    return new THttpService(decorate(tcs), newAllowedSerializationFormats(defaultSerializationFormat,
                                                                          otherSerializationFormats));
}
 
Example 5
Source File: TraceAttributeNameDao.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, List<String>> load(String agentRollupId) throws Exception {
    BoundStatement boundStatement = readPS.bind();
    boundStatement.setString(0, agentRollupId);
    ResultSet results = session.read(boundStatement);
    ListMultimap<String, String> traceAttributeNames = ArrayListMultimap.create();
    for (Row row : results) {
        int i = 0;
        String transactionType = checkNotNull(row.getString(i++));
        String traceAttributeName = checkNotNull(row.getString(i++));
        traceAttributeNames.put(transactionType, traceAttributeName);
    }
    return Multimaps.asMap(traceAttributeNames);
}
 
Example 6
Source File: TraceAttributeNameDao.java    From glowroot with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, List<String>> processResultSet(ResultSet resultSet) throws Exception {
    ListMultimap<String, String> multimap = ArrayListMultimap.create();
    while (resultSet.next()) {
        multimap.put(resultSet.getString(1), resultSet.getString(2));
    }
    return Multimaps.asMap(multimap);
}
 
Example 7
Source File: ImmutableContextSetImpl.java    From LuckPerms with MIT License 4 votes vote down vote up
@Override
public @NonNull Map<String, Set<String>> toMap() {
    return Multimaps.asMap(this.map);
}