Example usage for java.util Map isEmpty

List of usage examples for java.util Map isEmpty

Introduction

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

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this map contains no key-value mappings.

Usage

From source file:Main.java

/**
 *
 * @param map/*from w w  w  .  j  a v a  2s  . c  o m*/
 * @return
 */
public static boolean isEmpty(Map map) {
    if (null == map) {
        return true;
    } else if (map.isEmpty()) {
        return true;
    }
    return false;
}

From source file:Main.java

@SuppressWarnings("rawtypes")
public static boolean isEmpty(Object array) {
    if (null != array) {
        if (array instanceof List) {
            List list = (List) array;
            if (!list.isEmpty()) {
                return false;
            }/* w w  w . j av  a 2s  .c  o m*/
        } else if (array instanceof Map) {
            Map map = (Map) array;
            if (!map.isEmpty()) {
                return false;
            }
        } else if (array instanceof Object[]) {
            Object[] arr = (Object[]) array;
            if (arr.length > 0) {
                return false;
            }
        }
    }

    return true;
}

From source file:Main.java

public static boolean isEmpty(final Map<?, ?> m) {
    return m == null || m.isEmpty();
}

From source file:Main.java

/**
 * Utility method to check for a not empty {@link Map} including a null check.
 *
 * @param map {@link Map} to test for non empty
 * @param <K> Type of Key in Map//  www  . jav a 2 s  . c o m
 * @param <V> Type of Value in Map
 * @return true if map is not null and has at least one entry.
 */
public static <K, V> boolean isNotEmpty(final Map<K, V> map) {
    return map != null && !map.isEmpty();
}

From source file:Main.java

public static <K, V> String toString(Map<K, V> paramMap) {
    if (paramMap == null)
        return "";
    if (paramMap.isEmpty())
        return "{}";
    StringBuilder localStringBuilder = new StringBuilder();
    Iterator localIterator = paramMap.entrySet().iterator();
    while (localIterator.hasNext()) {
        Map.Entry localEntry = (Map.Entry) localIterator.next();
        Object[] arrayOfObject = new Object[2];
        arrayOfObject[0] = localEntry.getKey().toString();
        arrayOfObject[1] = localEntry.getValue().toString();
        localStringBuilder.append(String.format(", %s -> %s ", arrayOfObject));
    }/*from w w w .j  a  v  a2 s  . co m*/
    return "{" + localStringBuilder.substring(1) + "}";
}

From source file:Main.java

/**
 * Check if map is not <tt>null</tt> and empty
 * //from  ww  w  . j  ava 2 s  . c  o  m
 * @param map
 *          map to check
 * 
 * @return <tt>true</tt>, if map is not null and empty, else <tt>false</tt>
 */
public static <K, V> boolean isEmpty(final Map<K, V> map) {
    return map != null && map.isEmpty();
}

From source file:com.github.yongchristophertang.engine.AssertUtils.java

/**
 * Assert a map of <K, V> is not empty.
 *///from  w ww .  j ava  2 s . c  o  m
public static <K, V> void mapNotEmpty(Map<K, V> map, String message) {
    if (map.isEmpty()) {
        throw new IllegalArgumentException(message);
    }
}

From source file:com.zxy.commons.mongodb.MongodbUtils.java

/**
 * ?/* w w  w  .  j a v a 2  s  .  c  om*/
 *
 * @param params params
 * @return Query
 */
public static Query getQuery(Map<String, Object> params) {
    if (params == null || params.isEmpty()) {
        return null;
    }
    List<Criteria> criterias = new ArrayList<>();
    for (Map.Entry<String, Object> entry : params.entrySet()) {
        criterias.add(Criteria.where(entry.getKey()).is(entry.getValue()));
    }
    return new Query(new Criteria().andOperator(criterias.toArray(new Criteria[params.size()])));

}

From source file:Main.java

/**
 * Tells if a given map is null or empty.
 *
 * @param map The map to be evaluated.//ww  w  .  j a v a2 s. c o m
 * @return {@code true} if the given map is null or empty.
 */
public static boolean isEmptyOrNull(final Map<?, ?> map) {
    return map == null || map.isEmpty();
}

From source file:Main.java

public static boolean isNotEmpty(Map<?, ?> map) {
    if (map == null) {
        return false;
    }//from   w w w.ja  va 2 s.co  m
    return !map.isEmpty();
}