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.eel.kitchen.jsonschema.MiniPerfTest2.java

private static void doValidate(final Map<String, JsonNode> schemas, final JsonSchema schema, final int i) {
    String name;/*ww  w .j  a va2 s.  com*/
    JsonNode value;
    ValidationReport report;

    for (final Map.Entry<String, JsonNode> entry : schemas.entrySet()) {
        name = entry.getKey();
        value = entry.getValue();
        report = schema.validate(value);
        if (!report.isSuccess()) {
            System.err.println("ERROR: schema " + name + " did not " + "validate (iteration " + i + ')');
            System.exit(1);
        }
    }
}

From source file:ee.ria.xroad.common.message.SoapMessageEncoder.java

private static String[] convertHeaders(Map<String, String> headers) {
    String[] ret = new String[headers.size()];
    int idx = 0;/*ww  w .  j a va  2  s .  com*/
    for (Map.Entry<String, String> entry : headers.entrySet()) {
        ret[idx++] = entry.getKey() + ": " + entry.getValue();
    }

    return ret;
}

From source file:io.cloudslang.lang.entities.utils.ValueUtils.java

public static Map<String, Serializable> flatten(Map<String, Value> valueMap) {
    Map<String, Serializable> result = null;
    if (valueMap != null) {
        result = new LinkedHashMap<>();
        for (Map.Entry<String, Value> entry : valueMap.entrySet()) {
            result.put(entry.getKey(), entry.getValue().toString());
        }//from w  w  w  .  j  ava 2 s  .  c  o  m
    }
    return result;
}

From source file:Main.java

/**
 * Add an empty element (&lt; /&gt;) to an XML document buffer.
 *
 * @param strXmlBuffer//from   ww w. j  a  v  a  2  s .  c  o m
 *            The XML document buffer
 * @param strTag
 *            The tag name of the element to add
 * @param attrList
 *            The attributes list
 */
public static void addEmptyElement(StringBuffer strXmlBuffer, String strTag, Map<?, ?> attrList) {
    strXmlBuffer.append(TAG_BEGIN);
    strXmlBuffer.append(strTag);

    if (attrList != null) {
        for (Entry<?, ?> entry : attrList.entrySet()) {
            String code = (String) entry.getKey();
            strXmlBuffer.append(
                    TAG_SEPARATOR + code + TAG_ASSIGNMENT + TAG_ENCLOSED + entry.getValue() + TAG_ENCLOSED);
        }
    }

    strXmlBuffer.append(TAG_CLOSE_END);
}

From source file:com.baidu.cc.common.JsonUtils.java

/**
 * convert map to json object.//from   www.jav a  2 s .  c  om
 * 
 * @param map
 *            key is string value will convert to string
 * @return {@link JsonObject}
 */
public static JsonObject fromSimpleMap(Map<String, Object> map) {
    JsonObject jo = new JsonObject();
    if (MapUtils.isEmpty(map)) {
        return jo;
    }

    Iterator<Entry<String, Object>> iter = map.entrySet().iterator();
    while (iter.hasNext()) {
        Entry<String, Object> entry = iter.next();
        jo.addProperty(entry.getKey(), String.valueOf(entry.getValue()));
    }
    return jo;
}

From source file:com.nci.tkb.busi.serviceimpl.RequestHandlerUtils.java

public static final Map<String, String> getRequestValue(String requestCode, Map<String, String> response)
        throws UseException {
    Map<String, String> retMap = new HashMap<String, String>();
    Map<String, String> _maps = dispache(requestCode);
    for (Map.Entry<String, String> entry : _maps.entrySet()) {
        String _key = entry.getKey();
        String _value = entry.getValue();
        String value = response.get(_key);
        if (MUST.equals(_value) && StringUtils.isBlank(value)) {
            log.info(StaticMethod.getTraceInfo());
            log.error("****************MISSING MUST CODE:" + _key);
            throw new UseException(RetCode.RETCODE_MISSING, "MISSING MUST CODE" + _key);
        } else {/* w  w w  . ja  va  2s .  c  o  m*/
            retMap.put(_key, value);
        }
    }
    return retMap;
}

From source file:Main.java

public static <K, V extends Comparable<? super V>> List<Map.Entry<K, V>> sortMapByValue(Map<K, V> map,
        final boolean reverse) {
    if (isEmpty(map)) {
        return null;
    }//w w  w. j av a  2  s .c o  m

    List<Map.Entry<K, V>> list = new ArrayList<Map.Entry<K, V>>(map.entrySet());

    Collections.sort(list, new Comparator<Map.Entry<K, V>>() {

        public int compare(Map.Entry<K, V> entry1, Map.Entry<K, V> entry2) {
            int result = entry1.getValue().compareTo(entry2.getValue());
            if (reverse) {
                result *= -1;
            }

            return result;
        }
    });

    return list;
}

From source file:Main.java

public static String Json2Str(Map<String, Object> info) {
    String result = "";
    if (info != null) {
        try {/*w  w w.  j a  va2s  . c  om*/
            JSONObject json = new JSONObject();
            for (Map.Entry<String, Object> e : info.entrySet()) {
                String key = e.getKey();
                if (json.isNull(key)) {
                    json.put(key, null);
                } else {
                    json.put(key, json.get(key));
                }
            }
            result = json.toString();
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }
    return result;
}

From source file:Main.java

static public boolean addNamespaceURIs(Document doc, Map<String, String> nsMap) {
    Element root = doc.getDocumentElement();
    if (root == null)
        return false;
    // Add Namespace attributes
    for (Entry<String, String> entry : nsMap.entrySet()) {
        root.setAttribute("xmlns:" + entry.getKey(), entry.getValue());
    }/*w  w w .ja v a  2  s  .  c  o  m*/
    return true;
}

From source file:org.cloudifysource.esc.driver.provisioning.jclouds.ProvisioningUtils.java

@SuppressWarnings("unchecked")
private static void populateMapFromBean(Map<String, String> map, Object bean, String keyPrefix)
        throws IllegalAccessException, InvocationTargetException, NoSuchMethodException {

    if (bean == null) {
        return;/*w w  w  .  java 2 s .  c o m*/
    }
    if (List.class.isAssignableFrom(bean.getClass())) {
        List<Object> list = (List<Object>) bean;
        int index = 0;
        for (Object object : list) {
            populateMapFromBean(map, object, keyPrefix + "." + index);
            ++index;
        }
    } else if (Map.class.isAssignableFrom(bean.getClass())) {
        Map<String, Object> propertyMap = (Map<String, Object>) bean;
        Set<Entry<String, Object>> entries = propertyMap.entrySet();
        for (Entry<String, Object> propertyEntry : entries) {
            populateMapFromBean(map, propertyEntry.getValue(), keyPrefix + "." + propertyEntry.getKey());
        }
    } else {
        if (org.springframework.beans.BeanUtils.isSimpleProperty(bean.getClass())) {
            if (!Class.class.isAssignableFrom(bean.getClass())) {
                map.put(keyPrefix, bean.toString());
            }
        } else {
            Map<String, Object> propertyMap = PropertyUtils.describe(bean);
            Set<Entry<String, Object>> entries = propertyMap.entrySet();
            for (Entry<String, Object> entry : entries) {
                if (keyPrefix.isEmpty()) {
                    populateMapFromBean(map, entry.getValue(), entry.getKey());
                } else {
                    populateMapFromBean(map, entry.getValue(), keyPrefix + "." + entry.getKey());
                }
            }

        }

    }

}