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

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

Introduction

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

Prototype

Collection<Map.Entry<K, V>> entries();

Source Link

Document

Returns a view collection of all key-value pairs contained in this multimap, as Map.Entry instances.

Usage

From source file:org.eclipse.papyrus.uml.diagram.activity.activitygroup.utils.DebugUtils.java

/**
 * Display a multi map/* w w w  .ja  va 2 s.c  om*/
 * 
 * @param message
 * @param multimap
 */
public static void displayMultipmapDebug(String message, Multimap<EReference, EObject> multimap) {
    if (DebugUtils.isDebugging()) {
        DebugUtils.getLog().debug(message);
        for (Entry<EReference, EObject> e : multimap.entries()) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(Utils.getCorrectLabel(e.getValue()));
            stringBuilder.append(" --> ");
            stringBuilder.append(e.getKey().getName());
            DebugUtils.getLog().debug(stringBuilder.toString());
        }
    }
}

From source file:io.blobkeeper.server.util.MetadataParser.java

public static void copyMetadata(@NotNull Multimap<String, String> headers, @NotNull HttpResponse response) {
    HttpHeaders httpHeaders = response.headers();
    for (Map.Entry<String, String> elt : headers.entries()) {
        if (elt.getKey().equals(AUTH_TOKEN_HEADER)) {
            continue;
        }//www .ja va  2  s .  c o m

        if (elt.getKey().equals(CONTENT_TYPE_HEADER)) {
            httpHeaders.add(CONTENT_TYPE, elt.getValue());
        } else {
            httpHeaders.add(elt.getKey(), elt.getValue());
        }
    }
}

From source file:com.facebook.buck.android.exopackage.ExopackageUtil.java

public static ImmutableMultimap<Path, Path> applyFilenameFormat(Multimap<String, Path> filesToHashes,
        Path deviceDir, String filenameFormat) {
    ImmutableMultimap.Builder<Path, Path> filesBuilder = ImmutableMultimap.builder();
    for (Map.Entry<String, Path> entry : filesToHashes.entries()) {
        filesBuilder.put(deviceDir.resolve(String.format(filenameFormat, entry.getKey())), entry.getValue());
    }//  ww w.j  av  a2 s .  c o m
    return filesBuilder.build();
}

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

public static String replaceTokens(String input, Multimap<String, ?> tokenValues) {
    for (Entry<String, ?> tokenValue : tokenValues.entries()) {
        Pattern pattern = TOKEN_TO_PATTERN.getUnchecked(tokenValue.getKey());
        input = replaceAll(input, pattern, tokenValue.getValue().toString());
    }/*  w  w  w .j a  v a 2 s .c  o  m*/
    return input;
}

From source file:com.addthis.basis.util.MultidictUtil.java

/**
 * serialize a string map to url query format
 *
 * @param map/*from ww  w  . j av  a2s. c o  m*/
 * @return map contents in key1=value1&key2=value2 format
 */
public static String toString(Multimap<String, String> map) {
    StringBuilder sb = new StringBuilder();
    for (Iterator<Map.Entry<String, String>> i = map.entries().iterator(); i.hasNext();) {
        Map.Entry<String, String> entry = i.next();
        if (entry.getValue() == null) {
            sb.append(urlEncode(entry.getKey()));
        } else {
            sb.append(urlEncode(entry.getKey())).append("=").append(urlEncode(entry.getValue()));
        }
        if (i.hasNext()) {
            sb.append("&");
        }
    }
    return sb.toString();
}

From source file:eu.tomylobo.routes.util.Ini.java

private static void saveSection(BufferedWriter stream, Multimap<String, String> section) throws IOException {
    for (Entry<String, String> entry : section.entries()) {
        stream.write(entry.getKey());/*from ww  w  .j  a  v a2 s .  c o  m*/
        stream.write("=");
        stream.write(entry.getValue());
        stream.newLine();
    }
}

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

/**
 * change the keys but keep the values in-tact.
 * //w  ww . j ava 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:brooklyn.networking.cloudstack.HttpUtil.java

public static HttpToolResponse httpGet(HttpClient httpClient, URI uri, Multimap<String, String> headers) {
    HttpGet httpGet = new HttpGet(uri);
    for (Map.Entry<String, String> entry : headers.entries()) {
        httpGet.addHeader(entry.getKey(), entry.getValue());
    }/*  w ww  .j  a v a 2 s  . c o m*/

    long startTime = System.currentTimeMillis();
    try {
        HttpResponse httpResponse = httpClient.execute(httpGet);
        try {
            return new HttpToolResponse(httpResponse, startTime);
        } finally {
            EntityUtils.consume(httpResponse.getEntity());
        }
    } catch (Exception e) {
        throw Exceptions.propagate(e);
    }
}

From source file:com.palantir.common.streams.KeyedStream.java

/**
 * Returns a keyed stream of {@code multimap}'s entries.
 *///w w  w .  j a  v  a2 s. c om
static <K, V> KeyedStream<K, V> stream(Multimap<K, V> multimap) {
    return new KeyedStreamImpl<>(multimap.entries().stream());
}

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

private static String buildQueryLine(Multimap<String, ?> queryParams, AppendParam appendParam) {
    StringBuilder queryBuilder = appendParam.b;
    for (Entry<String, ?> pair : queryParams.entries()) {
        queryBuilder.append('&');
        appendParam.appendKey(pair.getKey());
        if (pair.getValue() != null)
            queryBuilder.append('=');
        if (pair.getValue() != null && !pair.getValue().equals("")) {
            appendParam.appendValue(pair.getValue());
        }//from w  ww . j  av a 2 s.c  o m
    }
    queryBuilder.deleteCharAt(0);
    return queryBuilder.toString();
}