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:com.thoughtworks.go.server.domain.user.FilterValidator.java

static void validateDefaultIsPresent(Map<String, DashboardFilter> current) {
    if (current.isEmpty())
        throw new FilterValidationException(MSG_NO_DEFAULT_FILTER);
}

From source file:Main.java

/**
 * Checks passed {@link Map} instance on null and emptiness returns true if
 * it is not null and is not empty/*from  ww w  .j  av a2  s.  c o m*/
 * 
 * @param map
 * @return <code>boolean</code>
 */
public static boolean valid(Map<?, ?> map) {
    return (map != null && !map.isEmpty());
}

From source file:Main.java

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

From source file:Main.java

public static boolean isCheckMapState(Map<String, String> value) {
    if (value == null) {
        return false;
    }/* w ww.j  av a  2  s  . c om*/
    if (value.isEmpty()) {
        return false;

    }
    if (value.containsKey("status") && value.get("status").equals("0")) {
        return true;
    } else {
        return false;
    }

}

From source file:Main.java

/**
 * Join the two given maps to one by checking if one of the two maps already fulfills everything. Be aware that the
 * newly created collection is unmodifiable but will change if the underlying collections change!
 *
 * @param <K>    The key type/*from www . ja  v a 2 s . com*/
 * @param <V>    The value type
 * @param first  The first {@link Map} to join
 * @param second The second {@link Map} to join
 *
 * @return A {@link Map} with the joined content (can be one of the given map if the other is empty or null)
 */
public static <K, V> Map<K, V> joinMapUnmodifiable(Map<K, V> first, Map<K, V> second) {
    if (first == null || first.isEmpty()) {
        if (second == null || second.isEmpty()) {
            return Collections.emptyMap();
        } else {
            return Collections.unmodifiableMap(second);
        }
    } else if (second == null || second.isEmpty()) {
        return Collections.unmodifiableMap(first);
    } else {
        Map<K, V> temp = new LinkedHashMap<K, V>(first.size() + second.size());
        temp.putAll(first);
        temp.putAll(second);
        return Collections.unmodifiableMap(temp);
    }
}

From source file:Main.java

/**
 * Return {@code true} if the supplied Map is {@code null} or empty.
 * Otherwise, return {@code false}.//from w  w w . j  ava 2s .  c  o  m
 *
 * @param map the Map to check
 * @return whether the given Map is empty
 */
public static boolean isEmpty(Map<?, ?> map) {
    return (map == null || map.isEmpty());
}

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();
    }/*from  www  .jav  a 2 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

/**
 * Dumps XML attributes out to the specified writer
 *
 * @param out the writer/*from ww  w . j av a 2 s.  c om*/
 * @param attributes the attributes
 * @throws IOException
 */
public static void dumpAttributes(Writer out, Map attributes) throws IOException {
    if ((attributes == null) || (attributes.isEmpty())) {
        return;
    }

    Iterator it = attributes.entrySet().iterator();
    Map.Entry me;
    String value;

    while (it.hasNext()) {
        me = (Map.Entry) it.next();
        value = (String) me.getValue();

        if (value != null) {
            out.write(' ');
            out.write((String) me.getKey());
            out.write("=\"");
            out.write(value);
            out.write('"');
        }
    }
}

From source file:Main.java

/**
 * Build a List from the entry set of a map.
 * //  www  . ja  v a2s .co  m
 *  <p>
 * NOTE: This should not be necessary but there are bugs
 * when you iterate using map.entrySet().iterator().
 * </p>
 * 
 * @param map the map to use as the source
 * @param sortedByValue whether or not to sort the values
 * of the created list
 * @return a list containing all values of the given
 * map
 */
public static List mapToEntryList(Map map, boolean sortedByValue) {
    List retList = new ArrayList();
    if (map.isEmpty()) {
        return Collections.EMPTY_LIST;
    }
    Iterator it = map.keySet().iterator();
    while (it.hasNext()) {
        Object key = it.next();
        Object obj = map.get(key);
        retList.add(obj);
    }

    // Sort
    if (sortedByValue)
        Collections.sort(retList);
    return retList;
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static String toXML(Object obj) {
    Map<String, Object> map = (Map<String, Object>) obj;
    if (map == null || map.isEmpty()) {
        return MAP_EMPTY;
    }//  w  w  w .  j a  v  a  2 s. c  om
    StringBuilder sb = new StringBuilder();
    sb.append(MAP_OPEN);
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        addEntry(sb, entry.getKey(), entry.getValue() == null ? "" : entry.getValue().toString());
    }
    sb.append(MAP_CLOSE);
    return sb.toString();
}