Example usage for java.util Map entrySet

List of usage examples for java.util Map entrySet

Introduction

In this page you can find the example usage for java.util Map entrySet.

Prototype

Set<Map.Entry<K, V>> entrySet();

Source Link

Document

Returns a Set view of the mappings contained in this map.

Usage

From source file:Main.java

/**
 * Busca por um determinado string numa tabela de espalhamento
 * /*from   w ww . j  a v a 2  s.c  o  m*/
 * @param map
 * @param newString
 * @return
 */
public static String searchStrStr(Map<String, String> map, String newString) {
    String foundedString = null;

    for (Map.Entry<String, String> entry : map.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();

        if (key.equals(newString)) {
            foundedString = value;
            break;
        }
    }

    return foundedString;
}

From source file:Main.java

public static void addAttributes(Element element, Map<String, Object> map) {
    if (map != null) {
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            Object attrValue = entry.getValue();
            element.setAttribute(entry.getKey(), attrValue == null ? null : attrValue.toString());
        }/*ww  w  .ja  v a2 s  .c o  m*/
    }
}

From source file:amqp.spring.camel.component.SpringAMQPHeader.java

public static Message copyHeaders(Message msg, Map<String, Object> headers) {
    for (Map.Entry<String, Object> headerEntry : headers.entrySet()) {
        if (!msg.getMessageProperties().getHeaders().containsKey(headerEntry.getKey())) {
            msg.getMessageProperties().setHeader(headerEntry.getKey(), headerEntry.getValue());
        }// w w w  . jav a  2  s.c om
    }

    return msg;
}

From source file:amqp.spring.camel.component.SpringAMQPHeader.java

public static SpringAMQPMessage copyHeaders(SpringAMQPMessage msg, Map<String, Object> headers) {
    for (Map.Entry<String, Object> headerEntry : headers.entrySet()) {
        if (!SpringAMQPMessage.EXCHANGE_PATTERN.equals(headerEntry.getKey())) {
            msg.setHeader(headerEntry.getKey(), headerEntry.getValue());
        }//from  w  w  w.j  av a 2  s. co  m
    }

    return msg;
}

From source file:org.trustedanalytics.serviceexposer.rest.CredentialsController.java

private static Collection<Map<String, String>> getFlattenedCredentials(
        Map<String, Map<String, String>> instances) {
    return instances.entrySet().stream().map(entry -> ImmutableMap.<String, String>builder()
            .putAll(entry.getValue()).put("name", entry.getKey()).build()).collect(Collectors.toList());
}

From source file:org.apache.sling.testing.tools.junit.TestDescriptionInterceptor.java

/**
 * Adds all MDC key-value pairs as HTTP header where the key starts
 * with 'X-Sling-'// w ww  . j a  v a  2  s  .  co m
 */
private static void addSlingHeaders(HttpRequest m) {
    Map<?, ?> mdc = MDC.getCopyOfContextMap();
    if (mdc != null) {
        for (Map.Entry<?, ?> e : mdc.entrySet()) {
            Object key = e.getKey();
            if (key instanceof String && ((String) key).startsWith(SLING_HEADER_PREFIX)
                    && e.getValue() instanceof String) {
                m.addHeader((String) key, (String) e.getValue());
            }
        }
    }
}

From source file:Main.java

public static String getParams(Map<String, String> form) {
    StringBuffer params = new StringBuffer();
    int i = 0;//from  w w w . j  a  v a  2 s  .  c o m
    for (Map.Entry<String, String> entry : form.entrySet()) {
        if (i > 0) {
            params.append("&");
        }
        params.append(entry.getKey());
        params.append("=");
        params.append(entry.getValue());
        i++;
    }
    return params.toString();

}

From source file:Main.java

public static <K, V extends Comparable<? super V>> Map<K, Integer> calculateCount(Map<K, Integer> map) {
    Map<K, Integer> result = new HashMap<K, Integer>();
    for (Map.Entry<K, Integer> entry : map.entrySet()) {
        K key = entry.getKey();/* w  ww .  ja v a 2 s . c  o  m*/
        Integer value = (Integer) getValue(result, key, Integer.class);
        value++;
        result.put(key, value);
    }

    return result;
}

From source file:Main.java

/**
 * retain the keyIdMap keys not in keyValueMap.keys()
 * //from   ww w .j  a  v  a  2 s .  c o  m
 * @param keyValueMap
 * @param keyIdMap
 * @return
 */
public static <G> List<G> retainKeysNotIn(Map<String, G> keyIdMap, Map<String, ?> keyValueMap) {
    List<G> result = new ArrayList<G>();
    for (Entry<String, G> keyIdMapEntry : keyIdMap.entrySet()) {
        if (keyValueMap.get(keyIdMapEntry.getKey()) == null) {
            result.add(keyIdMapEntry.getValue());
        }
    }
    return result;
}

From source file:Main.java

public static <T> String printMapWithDelimiter(Map<T, T> map, String delimiter) {
    boolean first = true;
    StringBuilder sb = new StringBuilder();
    for (Map.Entry<T, T> entry : map.entrySet()) {
        if (first)
            first = false;//from   w w  w  . j  a  va  2s  .  co  m
        else
            sb.append(delimiter);
        sb.append(entry.getKey()).append("=").append(entry.getValue());
    }
    return sb.toString();
}