Example usage for java.util Map keySet

List of usage examples for java.util Map keySet

Introduction

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

Prototype

Set<K> keySet();

Source Link

Document

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

Usage

From source file:Main.java

@SuppressWarnings({ "unchecked" })
public static String map2Xml(Map srcMap) {
    StringBuffer xmlBuffer = new StringBuffer("");
    Iterator ite = srcMap.keySet().iterator();
    String key;/* w  w  w . j  a v  a2 s .c o m*/
    Object obj;
    while (ite.hasNext()) {
        key = (String) ite.next();
        obj = srcMap.get(key);
        if (obj instanceof Map) {
            wrapLeftSign(xmlBuffer, key);
            xmlBuffer.append(map2Xml((Map) obj));
            wrapRightSign(xmlBuffer, key);
        } else if (obj instanceof List) {
            if (((List) obj).get(0) instanceof Map) {
                for (Map map : (List<Map>) obj) {
                    wrapLeftSign(xmlBuffer, key);
                    xmlBuffer.append(map2Xml(map));
                    wrapRightSign(xmlBuffer, key);
                }
            } else {
                for (Object something : (List<Object>) obj) {
                    wrapLeftSign(xmlBuffer, key);
                    xmlBuffer.append(something);
                    wrapRightSign(xmlBuffer, key);
                }
            }
        } else {
            wrapLeftSign(xmlBuffer, key);
            xmlBuffer.append(obj);
            wrapRightSign(xmlBuffer, key);
        }
    }
    return xmlBuffer.toString();
}

From source file:Main.java

public static void rename(Collection<Map<String, Object>> collection, Map<String, String> renames) {
    for (Map<String, Object> map : collection) {
        Object obj;//from   w w w  .ja va  2 s .com
        for (String originalName : renames.keySet()) {
            if (map.containsKey(originalName)) {
                obj = map.get(originalName);
                //Must remove first then added after
                map.remove(originalName);
                map.put(renames.get(originalName), obj);
            }
        }

    }
}

From source file:Main.java

/**
 * create an element from a document, that has some text content in it
 * @param doc - document/*from   ww  w. j  a  va 2 s .  c om*/
 * @param name - element name
 * @param attributes - attribute map
 * @return element object
 */
public static Element createElement(Document doc, String name, Map<String, String> attributes) {
    Element e = doc.createElement(name);
    for (String attribute : attributes.keySet())
        e.setAttribute(attribute, attributes.get(attribute));
    return e;
}

From source file:fr.mael.microrss.util.Tools.java

public static void merge(Map<String, Object> map1, Map<String, Object> map2) {
    for (String key : map2.keySet()) {
        map1.put(key, map2.get(key));/*from  w w  w  .  jav a2 s  .c  o  m*/
    }
}

From source file:Main.java

public static final Map<String, String> map2Type(Map<String, Object> map) {
    Map<String, String> resultMap = new HashMap<String, String>();
    Iterator<String> iterator = map.keySet().iterator();
    while (iterator.hasNext()) {
        String key = iterator.next();
        Object value = map.get(key);
        resultMap.put(key, Object2String(value));
    }/*  w  w  w.  j  ava2s.  c om*/
    return resultMap;
}

From source file:Main.java

private static void organizeAndStart(Context context, Class<?> classes, Map<String, String> paramMap) {
    intent = new Intent(context, classes);

    if (null != paramMap) {
        Set<String> set = paramMap.keySet();
        for (Iterator<String> iterator = set.iterator(); iterator.hasNext();) {
            String key = iterator.next();
            intent.putExtra(key, paramMap.get(key));
        }//from  w ww .j  a  v  a  2  s. co  m
    }
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    context.startActivity(intent);
}

From source file:com.sunrise.sup.core.common.util.URLUtil.java

/**
 * Url/*  ww  w.  jav a  2s.c  o  m*/
 * 
 * @param url
 * @param params
 * @param removeUnprintableChar
 *            ????ascii
 * @return
 */
public static String concatUrl(String url, Map params, boolean removeUnprintableChar) {
    Iterator it = params.keySet().iterator();
    while (it.hasNext()) {
        String key = it.next().toString();
        Object value = params.get(key);
        if (value instanceof Object[]) {
            Object[] temp = (Object[]) value;
            for (int i = 0; i < temp.length; i++) {
                url = concatUrl(url, key, temp[i].toString());
            }
        } else {
            url = concatUrl(url, key, value.toString());
        }
    }
    if (removeUnprintableChar) {
        return removeUnprintableChar(url);
    } else {
        return url;
    }
}

From source file:Main.java

public static String openGetConnection(String urlString, Map<String, String> map) {
    List<NameValuePair> nameValuePairs = new ArrayList<>();
    for (String key : map.keySet()) {
        nameValuePairs.add(new BasicNameValuePair(key, map.get(key)));
    }/*from www. j  a  v  a  2s.  c  o  m*/
    String params = URLEncodedUtils.format(nameValuePairs, "utf-8");
    urlString += "?";
    urlString += params;
    HttpClient client = new DefaultHttpClient();
    HttpGet get = new HttpGet(urlString);
    try {
        HttpResponse httpResponse = client.execute(get);
        BufferedReader br = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent()));
        StringBuilder json = new StringBuilder("");
        String line = null;
        while ((line = br.readLine()) != null) {
            json.append(line);
        }
        return json.toString();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:Main.java

public static String printHashMap(Map<?, ?> inSet) {
    if (inSet == null) {
        return "null";
    }//ww w.  j  a v  a2 s.c  om
    StringBuilder sb = new StringBuilder("[ ");
    Set<?> keys = inSet.keySet();
    for (Object key : keys) {
        sb.append("(key=").append(key).append(", value=").append(inSet.get(key)).append(") ");
    }
    sb.append("]");
    return sb.toString();
}

From source file:Main.java

private static void organizeAndStart(Context context, Class<?> classes, Map<String, String> paramMap) {
    intent = new Intent(context, classes);
    if (null != paramMap) {
        Set<String> set = paramMap.keySet();
        for (Iterator<String> iterator = set.iterator(); iterator.hasNext();) {
            String key = iterator.next();
            intent.putExtra(key, paramMap.get(key));
        }/*w  w w.  ja  v a 2 s.  c  o  m*/
    }
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    context.startActivity(intent);
}