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 boolean mapContainsKeyIgnoringCase(Map<String, String> map, String key) {
    if (map.containsKey(key)) {
        return true;
    }/*from   ww  w  . jav a2s  . c  o m*/
    return collectionContainsIgnoringCase(map.keySet(), key);
}

From source file:Main.java

public static void writeOutAttributesForNode(Map<?, ?> attributes, Node node) {
    if (attributes != null) {
        // Add attributes
        for (Iterator<?> i = attributes.keySet().iterator(); i.hasNext();) {
            Object key = i.next();
            Object value = attributes.get(key);
            if ((key != null) && (value != null)) {
                Attr attNode = node.getOwnerDocument().createAttribute(key.toString());
                attNode.setNodeValue(value.toString());
                node.getAttributes().setNamedItem(attNode);
            }/*www. j  a v  a 2  s  .c  o m*/
        }
    }
}

From source file:org.eclipse.swordfish.core.configuration.xml.SaxParsingPrototype.java

private static Map<String, String> flatten(Map<String, List<String>> props) {
    Map<String, String> ret = new HashMap<String, String>(props.size());
    for (String key : props.keySet()) {
        List<String> values = props.get(key);
        Assert.state(values.size() > 0);
        if (values.size() == 1) {
            ret.put(key, values.get(0));
        } else {/*from  ww  w .j a  v a 2 s.com*/
            for (int i = 0; i < values.size(); i++) {
                ret.put(key + "{" + (i + 1) + "}", values.get(i));
            }
        }
    }
    return ret;
}

From source file:edu.northwestern.bioinformatics.studycalendar.domain.Gender.java

public static String getCodeByVariation(String code) {
    Map<String, String[]> keyVariations = Gender.getGenderValueMap();
    for (String key : keyVariations.keySet()) {
        String[] variations = keyVariations.get(key);
        for (String variation : variations) {
            if (variation.equals(code.toLowerCase())) {
                return key;
            }//from ww w . j  av a2s .com
        }
    }
    return null;
}

From source file:Main.java

public static <K, V> List<K> keyToList(Map<K, V> map, int count) {
    if (isNotNull(map)) {
        if (map.size() <= count) {
            return new ArrayList<K>(map.keySet());
        } else {/* w w w .  j  ava 2  s  . c o m*/
            List<K> list = new ArrayList<K>(map.keySet());
            return list.subList(0, count);
        }
    }
    return null;
}

From source file:Main.java

public static JSONObject toJSON(Map<String, String> object) {

    JSONObject jsonObject = new JSONObject();

    for (String key : object.keySet()) {
        try {//from   w  w  w .  jav  a  2s  .  co m
            jsonObject.put(key, object.get(key));
        } catch (JSONException je) {
        }
    }
    return jsonObject;
}

From source file:Main.java

public static String mapToJson(Map<String, Object> maps) {
    StringBuffer sb = new StringBuffer();
    int size = maps.size();
    int i = 0;//  w  w w.  j  a  v a  2  s.c om
    sb.append("{");
    for (String key : maps.keySet()) {
        i++;
        sb.append("\"" + key + "\"" + ":" + "\"" + maps.get(key) + "\"");
        if (i != size) {
            sb.append(",");
        }
    }
    sb.append("}");
    return sb + "";
}

From source file:com.baasbox.db.hook.HooksManager.java

public static void enableHidePasswordHook(ODatabaseRecordTx db, boolean enable) {
    Map<ORecordHook, HOOK_POSITION> hooks = db.getHooks();
    List hs = IteratorUtils.toList(hooks.keySet().iterator());
    Iterator<ORecordHook> it = hs.iterator();
    while (it.hasNext()) {
        ORecordHook h = it.next();//from   www. ja v a2 s  . c om
        if (h instanceof HidePassword) {
            if (BaasBoxLogger.isDebugEnabled())
                BaasBoxLogger.debug("Enable: " + enable + " " + ((BaasBoxHook) h).getHookName() + " hook");
            ((HidePassword) h).enable(enable);
            break;
        }
    }
}

From source file:com.googlecode.jtiger.modules.ecside.common.HTMLOptionsUtil.java

public static String getOptionsList(Map imap, Object defaultKey, String otherAttribute) {
    StringBuffer rs = new StringBuffer();
    Iterator itor = imap.keySet().iterator();

    while (itor.hasNext()) {
        //         String key=(String)itor.next();
        //         String value=(String)imap.get(key);
        String key = String.valueOf(itor.next());

        String value = convertString(imap.get(key), "");

        String selected = "";
        if (key.equals(defaultKey)) {
            selected = "selected=\"selected\"";
        }//from  w  w  w. j  a v  a  2  s  .c  o  m
        otherAttribute = StringUtils.isBlank(otherAttribute) ? "" : " " + otherAttribute + " ";

        rs.append("<option value=\"").append(key).append("\" ").append(selected).append(otherAttribute)
                .append(" >").append(value).append("</option>\n");
    }

    return rs.toString();
}

From source file:Main.java

public static <T> Set removeRepetition(Collection<T> ts) {
    if (ts == null || ts.isEmpty()) {
        return Collections.emptySet();
    }//from w w  w . j ava  2  s  .c o m
    Map<T, Object> map = new LinkedHashMap();
    for (T t : ts) {
        if (!map.containsKey(t)) {
            map.put(t, -1);
        }
    }
    Set<T> set = map.keySet();
    return set;
}