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:com.zimbra.soap.adminext.type.Attr.java

public static List<Attr> fromMultimap(Multimap<String, String> attrMap) {
    List<Attr> attrs = new ArrayList<Attr>();
    if (attrMap != null) {
        for (Map.Entry<String, String> entry : attrMap.entries()) {
            attrs.add(new Attr(entry.getKey(), entry.getValue()));
        }//ww  w .  j  ava  2 s . c  om
    }
    return attrs;
}

From source file:cuchaz.enigma.analysis.EntryRenamer.java

public static <Key, Val> void renameClassesInMultimap(Map<String, String> renames, Multimap<Key, Val> map) {
    // for each key/value pair...
    Set<Map.Entry<Key, Val>> entriesToAdd = Sets.newHashSet();
    for (Map.Entry<Key, Val> entry : map.entries()) {
        entriesToAdd.add(new AbstractMap.SimpleEntry<>(renameClassesInThing(renames, entry.getKey()),
                renameClassesInThing(renames, entry.getValue())));
    }//from   w w  w .  j av  a2s .  com
    map.clear();
    for (Map.Entry<Key, Val> entry : entriesToAdd) {
        map.put(entry.getKey(), entry.getValue());
    }
}

From source file:cuchaz.enigma.analysis.EntryRenamer.java

public static <Key, Val> void renameMethodsInMultimap(Map<MethodEntry, MethodEntry> renames,
        Multimap<Key, Val> map) {
    // for each key/value pair...
    Set<Map.Entry<Key, Val>> entriesToAdd = Sets.newHashSet();
    for (Map.Entry<Key, Val> entry : map.entries()) {
        entriesToAdd.add(new AbstractMap.SimpleEntry<>(renameMethodsInThing(renames, entry.getKey()),
                renameMethodsInThing(renames, entry.getValue())));
    }//from   ww w. java2s . c om
    map.clear();
    for (Map.Entry<Key, Val> entry : entriesToAdd) {
        map.put(entry.getKey(), entry.getValue());
    }
}

From source file:brooklyn.networking.cloudstack.HttpUtil.java

public static HttpToolResponse httpPost(HttpClient httpClient, URI uri, Multimap<String, String> headers,
        byte[] body) {
    HttpPost httpPost = new HttpPost(uri);
    for (Map.Entry<String, String> entry : headers.entries()) {
        httpPost.addHeader(entry.getKey(), entry.getValue());
    }/*ww  w .j  av  a 2s.  c  om*/
    if (body != null) {
        HttpEntity httpEntity = new ByteArrayEntity(body);
        httpPost.setEntity(httpEntity);
    }

    long startTime = System.currentTimeMillis();
    try {
        HttpResponse httpResponse = httpClient.execute(httpPost);

        try {
            return new HttpToolResponse(httpResponse, startTime);
        } finally {
            EntityUtils.consume(httpResponse.getEntity());
        }
    } catch (Exception e) {
        throw Exceptions.propagate(e);
    }
}

From source file:com.google.cloud.dataflow.sdk.options.PipelineOptionsReflector.java

/**
 * Retrieve metadata for the full set of pipeline options visible within the type hierarchy
 * of a single {@link PipelineOptions} interface.
 *
 * @see PipelineOptionsReflector#getOptionSpecs(Iterable)
 *///from w  ww .jav  a2s . c om
static Set<PipelineOptionSpec> getOptionSpecs(Class<? extends PipelineOptions> optionsInterface) {
    Iterable<Method> methods = ReflectHelpers.getClosureOfMethodsOnInterface(optionsInterface);
    Multimap<String, Method> propsToGetters = getPropertyNamesToGetters(methods);

    ImmutableSet.Builder<PipelineOptionSpec> setBuilder = ImmutableSet.builder();
    for (Map.Entry<String, Method> propAndGetter : propsToGetters.entries()) {
        String prop = propAndGetter.getKey();
        Method getter = propAndGetter.getValue();

        @SuppressWarnings("unchecked")
        Class<? extends PipelineOptions> declaringClass = (Class<? extends PipelineOptions>) getter
                .getDeclaringClass();

        if (!PipelineOptions.class.isAssignableFrom(declaringClass)) {
            continue;
        }

        if (declaringClass.isAnnotationPresent(Hidden.class)) {
            continue;
        }

        setBuilder.add(PipelineOptionSpec.of(declaringClass, prop, getter));
    }

    return setBuilder.build();
}

From source file:org.immutables.sequence.Entries.java

public static <K, V> Entries<K, V> from(Multimap<? extends K, ? extends V> map) {
    return from(map.entries());
}

From source file:org.agorava.core.utils.URLUtils.java

/**
 * @param parameters map to build the query string from
 * @return a query string corresponding to the map
 *//*from   w w  w.j av a2 s  . c o m*/
private static String mapToQueryString(Multimap<String, Object> parameters) {
    if (parameters.size() == 0)
        return EMPTY_STRING;
    Multimap<String, String> urlEncodeMap = Multimaps.transformValues(parameters, new formUrlEncodeFunc());
    return queryMapJoiner.join(urlEncodeMap.entries());
}

From source file:com.zimbra.soap.type.KeyValuePair.java

public static List<KeyValuePair> fromMultimap(Multimap<String, String> keyValuePairMap) {
    List<KeyValuePair> keyValuePairs = new ArrayList<KeyValuePair>();
    if (keyValuePairMap != null) {
        for (Map.Entry<String, String> entry : keyValuePairMap.entries()) {
            keyValuePairs.add(new KeyValuePair(entry.getKey(), entry.getValue()));
        }/*  w ww . j a  v a2s  . c o m*/
    }
    return keyValuePairs;
}

From source file:org.opendaylight.controller.sal.binding.impl.util.MapUtils.java

public static <P extends Path<P>, V extends Object> Collection<Entry<? extends P, ? extends V>> getAllChildren(
        final Multimap<? extends P, ? extends V> map, final P path) {
    HashSet<Entry<? extends P, ? extends V>> _hashSet = new HashSet<Entry<? extends P, ? extends V>>();
    final HashSet<Entry<? extends P, ? extends V>> ret = _hashSet;
    final Collection<? extends Entry<? extends P, ? extends V>> entries = map.entries();
    for (final Entry<? extends P, ? extends V> entry : entries) {
        {//  w  w  w.j  ava  2 s  . c  om
            final P currentPath = entry.getKey();
            if (path.contains(currentPath)) {
                ret.add(entry);
            } else if (currentPath.contains(path)) {
                ret.add(entry);
            }
        }
    }
    return ret;
}

From source file:org.jclouds.glacier.util.AWSRequestSignerV4.java

private static String buildCanonicalizedHeadersString(Multimap<String, String> canonicalizedHeadersMap) {
    StringBuilder canonicalizedHeadersBuffer = new StringBuilder();
    for (Entry<String, String> header : canonicalizedHeadersMap.entries()) {
        String key = header.getKey();
        canonicalizedHeadersBuffer.append(key.toLowerCase()).append(':').append(header.getValue()).append('\n');
    }// w w  w . j  ava2 s .  c o m
    return canonicalizedHeadersBuffer.toString();
}