Example usage for java.util Map size

List of usage examples for java.util Map size

Introduction

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

Prototype

int size();

Source Link

Document

Returns the number of key-value mappings 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));//w  w  w.j av a 2  s .  c om
    }

    return multiMap;
}

From source file:Main.java

/***
 *
 * @param pressingLength model's length of pause between clicks (x)
 * @return Mx's values List, for My use ALPHA = 1
 *//*from  w ww.j av a  2  s  . co m*/
private static double M(Map<String, Long> pressingLength) {
    double x = 0;
    for (String key : pressingLength.keySet()) {
        x += pressingLength.get(key);
    }
    return x / pressingLength.size();
}

From source file:com.alacoder.lion.common.utils.StringTools.java

public static String toQueryString(Map<String, String> ps) {
    StringBuilder buf = new StringBuilder();
    if (ps != null && ps.size() > 0) {
        for (Map.Entry<String, String> entry : new TreeMap<String, String>(ps).entrySet()) {
            String key = entry.getKey();
            String value = entry.getValue();
            if (key != null && key.length() > 0 && value != null && value.length() > 0) {
                if (buf.length() > 0) {
                    buf.append("&");
                }//from ww  w . j  av  a2  s .c o  m
                buf.append(key);
                buf.append("=");
                buf.append(value);
            }
        }
    }
    return buf.toString();
}

From source file:Main.java

public static <KeyT, ValueT> boolean mapsEquals(Map<KeyT, ValueT> map1, Map<KeyT, ValueT> map2) {
    if (map1 == null) {
        return map2 == null || map2.isEmpty();
    }/*  w w  w.j  a  v  a2  s .  c  o  m*/
    if (map1.size() != map2.size() || !map1.keySet().containsAll(map2.keySet())) {
        return false;
    }
    for (KeyT key : map1.keySet()) {
        final ValueT value1 = map1.get(key);
        final ValueT value2 = map2.get(key);
        if (!equals(value1, value2)) {
            return false;
        }
    }
    return true;
}

From source file:Main.java

public static Intent mapToIntent(Context context, Class<?> clazz, Map<String, Object> map) {
    Intent intent = new Intent(context, clazz);
    Bundle bundle = new Bundle();
    if (map != null && map.size() > 0) {
        for (String key : map.keySet()) {
            if (map.get(key) instanceof String) {
                bundle.putString(key, (String) map.get(key));
            } else if (map.get(key) instanceof Integer) {
                bundle.putInt(key, (Integer) map.get(key));
            } else if (map.get(key) instanceof Boolean) {
                bundle.putBoolean(key, (Boolean) map.get(key));
            } else if (map.get(key) instanceof Double) {
                bundle.putDouble(key, (Double) map.get(key));
            } else if (map.get(key) instanceof Long) {
                bundle.putLong(key, (Long) map.get(key));
            } else if (map.get(key) instanceof Float) {
                bundle.putFloat(key, (Float) map.get(key));
            } else if (map.get(key) instanceof Double) {
                bundle.putDouble(key, (Double) map.get(key));
            } else if (map.get(key) instanceof Serializable) {
                bundle.putSerializable(key, (Serializable) map.get(key));
            } else if (map.get(key) instanceof Parcelable) {
                bundle.putParcelable(key, (Parcelable) map.get(key));
            }//from w w w . j a  v a2s .  com
        }
    }
    return intent.putExtras(bundle);
}

From source file:com.pinterest.deployservice.common.CommonUtils.java

public static Map<String, String> encodeScript(Map<String, String> data) throws Exception {
    Map<String, String> encoded = new HashMap<String, String>(data.size());
    for (Map.Entry<String, String> entry : data.entrySet()) {
        encoded.put(entry.getKey(), Base64.encodeBase64URLSafeString(entry.getValue().getBytes("UTF8")));
    }// w w  w. j  a v a  2s. c  o  m
    return encoded;
}

From source file:com.pinterest.deployservice.common.CommonUtils.java

public static Map<String, String> decodeScript(Map<String, String> data) throws Exception {
    Map<String, String> decoded = new HashMap<String, String>(data.size());
    for (Map.Entry<String, String> entry : data.entrySet()) {
        decoded.put(entry.getKey(), new String(Base64.decodeBase64(entry.getValue().getBytes("UTF8")), "UTF8"));
    }/* ww  w.ja  va2s  .  c  om*/
    return decoded;
}

From source file:Main.java

public static <K, V> List<K> getKeyListByValues(Map<K, V> map, V[] values) {
    if ((values == null) || (values.length == 0)) {
        return null;
    }//from  w w w  .ja  v  a  2  s.c o  m
    List<K> keyList = new ArrayList<K>(map.size());
    Set<Map.Entry<K, V>> entrySet = map.entrySet();
    for (Iterator<?> localIterator = entrySet.iterator(); localIterator.hasNext();) {
        Map.Entry<K, V> entry = (Map.Entry) localIterator.next();

        for (int i = 0; i < values.length; i++) {
            Object value = values[i];
            if ((entry.getValue() == null)
                    || ((entry.getValue() != null) && (entry.getValue().equals(value)))) {
                keyList.add(entry.getKey());
            }
        }
    }
    return keyList;
}

From source file:Main.java

/**
 * Write string string map.//from www .  java2s  .c  om
 *
 * @param map the map
 * @param os the os
 * @throws IOException Signals that an I/O exception has occurred.
 */
public static void writeStringStringMap(Map<String, String> map, OutputStream os) throws IOException {
    if (map != null) {
        writeInt(os, map.size());
        for (Map.Entry<String, String> entry : map.entrySet()) {
            writeString(os, entry.getKey());
            writeString(os, entry.getValue());
        }
    } else {
        writeInt(os, 0);
    }
}

From source file:org.xmatthew.spy2servers.core.context.ComponentContextUtils.java

@SuppressWarnings("unchecked")
public static ComponentContext getComponentContext(ApplicationContext context) {
    Map beansMap = context.getBeansOfType(Component.class);
    if (beansMap != null) {

        List<Component> components = new ArrayList<Component>(beansMap.size());
        components.addAll(beansMap.values());
        ComponentContext componentContext = new ComponentContext();
        componentContext.setComponents(components);
        return componentContext;
    }//www.  ja v  a2 s  .  c o m
    return null;
}