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:de.zib.gndms.stuff.misc.LanguageAlgebra.java

public static MultiValueMap<String, String> getMultiValueMapFromMap(Map<String, String> map) {
    MultiValueMap<String, String> multiMap = new LinkedMultiValueMap<String, String>(map.size());

    for (String k : map.keySet()) {
        multiMap.add(k, map.get(k));/*from  w w  w  .  ja  va 2s .  co  m*/
    }

    return multiMap;
}

From source file:Main.java

/**
 * @return clear map of pressing time values, discard wrong values
 *///  w w w .  j  ava  2s. c  o  m
public static Map<String, Long> discardingOutliers(Map<String, Long> pressingLength, List<Double> dispersion,
        List<Double> mathExpectation) {
    Map<String, Long> clear = new HashMap<String, Long>();
    int i = 0;
    for (String key : pressingLength.keySet()) {
        if ((pressingLength.get(key) >= (mathExpectation.get(i) - 3 * sqrt(dispersion.get(i))))
                && (pressingLength.get(key) <= (mathExpectation.get(i) + 3 * sqrt(dispersion.get(i++))))) {
            clear.put(key, pressingLength.get(key));
        }
    }
    return clear;
}

From source file:Main.java

public static void mapToAndroidLayoutMapper(Class classObj, Map map, String prefixStr, Activity view) {

    if (map == null) {
        return;/*from   w ww. j  a va2  s  . c  o  m*/
    }

    for (Object keyObj : map.keySet().toArray()) {
        String keyStr = keyObj.toString();
        Field fieldObj = null;
        try {
            fieldObj = classObj.getField(prefixStr + "_" + keyStr);
        } catch (NoSuchFieldException e) {
            continue;
        }
        Object layoutObj = null;
        try {
            layoutObj = fieldObj.get(fieldObj);
        } catch (IllegalAccessException e) {
            continue;
        }
        Integer layoutIntvalue = (Integer) layoutObj;

        View selectedView = view.findViewById(layoutIntvalue);

        if (selectedView instanceof TextView) {
            TextView textView = (TextView) selectedView;
            textView.setText((String) map.get(keyStr));
        } else if (selectedView instanceof ImageView) {
            ImageView imageView = (ImageView) selectedView;

        }

    }

}

From source file:Main.java

public static void applyProperties(Object paramObject, Element paramElement) {
    Map<String, Object> localMap = getProperties(paramElement);
    Iterator<String> iterator = localMap.keySet().iterator();
    Field[] arrayOfField = paramObject.getClass().getFields();
    Method[] arrayOfMethod = paramObject.getClass().getMethods();
    while (iterator.hasNext()) {
        String str = iterator.next();
        Object localObject = localMap.get(str);
        try {//from   w  w w.j  av  a2 s  .  c o m
            for (int i = 0; i < arrayOfField.length; ++i) {
                if ((!arrayOfField[i].getName().equalsIgnoreCase(str))
                        || (!isTypeMatch(arrayOfField[i].getType(), localObject.getClass())))
                    continue;
                arrayOfField[i].set(paramObject, localObject);
                System.err.println("Set field " + arrayOfField[i].getName() + "=" + localObject);
                break;
            }
            for (int i = 0; i < arrayOfMethod.length; ++i) {
                if ((!arrayOfMethod[i].getName().equalsIgnoreCase("set" + str))
                        || (arrayOfMethod[i].getParameterTypes().length != 1)
                        || (!isTypeMatch(arrayOfMethod[i].getParameterTypes()[0], localObject.getClass())))
                    continue;
                arrayOfMethod[i].invoke(paramObject, new Object[] { localObject });
                System.err.println("Set method " + arrayOfMethod[i].getName() + "=" + localObject);
                break;
            }
        } catch (Exception localException) {
            System.err.println("Unable to apply property '" + str + "': " + localException.toString());
        }
    }
}

From source file:max.hubbard.bettershops.Utils.ItemUtils.java

public static String getEnchants(ItemStack i) {
    List<String> e = new ArrayList<String>();
    Map<Enchantment, Integer> en = i.getEnchantments();
    for (Enchantment t : en.keySet()) {
        e.add(t.getName() + ":" + en.get(t));
    }//from ww  w.j a v a  2s  .c o m
    return StringUtils.join(e, ",");
}

From source file:Main.java

private static void toXMLCycle(Object element, StringBuffer xml, StringBuffer space) {
    if (element instanceof Map) {
        Map map = (Map) element;

        xml.append(space);/*from  w w  w. j a v a  2s .  c o  m*/
        xml.append("<dict>\r\n");
        space.append("  ");
        for (Object key : map.keySet()) {
            xml.append(space);
            xml.append("<key>");
            xml.append(key.toString());
            xml.append("</key>\r\n");

            Object value = map.get(key);
            toXMLCycle(value, xml, space);
        }

        space.delete(0, 2);
        xml.append(space);
        xml.append("</dict>\r\n");

    } else if (element instanceof List) {
        xml.append(space);
        xml.append("<array>\r\n");
        space.append("  ");

        List list = (List) element;
        for (Object item : list) {
            toXMLCycle(item, xml, space);
        }

        space.delete(0, 2);
        xml.append(space);
        xml.append("</array>\r\n");

    } else {
        xml.append(space);
        xml.append("<string>");
        xml.append(element.toString());
        xml.append("</string>\r\n");
    }
}

From source file:Main.java

@SuppressWarnings("rawtypes")
public static void print(Map map) {
    if (isNotNull(map)) {
        System.out.println("********************************************");
        for (Object key : map.keySet()) {
            Object value = map.get(key);
            if (value instanceof Collection) {
                print((Map) value);
            } else {
                System.out.println("Key=" + key + "; Value=" + value);
            }//ww w.  ja v  a  2  s. c om
        }
        return;
    }
}

From source file:Main.java

private static byte[] createZip(Map<String, byte[]> files) throws IOException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    ZipOutputStream zf = new ZipOutputStream(bos);
    Iterator<String> it = files.keySet().iterator();
    String fileName = null;//from  w  w  w  . j  a  v a 2s. c  o m
    ZipEntry ze = null;

    while (it.hasNext()) {
        fileName = it.next();
        ze = new ZipEntry(fileName);
        zf.putNextEntry(ze);
        zf.write(files.get(fileName));
    }
    zf.close();

    return bos.toByteArray();
}

From source file:com.ning.billing.recurly.model.RecurlyObject.java

public static Boolean booleanOrNull(@Nullable final Object object) {
    if (isNull(object)) {
        return null;
    }//from w ww  .jav  a  2s  .c  o  m

    // Booleans are represented as objects (e.g. <display_quantity type="boolean">false</display_quantity>), which Jackson
    // will interpret as an Object (Map), not Booleans.
    if (object instanceof Map) {
        final Map map = (Map) object;
        if (map.keySet().size() == 2 && "boolean".equals(map.get("type"))) {
            return Boolean.valueOf((String) map.get(""));
        }
    }

    return Boolean.valueOf(object.toString());
}

From source file:com.ning.billing.recurly.model.RecurlyObject.java

public static Integer integerOrNull(@Nullable final Object object) {
    if (isNull(object)) {
        return null;
    }/*from   w w  w.j  a  va 2  s .c om*/

    // Integers are represented as objects (e.g. <year type="integer">2015</year>), which Jackson
    // will interpret as an Object (Map), not Integers.
    if (object instanceof Map) {
        final Map map = (Map) object;
        if (map.keySet().size() == 2 && "integer".equals(map.get("type"))) {
            return Integer.valueOf((String) map.get(""));
        }
    }

    return Integer.valueOf(object.toString());
}