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:Main.java

public static <K, V> List<K> keyToList(Map<K, V> map) {
    return keyToList(map, map.size());
}

From source file:Main.java

public static Object getJsonValue(String jsonStr, String key) {
    Object rulsObj = null;//w  w  w .  ja v a  2s .  c o m
    Map<?, ?> rulsMap = jsonToMap(jsonStr);
    if (rulsMap != null && rulsMap.size() > 0) {
        rulsObj = rulsMap.get(key);
    }
    return rulsObj;
}

From source file:Main.java

@SuppressWarnings("rawtypes")
public static boolean isEmpty(Map map) {
    if (null == map || "".equals(map) || map.size() < 1)
        return true;
    return false;
}

From source file:Main.java

public final static <K, V> Map<K, V> unicon(Map<K, V> map1, Map<K, V> map2) {
    Map<K, V> map = new HashMap<>(map1.size() + map2.size());
    map.putAll(map1);//from  w  ww.  jav  a2s .c  om
    map.putAll(map2);
    return map;
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T, U> T[] getKeyArray(Map<T, U> m, Class<T> clazz) {
    if (m == null || m.size() == 0) {
        T[] a = (T[]) java.lang.reflect.Array.newInstance(clazz, 0);
        return Collections.<T>emptyList().toArray(a);
    } else {// ww  w  .  j  a va 2 s  .  com
        T[] a = (T[]) java.lang.reflect.Array.newInstance(clazz, m.size());
        return m.keySet().toArray(a);
    }
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T, U> U[] getValueArray(Map<T, U> m, Class<U> clazz) {
    if (m == null || m.size() == 0) {
        U[] a = (U[]) java.lang.reflect.Array.newInstance(clazz, 0);
        return Collections.<U>emptyList().toArray(a);
    } else {// w  w  w  .j av a2s  .c  om
        U[] a = (U[]) java.lang.reflect.Array.newInstance(clazz, m.size());
        return m.values().toArray(a);
    }
}

From source file:Main.java

/**
 * Checks whether the MAP is not NULL and has at least one element.
 * /*from w w  w  .j a  v a 2s.c  om*/
 * @param <T>
 *            the generic type
 * @param <V>
 *            the value type
 * @param map
 *            the map
 * @return true, if successful
 */
public static <T, V> boolean hasElements(Map<T, V> map) {
    return (null != map && map.size() > 0);
}

From source file:Main.java

public static <K> Map<K, String> trimMapValue(Map<K, String> map) {
    Map<K, String> covertedResult = new HashMap<K, String>(map.size());

    Set<Entry<K, String>> entrySet = map.entrySet();
    for (Entry<K, String> entry : entrySet) {
        covertedResult.put(entry.getKey(), entry.getValue().trim());
    }/* w ww .ja  v  a2 s  . c om*/
    return covertedResult;
}

From source file:Main.java

public static void writeStringMap(Map<String, String> map, Parcel parcel) {
    if (map != null && map.size() > 0) {
        parcel.writeInt(map.size());/* ww w  .java 2s.  c  o m*/
        for (Map.Entry<String, String> entry : map.entrySet()) {
            parcel.writeString(entry.getKey());
            parcel.writeString(entry.getValue());
        }
    } else {
        parcel.writeInt(0);
    }
}

From source file:Main.java

@SuppressWarnings("rawtypes")
public static boolean isNotEmpty(Map map) {

    boolean result = false;

    if (null != map && 0 < map.size()) {
        result = true;//from   w  w  w.  j a v a 2s  . c  om
    }

    return result;
}