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

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

Introduction

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

Prototype

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

Source Link

Document

Returns a new builder.

Usage

From source file:com.facebook.buck.cxx.AbstractCxxPreprocessorInput.java

public static CxxPreprocessorInput concat(Iterable<CxxPreprocessorInput> inputs) {
    ImmutableMultimap.Builder<CxxSource.Type, String> preprocessorFlags = ImmutableMultimap.builder();
    ImmutableList.Builder<CxxHeaders> headers = ImmutableList.builder();
    ImmutableSet.Builder<FrameworkPath> frameworks = ImmutableSet.builder();
    ImmutableSet.Builder<BuildTarget> rules = ImmutableSet.builder();

    for (CxxPreprocessorInput input : inputs) {
        preprocessorFlags.putAll(input.getPreprocessorFlags());
        headers.addAll(input.getIncludes());
        frameworks.addAll(input.getFrameworks());
        rules.addAll(input.getRules());// w  w  w. j  a  v a2 s .  c  om
    }

    return CxxPreprocessorInput.of(preprocessorFlags.build(), headers.build(), frameworks.build(),
            rules.build());
}

From source file:org.jclouds.gogrid.binders.BindRealIpPortPairsToQueryParams.java

@SuppressWarnings({ "unchecked" })
@Override// w  w  w  . j a va 2 s.  c o m
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
    checkArgument(checkNotNull(input, "input is null") instanceof List,
            "this binder is only valid for a List argument");

    List<IpPortPair> ipPortPairs = (List<IpPortPair>) input;
    ImmutableMultimap.Builder<String, String> builder = ImmutableMultimap.<String, String>builder();

    int i = 0;
    for (IpPortPair ipPortPair : ipPortPairs) {
        checkNotNull(ipPortPair.getIp(), "There must be an IP address defined");
        checkNotNull(ipPortPair.getIp().getIp(), "There must be an IP address defined in Ip object");
        checkState(ipPortPair.getPort() > 0, "The port number must be a positive integer");

        builder.put(REAL_IP_LIST_KEY + i + ".ip", ipPortPair.getIp().getIp());
        builder.put(REAL_IP_LIST_KEY + i + ".port", String.valueOf(ipPortPair.getPort()));
        i++;
    }
    return (R) request.toBuilder().replaceQueryParams(builder.build()).build();
}

From source file:com.qualys.feign.jaxrs.BeanParamTransformerFactory.java

Multimap<String, Annotation> getNames(Annotation[] annotations) {
    ImmutableMultimap.Builder<String, Annotation> names = ImmutableMultimap.builder();
    for (Annotation annotation : annotations) {
        Class<?> cls = annotation.getClass();
        if (QueryParam.class.isAssignableFrom(cls))
            names.put(((QueryParam) annotation).value(), annotation);

        if (FormParam.class.isAssignableFrom(cls))
            names.put(((FormParam) annotation).value(), annotation);

        if (HeaderParam.class.isAssignableFrom(cls))
            names.put(((HeaderParam) annotation).value(), annotation);

        if (PathParam.class.isAssignableFrom(cls))
            names.put(((PathParam) annotation).value(), annotation);
    }/*from   www  .  j  a  v a2 s.c o  m*/

    return names.build();
}

From source file:org.ambraproject.wombat.config.site.SiteSet.java

private static ImmutableMultimap<String, Site> groupByJournalKey(Set<Site> sites) {
    ImmutableMultimap.Builder<String, Site> builder = ImmutableMultimap.builder();
    for (Site site : sites) {
        builder.put(site.getJournalKey(), site);
    }//from   www  .ja  v a  2s. c o  m
    return builder.build();
}

From source file:me.lucko.luckperms.api.context.ImmutableContextSet.java

/**
 * Creates a ImmutableContextSet from an existing map
 *
 * @param map the map to copy from//from   ww  w.j a va  2  s  . c o m
 * @return a new ImmutableContextSet representing the pairs from the map
 * @throws NullPointerException if the map is null
 */
public static ImmutableContextSet fromMap(Map<String, String> map) {
    if (map == null) {
        throw new NullPointerException("map");
    }

    ImmutableMultimap.Builder<String, String> b = ImmutableMultimap.builder();
    for (Map.Entry<String, String> e : map.entrySet()) {
        b.put(e.getKey(), e.getValue());
    }

    return new ImmutableContextSet(b.build());
}

From source file:com.wrmsr.search.dsl.util.ImmutableCollectors.java

public static <I, K, V> Collector<I, ImmutableMultimap.Builder<K, V>, ImmutableMultimap<K, V>> toImmutableMultimap(
        Function<I, K> keyMapper, Function<I, V> valueMapper) {
    return Collector.of(ImmutableMultimap::builder,
            (builder, in) -> builder.put(keyMapper.apply(in), valueMapper.apply(in)),
            (ImmutableMultimap.Builder<K, V> left, ImmutableMultimap.Builder<K, V> right) -> left
                    .putAll(right.build()),
            ImmutableMultimap.Builder<K, V>::build);
}

From source file:org.jclouds.util.Multimaps2.java

/**
 * change the keys but keep the values in-tact.
 * /* w  ww.j  a v  a  2 s.  c o m*/
 * @param <K1>
 *           input key type
 * @param <K2>
 *           output key type
 * @param <V>
 *           value type
 * @param in
 *           input map to transform
 * @param fn
 *           how to transform the values
 * @return immutableMap with the new keys.
 */
public static <K1, K2, V> Multimap<K2, V> transformKeys(Multimap<K1, V> in, Function<K1, K2> fn) {
    checkNotNull(in, "input map");
    checkNotNull(fn, "function");
    Builder<K2, V> returnVal = ImmutableMultimap.builder();
    for (Entry<K1, V> entry : in.entries())
        returnVal.put(fn.apply(entry.getKey()), entry.getValue());
    return returnVal.build();
}

From source file:grakn.core.graql.reasoner.pattern.RelationPattern.java

/**
 *
 * @param rpConf configuration of rolePlayers in the form (role, variable) -> (role player type)
 * @param ids list of roleplayer ids//  ww w  . j a va2s . c  om
 * @param relIds list of relation ids
 */
protected RelationPattern(Multimap<RelationProperty.RolePlayer, Label> rpConf, List<ConceptId> ids,
        List<ConceptId> relIds) {
    ImmutableMultimap.Builder<RelationProperty.RolePlayer, Pair<Label, List<ConceptId>>> builder = ImmutableMultimap
            .builder();
    rpConf.forEach((key, value) -> builder.put(key, new Pair<>(value, ids)));
    this.patterns = generateRelationPatterns(builder.build(), relIds);
}

From source file:org.jclouds.simpledb.binders.BindAttributesToIndexedFormParams.java

@Override
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
    checkArgument(checkNotNull(input, "input") instanceof Item, "this binder is only valid for AttributeMap");
    Item attributeMap = (Item) input;/*from   w  w  w  . j a  v a  2 s .c om*/

    Builder<String, String> builder = ImmutableMultimap.builder();
    int amazonOneBasedIndex = 1; // according to docs, counters must start with 1
    for (String itemName : attributeMap.getAttributes().keySet()) {

        Collection<AttributePair> c = attributeMap.getAttributes().get(itemName);
        Iterator<AttributePair> it = c.iterator();
        while (it.hasNext()) {
            AttributePair attr = it.next();
            // not null by contract

            String value = attr.getValue();

            if (value != null) {
                builder.put(format(attributeName, amazonOneBasedIndex), attr.getKey());
                builder.put(format(attributeValue, amazonOneBasedIndex), value);
                builder.put(format(attributeReplace, amazonOneBasedIndex), String.valueOf(attr.isReplace()));

            }
            amazonOneBasedIndex++;
        }

    }
    ImmutableMultimap<String, String> forms = builder.build();
    return forms.size() == 0 ? request : ModifyRequest.putFormParams(request, forms);
}

From source file:com.isotrol.impe3.core.impl.RequestParamsFactory.java

/**
 * Returns the collection of request parameters from a JAX-RS headers object.
 * @param info URI information.//from  ww w  .  j  a  v  a  2  s . com
 * @return The request query parameters.
 */
public static RequestParams of(UriInfo info) {
    Preconditions.checkNotNull(info, "The URI object cannot be null.");
    final ImmutableMultimap.Builder<CaseIgnoringString, String> builder = ImmutableMultimap.builder();
    for (Entry<String, List<String>> entry : info.getQueryParameters().entrySet()) {
        List<String> values = entry.getValue();
        if (values != null) {
            builder.putAll(CaseIgnoringString.valueOf(entry.getKey()), values);
        }
    }
    return new Immutable(builder.build());
}