Example usage for java.util HashMap keySet

List of usage examples for java.util HashMap keySet

Introduction

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

Prototype

public Set<K> keySet() 

Source Link

Document

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

Usage

From source file:Main.java

public static String getUrl(HashMap<String, String> params) {
    String url = null;//from www.ja  va 2 s .  co  m
    if (params != null) {
        Iterator<String> it = params.keySet().iterator();
        StringBuffer sb = null;
        while (it.hasNext()) {
            String key = it.next();
            String value = params.get(key);
            if (sb == null) {
                sb = new StringBuffer();
                sb.append("?");
            } else {
                sb.append("&");
            }
            sb.append(key);
            sb.append("=");
            sb.append(value);
        }
        url = sb.toString();
    }
    return url;
}

From source file:org.hfoss.posit.android.web.PositHttpUtils.java

/**
 * Returns the NameValuePair objects required 
 * @param nameValuesMap/*from   w  w  w.  j a  va 2  s  .  c o m*/
 * @return
 */
public static List<NameValuePair> getNameValuePairs(HashMap<String, String> nameValuesMap) {
    Iterator<String> iter = nameValuesMap.keySet().iterator();
    List<NameValuePair> nvp = new ArrayList<NameValuePair>();
    while (iter.hasNext()) {
        String key = iter.next();
        String value = nameValuesMap.get(key);
        nvp.add(new BasicNameValuePair(key, value));
    }
    return nvp;
}

From source file:Main.java

public static String wrappedContext(HashMap<String, String> context) {
    String _context = "";
    if (context == null) {
        return "";
    }/* ww  w.  j a v  a 2 s  . c om*/
    for (String key : context.keySet()) {
        _context += key + ":" + context.get(key) + ",";
    }
    _context = _context.substring(0, _context.length() - 1);
    return _context;
}

From source file:org.hfoss.posit.android.web.PositHttpUtils.java

public static List<NameValuePair> convertFindsForPost(Find find) {
    List<NameValuePair> findList = new ArrayList<NameValuePair>();
    HashMap<String, String> findMap = find.getContentMap();
    for (String key : findMap.keySet()) {
        findList.add(new BasicNameValuePair(key, findMap.get(key)));
    }/*from   www.  j a v  a2s .  c  o  m*/
    return findList;
}

From source file:Main.java

public static Element createElement(String name, HashMap<String, Object> attributes) {

    Element e = document.createElement(name);

    for (String a : attributes.keySet())
        if (attributes.get(a) instanceof String)
            e.setAttribute(a, (String) attributes.get(a));

    return e;/*from  ww  w  . j  a v  a 2  s  . c  o m*/
}

From source file:com.austin.base.commons.util.StringUtil.java

/**
 * @param map ?HashMap/*w  ww . j  a  v a 2s .  c o m*/
 */
public static void printMap(HashMap map) {
    java.util.Iterator iterator = map.keySet().iterator();
    Object key = null;
    Object obj = null;
    while (iterator.hasNext()) {
        key = iterator.next();
        obj = map.get(key);
        System.out.println("key:" + key + " value:" + obj);

    }
}

From source file:com.sec.ose.osi.util.tools.Tools.java

public static ArrayList<String> sortByValue(final HashMap<String, Integer> map) {
    ArrayList<String> key = new ArrayList<String>();
    key.addAll(map.keySet());
    Collections.sort(key, new Comparator<Object>() {
        public int compare(Object o1, Object o2) {
            Integer v1 = map.get(o1);
            Integer v2 = map.get(o2);
            return v1.compareTo(v2);
        }/*from www. j a va  2  s  . com*/
    });
    Collections.reverse(key);
    return key;
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static Bundle addMapToBundle(HashMap<String, ?> map, Bundle bundle) {
    for (String key : map.keySet()) {
        Object value = map.get(key);
        if (value instanceof String) {
            bundle.putString(key, (String) value);
        } else if (value instanceof Integer) {
            bundle.putInt(key, (Integer) value);
        } else if (value instanceof Double) {
            bundle.putDouble(key, ((Double) value));
        } else if (value instanceof Boolean) {
            bundle.putBoolean(key, (Boolean) value);
        } else if (value instanceof HashMap) {
            bundle.putBundle(key, addMapToBundle((HashMap<String, Object>) value, new Bundle()));
        } else if (value instanceof ArrayList) {
            putArray(key, (ArrayList) value, bundle);
        }/*from w ww. j  av a2s. co  m*/
    }
    return bundle;
}

From source file:Main.java

/**
 * Processes the POST request from the client instructing the server to process 
 * a serverStart or serverProxy. Returns the fields in this request as a HashMap for
 * easy handling./*from   w  ww  .  ja  va  2 s .c o m*/
 * 
 * @param xmlStream the InputStream obtained from an HttpServletRequest object. This contains the desired pipeline from the client.
 * @param search a HashMap with arbitrary names as keys and XPath Strings as values, the results of which are assigned as values to the names in the returned HashMap. 
 * @return
 */
public static HashMap<String, String> procPipelineReq(InputStream xmlStream, HashMap<String, String> search) {
    HashMap<String, String> returnHash = new HashMap<String, String>();
    try {
        for (String item : search.keySet()) {
            Document xmlDoc = parse(xmlStream);
            XPath xpath = xpathFactory.newXPath();
            returnHash.put(item, xpath.evaluate(search.get(item), xmlDoc));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return returnHash;
}

From source file:Main.java

/**
 * @param localMap/*from  w ww. j  av a 2  s. com*/
 */
private static void initList(final HashMap<Integer, Integer> localMap) {
    List<Integer> list = new ArrayList<Integer>(localMap.keySet());
    Collections.sort(list);
    Integer min = list.get(0);
    Integer max = list.get(list.size() - 1);
    factor = max + 1;
    System.out.println(factor);
}