Java Code Examples for com.google.common.collect.ImmutableListMultimap#builder()

The following examples show how to use com.google.common.collect.ImmutableListMultimap#builder() . 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: CxxFlags.java    From buck with Apache License 2.0 6 votes vote down vote up
public static ImmutableListMultimap<CxxSource.Type, String> getLanguageFlags(
    ImmutableList<String> flags,
    PatternMatchedCollection<ImmutableList<String>> platformFlags,
    ImmutableMap<CxxSource.Type, ImmutableList<String>> languageFlags,
    CxxPlatform platform) {

  ImmutableListMultimap.Builder<CxxSource.Type, String> langFlags =
      ImmutableListMultimap.builder();

  langFlags.putAll(
      toLanguageFlags(getFlagsWithPlatformMacroExpansion(flags, platformFlags, platform)));

  for (ImmutableMap.Entry<CxxSource.Type, ImmutableList<String>> entry :
      languageFlags.entrySet()) {
    langFlags.putAll(
        entry.getKey(),
        Iterables.transform(
            entry.getValue(),
            (new TranslateMacrosFunction(ImmutableSortedMap.copyOf(platform.getFlagMacros())))
                ::apply));
  }

  return langFlags.build();
}
 
Example 2
Source File: MediaType.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * <em>Replaces</em> all parameters with the given attribute with a single parameter with the
 * given value. If multiple parameters with the same attributes are necessary use
 * {@link #withParameters}. Prefer {@link #withCharset} for setting the {@code charset} parameter
 * when using a {@link Charset} object.
 *
 * @throws IllegalArgumentException if either {@code attribute} or {@code value} is invalid
 */
public MediaType withParameter(String attribute, String value) {
  checkNotNull(attribute);
  checkNotNull(value);
  String normalizedAttribute = normalizeToken(attribute);
  ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder();
  for (Entry<String, String> entry : parameters.entries()) {
    String key = entry.getKey();
    if (!normalizedAttribute.equals(key)) {
      builder.put(key, entry.getValue());
    }
  }
  builder.put(normalizedAttribute, normalizeParameterValue(normalizedAttribute, value));
  MediaType mediaType = new MediaType(type, subtype, builder.build());
  // Return one of the constants if the media type is a known type.
  return MoreObjects.firstNonNull(KNOWN_TYPES.get(mediaType), mediaType);
}
 
Example 3
Source File: MultimapCodec.java    From bazel with Apache License 2.0 6 votes vote down vote up
@Override
public ImmutableMultimap<K, V> deserialize(
    DeserializationContext context, CodedInputStream codedIn)
    throws SerializationException, IOException {
  ImmutableMultimap.Builder<K, V> result;
  if (codedIn.readBool()) {
    result = ImmutableListMultimap.builder();
  } else {
    result = ImmutableSetMultimap.builder();
  }
  int length = codedIn.readInt32();
  for (int i = 0; i < length; i++) {
    K key = context.deserialize(codedIn);
    Collection<V> values = context.deserialize(codedIn);
    result.putAll(key, values);
  }
  return result.build();
}
 
Example 4
Source File: MediaType.java    From codebuff with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private static MediaType create(String type, String subtype, Multimap<String, String> parameters) {
  checkNotNull(type);
  checkNotNull(subtype);
  checkNotNull(parameters);
  String normalizedType = normalizeToken(type);
  String normalizedSubtype = normalizeToken(subtype);
  checkArgument(
    !WILDCARD.equals(normalizedType) || WILDCARD.equals(normalizedSubtype),
    "A wildcard type cannot be used with a non-wildcard subtype");
  ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder();
  for (Entry<String, String> entry : parameters.entries()) {
    String attribute = normalizeToken(entry.getKey());
    builder.put(attribute, normalizeParameterValue(attribute, entry.getValue()));
  }
  MediaType mediaType = new MediaType(normalizedType, normalizedSubtype, builder.build());
  // Return one of the constants if the media type is a known type.
  return MoreObjects.firstNonNull(KNOWN_TYPES.get(mediaType), mediaType);
}
 
Example 5
Source File: PushTableWriteThroughUnion.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
public Result apply(TableWriterNode writerNode, Captures captures, Context context)
{
    UnionNode unionNode = captures.get(CHILD);
    ImmutableList.Builder<PlanNode> rewrittenSources = ImmutableList.builder();
    List<Map<Symbol, Symbol>> sourceMappings = new ArrayList<>();
    for (int source = 0; source < unionNode.getSources().size(); source++) {
        rewrittenSources.add(rewriteSource(writerNode, unionNode, source, sourceMappings, context));
    }

    ImmutableListMultimap.Builder<Symbol, Symbol> unionMappings = ImmutableListMultimap.builder();
    sourceMappings.forEach(mappings -> mappings.forEach(unionMappings::put));

    return Result.ofPlanNode(
            new UnionNode(
                    context.getIdAllocator().getNextId(),
                    rewrittenSources.build(),
                    unionMappings.build(),
                    ImmutableList.copyOf(unionMappings.build().keySet())));
}
 
Example 6
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 7
Source File: PruneUnreferencedOutputs.java    From presto with Apache License 2.0 6 votes vote down vote up
@Override
public PlanNode visitUnion(UnionNode node, RewriteContext<Set<Symbol>> context)
{
    // Find out which output symbols we need to keep
    ImmutableListMultimap.Builder<Symbol, Symbol> prunedMappingBuilder = ImmutableListMultimap.builder();
    for (Symbol symbol : node.getOutputSymbols()) {
        if (context.get().contains(symbol)) {
            prunedMappingBuilder.putAll(symbol, node.getSymbolMapping().get(symbol));
        }
    }
    ListMultimap<Symbol, Symbol> prunedSymbolMapping = prunedMappingBuilder.build();

    // Find the corresponding input symbols to the remaining output symbols and prune the children
    ImmutableList.Builder<PlanNode> rewrittenSources = ImmutableList.builder();
    for (int i = 0; i < node.getSources().size(); i++) {
        ImmutableSet.Builder<Symbol> expectedSourceSymbols = ImmutableSet.builder();
        for (Collection<Symbol> symbols : prunedSymbolMapping.asMap().values()) {
            expectedSourceSymbols.add(Iterables.get(symbols, i));
        }
        rewrittenSources.add(context.rewrite(node.getSources().get(i), expectedSourceSymbols.build()));
    }

    return new UnionNode(node.getId(), rewrittenSources.build(), prunedSymbolMapping, ImmutableList.copyOf(prunedSymbolMapping.keySet()));
}
 
Example 8
Source File: UnaliasSymbolReferences.java    From presto with Apache License 2.0 6 votes vote down vote up
private ListMultimap<Symbol, Symbol> canonicalizeSetOperationSymbolMap(ListMultimap<Symbol, Symbol> setOperationSymbolMap)
{
    ImmutableListMultimap.Builder<Symbol, Symbol> builder = ImmutableListMultimap.builder();
    Set<Symbol> addedSymbols = new HashSet<>();
    for (Map.Entry<Symbol, Collection<Symbol>> entry : setOperationSymbolMap.asMap().entrySet()) {
        Symbol canonicalOutputSymbol = canonicalize(entry.getKey());
        if (addedSymbols.add(canonicalOutputSymbol)) {
            builder.putAll(
                    canonicalOutputSymbol,
                    entry.getValue().stream()
                            .map(this::canonicalize)
                            .collect(Collectors.toList()));
        }
    }
    return builder.build();
}
 
Example 9
Source File: RuleContext.java    From bazel with Apache License 2.0 5 votes vote down vote up
/**
 * For a given attribute, returns all {@link TransitiveInfoCollection}s provided by targets of
 * that attribute. Each {@link TransitiveInfoCollection} is keyed by the {@link
 * BuildConfiguration} under which the collection was created.
 */
public ImmutableListMultimap<BuildConfiguration, TransitiveInfoCollection>
    getPrerequisitesByConfiguration(String attributeName, TransitionMode mode) {
  ImmutableListMultimap.Builder<BuildConfiguration, TransitiveInfoCollection> result =
      ImmutableListMultimap.builder();
  for (ConfiguredTargetAndData prerequisite :
      getPrerequisiteConfiguredTargetAndTargets(attributeName, mode)) {
    result.put(prerequisite.getConfiguration(), prerequisite.getConfiguredTarget());
  }
  return result.build();
}
 
Example 10
Source File: AutoValueOrOneOfProcessor.java    From auto with Apache License 2.0 5 votes vote down vote up
final ImmutableListMultimap<ExecutableElement, AnnotationMirror> propertyMethodAnnotationMap(
    TypeElement type, ImmutableSet<ExecutableElement> propertyMethods) {
  ImmutableListMultimap.Builder<ExecutableElement, AnnotationMirror> builder =
      ImmutableListMultimap.builder();
  for (ExecutableElement propertyMethod : propertyMethods) {
    builder.putAll(propertyMethod, propertyMethodAnnotations(type, propertyMethod));
  }
  return builder.build();
}
 
Example 11
Source File: AutoValueOrOneOfProcessor.java    From auto with Apache License 2.0 5 votes vote down vote up
final ImmutableListMultimap<ExecutableElement, AnnotationMirror> propertyFieldAnnotationMap(
    TypeElement type, ImmutableSet<ExecutableElement> propertyMethods) {
  ImmutableListMultimap.Builder<ExecutableElement, AnnotationMirror> builder =
      ImmutableListMultimap.builder();
  for (ExecutableElement propertyMethod : propertyMethods) {
    builder.putAll(propertyMethod, propertyFieldAnnotations(type, propertyMethod));
  }
  return builder.build();
}
 
Example 12
Source File: TestHttpServletRequest.java    From rack-servlet with Apache License 2.0 5 votes vote down vote up
private Builder() {
  method = "GET";
  servletPath = "";
  requestUri = URI.create("http://example.com/");
  headersBuilder = ImmutableListMultimap.builder();
  body = "";
  attributes = new HashMap<String, Object>();
}
 
Example 13
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 14
Source File: ElementCostOfDataStructures.java    From memory-measurer with Apache License 2.0 5 votes vote down vote up
public ImmutableListMultimap construct(int entries) {
  ImmutableListMultimap.Builder builder = ImmutableListMultimap.builder();
  Object key = newEntry();
  for (int i = 0; i < entries; i++) {
    builder.put(key, newEntry());
  }
  return builder.build();
}
 
Example 15
Source File: SetOperationNodeTranslator.java    From presto with Apache License 2.0 5 votes vote down vote up
private UnionNode union(List<PlanNode> nodes, List<Symbol> outputs)
{
    ImmutableListMultimap.Builder<Symbol, Symbol> outputsToInputs = ImmutableListMultimap.builder();
    for (PlanNode source : nodes) {
        for (int i = 0; i < source.getOutputSymbols().size(); i++) {
            outputsToInputs.put(outputs.get(i), source.getOutputSymbols().get(i));
        }
    }

    return new UnionNode(idAllocator.getNextId(), nodes, outputsToInputs.build(), outputs);
}
 
Example 16
Source File: OutputFileWriter.java    From zsync4j with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
static ListMultimap<BlockSum, Integer> indexPositions(List<BlockSum> blockSums) {
  final ImmutableListMultimap.Builder<BlockSum, Integer> b = ImmutableListMultimap.builder();
  for (int i = 0; i < blockSums.size(); i++) {
    b.put(blockSums.get(i), i);
  }
  return b.build();
}
 
Example 17
Source File: Metaservices.java    From immutables with Apache License 2.0 5 votes vote down vote up
ListMultimap<String, String> allMetaservices() {
  ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder();

  for (Element element : round().getElementsAnnotatedWith(Metainf.Service.class)) {
    @Nullable TypeElement typeElement = validated(element);
    if (typeElement == null) {
      continue;
    }
    Set<String> interfaceNames = extractServiceInterfaceNames(typeElement);
    String binaryName = processing().getElementUtils().getBinaryName(typeElement).toString();
    builder.putAll(binaryName, interfaceNames);
  }

  return builder.build();
}
 
Example 18
Source File: PropertySet.java    From Strata with Apache License 2.0 5 votes vote down vote up
/**
 * Obtains an instance from a map.
 * <p>
 * The returned instance will have one value for each key.
 * 
 * @param keyValues  the key-values to create the instance with
 * @return the property set
 */
public static PropertySet of(Map<String, String> keyValues) {
  ArgChecker.notNull(keyValues, "keyValues");
  ImmutableListMultimap.Builder<String, String> builder = ImmutableListMultimap.builder();
  for (Entry<String, String> entry : keyValues.entrySet()) {
    builder.put(entry);
  }
  return new PropertySet(builder.build());
}
 
Example 19
Source File: ElementCostOfDataStructures.java    From memory-measurer with Apache License 2.0 5 votes vote down vote up
public ImmutableListMultimap construct(int entries) {
  ImmutableListMultimap.Builder builder = ImmutableListMultimap.builder();
  for (int i = 0; i < entries; i++) {
    builder.put(newEntry(), newEntry());
  }
  return builder.build();
}
 
Example 20
Source File: PlannerBindings.java    From fdb-record-layer with Apache License 2.0 4 votes vote down vote up
public Builder() {
    this.map = ImmutableListMultimap.builder();
}