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

public static <K> Map<K, Integer> uniomCounterMap(Map<? extends K, Integer> first,
        Map<? extends K, Integer> second) {
    Map<K, Integer> ret = new HashMap<K, Integer>(first);
    for (K key : second.keySet()) {
        if (ret.containsKey(key)) {
            ret.put(key, ret.get(key) + second.get(key));
        } else {//from w w w.ja  v  a  2s  .  c om
            ret.put(key, second.get(key));
        }
    }
    return ret;
}

From source file:Main.java

static int[] getSwitchKeys(Map buckets) {
    int[] keys = new int[buckets.size()];
    int index = 0;
    for (Iterator it = buckets.keySet().iterator(); it.hasNext();) {
        keys[index++] = ((Integer) it.next()).intValue();
    }//from  ww  w  .j av a2  s.com
    Arrays.sort(keys);
    return keys;
}

From source file:Main.java

public static boolean containsMap(Map mainMap, Map keyMap) {
    boolean b = true;
    if (mainMap != null && keyMap != null) {
        Set set = keyMap.keySet();
        for (Iterator iter = set.iterator(); iter.hasNext();) {
            String key = (String) iter.next();
            String mainValue = (String) mainMap.get(key);
            String keyValue = (String) keyMap.get(key);
            if (!mainValue.equals(keyValue)) {
                b = false;/*w w  w . j a  v  a2s.c o m*/
            }
        }
    } else {
        b = false;
    }
    return b;
}

From source file:Main.java

/**
 * Check whether map contains value//ww  w . ja v a  2 s.c  o m
 *
 * @param map specified map
 * @return boolean value
 */
public static boolean isEmpty(Map map) {
    boolean isEmpty = true;
    if (map != null) {
        Set keySet = map.keySet();
        Iterator it = keySet.iterator();
        while (it.hasNext()) {
            if (map.get(it.next()) != null) {
                isEmpty = false;
                break;
            }
        }
    }
    return isEmpty;
}

From source file:Main.java

public static Map<String, Object> getProperties(Map<String, Object> map) {
    Map<String, Object> propertiesMap = new HashMap<String, Object>();
    for (String key : map.keySet()) {
        if (!key.startsWith("__")) {
            propertiesMap.put(key, map.get(key));
        }// w w  w. ja v a  2  s  . c o  m
    }
    return propertiesMap;
}

From source file:Main.java

public static String stringifyParams(Map<String, String> params) {
    int pos = 0;/*from  ww  w .j  a  v  a 2 s .co m*/

    String paramsString = "";

    for (String key : params.keySet()) {
        if (pos == 0) {
            paramsString += key + "=" + params.get(key);
        } else {
            paramsString += "&" + key + "=" + params.get(key);
        }

        pos++;
    }

    return paramsString;
}

From source file:Main.java

public static Intent makeIntent(Context context, Class<?> classInstance, Map<String, Object> param) {
    Intent intent = new Intent(context, classInstance);
    for (Object obj : param.keySet().toArray()) {
        String key = (String) obj;
        intent.putExtra(key, (String) param.get(key));
    }/*from ww w .  j  a  v  a2s . co m*/

    return intent;

}

From source file:Main.java

public static String getMaximumKey(Map<String, Double> input) {
    String bestFeature = null;// ww w . j  a  v a2  s  . co  m
    Double bestValue = null;
    for (String feature : input.keySet()) {
        if (bestValue == null || bestValue.compareTo(input.get(feature)) < 0) {
            bestFeature = feature;
            bestValue = input.get(feature);
        }
    }
    return bestFeature;
}

From source file:Main.java

/**
 * This method returns the namespace associated with the supplied prefix.
 * /*w  ww . jav a  2  s.c  om*/
 * @param prefix The prefix
 * @param nsMap The existing namespace prefix mappings
 * @return The namespace
 */
public static String getNamespaceForPrefix(String prefix, java.util.Map<String, String> nsMap) {
    String ret = null;

    for (String namespace : nsMap.keySet()) {
        String p = nsMap.get(namespace);

        if (prefix.equals(p)) {
            ret = namespace;
            break;
        }
    }

    return (ret);
}

From source file:Main.java

/**
 * This function takes the Map generated by the calculateEntityReplacements function, and uses those values to replace any entities in the XML string with
 * their unique random integer replacements. The end results is an XML string that contains no entities, but contains identifiable strings that can be used
 * to replace those entities at a later point.
 * /*from  w w  w .j av a 2s .  co m*/
 * @param replacements
 *            The Map generated by the calculateEntityReplacements function
 * @param xml
 *            The XML string to modify
 * @return The modified XML
 */
private static String replaceEntities(final Map<String, String> replacements, final String xml) {
    String retValue = xml;
    for (final String entity : replacements.keySet())
        retValue = retValue.replaceAll("\\&" + entity + ";", replacements.get(entity));
    return retValue;
}