Example usage for com.google.common.collect Multimap replaceValues

List of usage examples for com.google.common.collect Multimap replaceValues

Introduction

In this page you can find the example usage for com.google.common.collect Multimap replaceValues.

Prototype

Collection<V> replaceValues(@Nullable K key, Iterable<? extends V> values);

Source Link

Document

Stores a collection of values with the same key, replacing any existing values for that key.

Usage

From source file:org.jclouds.http.utils.ModifyRequest.java

@SuppressWarnings("unchecked")
public static <R extends HttpRequest> R replaceHeader(R request, String header, Iterable<String> values) {
    Multimap<String, String> headers = LinkedHashMultimap.create(checkNotNull(request, "request").getHeaders());
    headers.replaceValues(checkNotNull(header, "header"), checkNotNull(values, "values"));
    return (R) request.toBuilder().headers(headers).build();
}

From source file:msi.gaml.compilation.GamlIdiomsProvider.java

public static Multimap<GamlIdiomsProvider<?>, IGamlDescription> forName(final String name) {
    final Multimap<GamlIdiomsProvider<?>, IGamlDescription> result = ArrayListMultimap.create();
    for (final GamlIdiomsProvider<?> p : PROVIDERS) {
        result.replaceValues(p, p.get(name));
    }//from  ww  w. j  a  va 2  s  . com
    return result;
}

From source file:org.jclouds.http.utils.ModifyRequest.java

@SuppressWarnings("unchecked")
public static <R extends HttpRequest> R replaceHeaders(R request, Multimap<String, String> headers) {
    Multimap<String, String> newHeaders = LinkedHashMultimap
            .create(checkNotNull(request, "request").getHeaders());
    for (String header : headers.keySet())
        newHeaders.replaceValues(header, headers.get(header));
    return (R) request.toBuilder().headers(newHeaders).build();
}

From source file:org.ambraproject.wombat.freemarker.ReplaceParametersDirective.java

@VisibleForTesting
static Multimap<String, String> replaceParameters(SimpleHash parameterMap,
        Multimap<String, TemplateModel> replacements) throws TemplateException {
    Multimap<String, String> result = HashMultimap.create();

    // The map is passed in as a Map<String, String[]>, but Freemarker doesn't support generics
    // (and wraps the map in its own data structure).
    Map map = parameterMap.toMap();
    Iterator iter = map.entrySet().iterator();
    while (iter.hasNext()) {
        Map.Entry entry = (Map.Entry) iter.next();
        String[] values = (String[]) entry.getValue();
        for (String value : values) {
            result.put((String) entry.getKey(), value);
        }//from  w w  w. j av a  2 s  .c  om
    }

    for (Map.Entry<String, Collection<TemplateModel>> replacementEntry : replacements.asMap().entrySet()) {
        Collection<String> replacementValues = Collections2.transform(replacementEntry.getValue(),
                Object::toString);
        result.replaceValues(replacementEntry.getKey(), replacementValues);
    }

    return ImmutableSetMultimap.copyOf(result);
}

From source file:org.jclouds.cloudstack.filters.QuerySigner.java

@VisibleForTesting
void addSigningParams(Multimap<String, String> params) {
    params.replaceValues("apiKey", ImmutableList.of(creds.get().identity));
    params.removeAll("signature");
}

From source file:org.jclouds.cloudstack.filters.QuerySigner.java

@VisibleForTesting
void addSignature(Multimap<String, String> params, String signature) {
    params.replaceValues("signature", ImmutableList.of(signature));
}

From source file:org.jclouds.ecs.filters.QuerySigner.java

@VisibleForTesting
void addSigningParams(Multimap<String, String> params) {
    params.replaceValues("AccessKeyId", ImmutableList.of(creds.get().identity));
    params.replaceValues("AccessKeyId", ImmutableList.of("bnF9nNdDFCTwM5mF"));
    params.replaceValues("SignatureMethod", ImmutableList.of("HMAC-SHA1"));
    params.replaceValues("Timestamp", ImmutableList.of(Timestamps.getCurrent()));
    params.replaceValues("SignatureVersion", ImmutableList.of("1.0"));
    params.replaceValues("SignatureNonce", ImmutableList.of(String.valueOf(new Random().nextInt())));
    params.removeAll("Signature");
}

From source file:org.jclouds.ecs.filters.QuerySigner.java

@VisibleForTesting
void addSignature(Multimap<String, String> params, String signature) {
    params.replaceValues("Signature", ImmutableList.of(signature));
}

From source file:org.jclouds.aws.ec2.filters.FormSigner.java

@VisibleForTesting
void addSigningParams(Multimap<String, String> params) {
    params.replaceValues(SIGNATURE_METHOD, ImmutableList.of("HmacSHA256"));
    params.replaceValues(SIGNATURE_VERSION, ImmutableList.of("2"));
    params.replaceValues(TIMESTAMP, ImmutableList.of(dateService.get()));
    params.replaceValues(AWS_ACCESS_KEY_ID, ImmutableList.of(accessKey));
    params.removeAll(SIGNATURE);/*from w  ww.j  a v a2s  . c om*/
}

From source file:org.jclouds.aws.ec2.filters.FormSigner.java

@VisibleForTesting
void addSignature(Multimap<String, String> params, String signature) {
    params.replaceValues(SIGNATURE, ImmutableList.of(signature));
}