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:org.exoplatform.social.client.core.net.DumpHttpResponse.java

/**
 * Dump the HttpResponse content which Rest Service to return.
 * @param entity Entity to dump//from  www  . ja v  a 2 s. c o m
 * @throws ParseException
 * @throws IOException
 */
public static void dumpContent(HttpResponse response) throws SocialHttpClientException {
    String responseContent = SocialHttpClientSupport.getContent(response);
    if (responseContent.length() > 0) {
        LOGGER.debug("\n\n++++++++++CONTENT OF RESPONSE+++++++++++++++++++++++\n\n");
        LOGGER.debug("RESPONSE CONTENT::" + responseContent);
        try {
            Map contentMap = SocialJSONDecodingSupport.parser(responseContent);
            Set<Entry> list = contentMap.entrySet();
            for (Entry e : list) {
                LOGGER.debug(e.getKey() + "::" + e.getValue());
            }
        } catch (org.json.simple.parser.ParseException pex) {
            throw new SocialHttpClientException("dumpContent() is parsing error.", pex);
        }

    }
}

From source file:Main.java

/**
 * Set layout params for map of views./*  w  w  w.j  ava  2s.  c  o m*/
 * @param views
 * @param params
 */
public static void setParams(Map<Integer, ? extends View> views,
        Map<Integer, ? extends ViewGroup.LayoutParams> params) {

    for (Entry<Integer, ? extends View> entry : views.entrySet()) {
        setParams(entry.getValue(), params.get(entry.getKey()));
    }
}

From source file:Main.java

public static String parametersToWWWFormURLEncoded(Map<String, String> parameters) throws Exception {
    StringBuilder s = new StringBuilder();
    for (Map.Entry<String, String> parameter : parameters.entrySet()) {
        if (s.length() > 0) {
            s.append("&");
        }/*from   ww  w .j  a  v a 2 s . c  o  m*/
        s.append(URLEncoder.encode(parameter.getKey(), "UTF-8"));
        s.append("=");
        s.append(URLEncoder.encode(parameter.getValue(), "UTF-8"));
    }
    return s.toString();
}

From source file:Main.java

/**
 * Write a HashMap to a Parcel, class of key and value can parcelable both
 * /* w ww.jav a 2s . c  om*/
 * @param map
 * @param out
 * @param flags
 */
public static <K extends Parcelable, V extends Parcelable> void writeHashMap(Map<K, V> map, Parcel out,
        int flags) {
    if (map != null) {
        out.writeInt(map.size());

        for (Entry<K, V> entry : map.entrySet()) {
            out.writeParcelable(entry.getKey(), flags);
            out.writeParcelable(entry.getValue(), flags);
        }
    } else {
        out.writeInt(-1);
    }
}

From source file:Main.java

static String getColumnSql(Map<String, String> columns) {
    StringBuilder sb = new StringBuilder();
    int i = 0;//w w w.ja v  a2 s.  c o  m

    for (Map.Entry<String, String> entry : columns.entrySet()) {
        String key = entry.getKey();
        String value = entry.getValue();
        sb.append(key + " " + value);
        i++;
        if (i != columns.size()) {
            sb.append(", ");
        }
    }

    return sb.toString();
}

From source file:Main.java

/**
 * Copies the entries of the given source into the given target.
 *
 * @param <TKey> The type of the keys of the given target map.
 * @param <TValue> Th type of the values of the given target map.
 * @param target The given target to copy the entries to.
 * @param source The given map to copy the entries from.
 * @note In case the key already exists in the given target, the value is
 * overwritten./*  w ww.  j a  v  a 2s  . co m*/
 */
public static <TKey, TValue> void putAll(final Map<TKey, TValue> target,
        final Map<? extends TKey, ? extends TValue> source) {
    if (target != null && source != null) {
        putAll(target, source.entrySet());
    }
}

From source file:Main.java

/**
 * Write a HashMap to a Parcel, class of key and value are both String
 * /*  ww w  . j  a  v  a  2s . c om*/
 * @param map
 * @param out
 * @param flags
 */
public static void writeHashMapStringAndString(Map<String, String> map, Parcel out, int flags) {
    if (map != null) {
        out.writeInt(map.size());
        for (Entry<String, String> entry : map.entrySet()) {
            out.writeString(entry.getKey());
            out.writeString(entry.getValue());
        }
    } else {
        out.writeInt(-1);
    }
}

From source file:Main.java

public static String transMapToString(Map<String, String> map) {
    Entry<String, String> entry;
    StringBuilder sb = new StringBuilder();
    for (Iterator<Entry<String, String>> iterator = map.entrySet().iterator(); iterator.hasNext();) {
        entry = iterator.next();/*w w w  . ja  va  2s .c o m*/
        sb.append(entry.getKey().toString()).append("=")
                .append(null == entry.getValue() ? "" : entry.getValue().toString())
                .append(iterator.hasNext() ? "&" : "");
    }
    return sb.toString();
}

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

public static Message setBasicPropertiesFromHeaders(Message msg, Map<String, Object> headers) {
    for (Map.Entry<String, Object> headerEntry : headers.entrySet()) {
        String headerKey = headerEntry.getKey();
        Object headerValue = headerEntry.getValue();

        String headerValueString = null;
        if (headerValue != null) {
            headerValueString = headerValue.toString();
        }//ww w .j  a  v  a 2s  .  c o  m

        //Not switching on a string since we want to support Java >= 1.6
        if (CONTENT_ENCODING.equals(headerKey)) {
            msg.getMessageProperties().setContentEncoding(headerValueString);
        } else if (CONTENT_TYPE.equals(headerKey)) {
            msg.getMessageProperties().setContentType(headerValueString);
        } else if (CORRELATION_ID.equals(headerKey)) {
            byte[] correlationId = headerValueString != null ? headerValueString.getBytes() : null;
            msg.getMessageProperties().setCorrelationId(correlationId);
        } else if (EXPIRATION.equals(headerKey)) {
            msg.getMessageProperties().setExpiration(headerValueString);
        } else if (PRIORITY.equals(headerKey)) {
            Integer priority = headerValueString != null ? Integer.parseInt(headerValueString) : null;
            msg.getMessageProperties().setPriority(priority);
        } else if (REPLY_TO.equals(headerKey)) {
            msg.getMessageProperties().setReplyTo(headerValueString);
        } else if (TYPE.equals(headerKey)) {
            msg.getMessageProperties().setType(headerValueString);
        }
    }

    return msg;
}

From source file:Main.java

public static String fromat(Map<String, String> map, String relname, String crid) {
    StringBuffer xml = new StringBuffer();
    xml.append("<root>");
    for (Entry<String, String> en : map.entrySet()) {
        xml.append("<attr n='" + en.getKey() + "' d='text'><![CDATA[" + en.getValue() + "]]></attr>");
    }//ww  w . j a  va2  s  . c o  m
    xml.append("<rel n='" + relname + "' d='from'><![CDATA[" + crid + "]]></rel>");
    xml.append("</root>");
    return xml.toString();

}