Example usage for java.util Collection isEmpty

List of usage examples for java.util Collection isEmpty

Introduction

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

Prototype

boolean isEmpty();

Source Link

Document

Returns true if this collection contains no elements.

Usage

From source file:Main.java

public static boolean isEmpty(final Collection<?> collection) {
    return (collection == null || collection.isEmpty());
}

From source file:Main.java

public static <T> T firstElementOf(final Collection<? extends T> items) {
    if (items != null && !items.isEmpty()) {
        return items.iterator().next();
    }//from   w  w  w. j a  va2 s.  com
    return null;
}

From source file:Main.java

/**
 * Checks if the collection is null or empty.
 * @param <T> a type of element of collection
 * @param parameter the collection/*www . ja va2 s . com*/
 * @return true if the collection is null or empty
 */
public static <T> boolean isEmpty(final Collection<T> parameter) {
    return parameter == null || parameter.isEmpty();
}

From source file:Main.java

/*************************** empty ****************************************/

public static <T> boolean isEmpty(Collection<T> collection) {
    return collection == null || collection.isEmpty();
}

From source file:Main.java

/**
 * /*from  w w w .  ja  va  2  s .  com*/
 * @Title: isNotEmpty
 * @author:  wuwh 
 *
 * <p>check collection is empty</p>
 *
 * <pre>
 * CollectionUtil.isNotEmpty(null)   = false
 * Map.put("ddd","ddd");
 * CollectionUtil.isNotEmpty(Map)=true
 * </pre>
 *
 */
public static boolean isNotEmpty(Collection collection) {
    return null != collection && !collection.isEmpty() ? true : false;
}

From source file:Main.java

private static <V> List<V> getIndexedValuesFrom(Collection<V> arg, int initial) {
    if (null == arg || arg.isEmpty()) {
        return Collections.EMPTY_LIST;
    }/*from  ww  w.j av a 2  s. co  m*/

    List<V> indexed = new ArrayList<V>();

    for (V each : arg) {
        initial++;
        if (initial % 2 == 0) {
            continue;
        }
        indexed.add(each);
    }
    return indexed;
}

From source file:Main.java

/**
 * Tests whether c contains no elements, true if c is null or c is empty.
 * @param c Collection to test.//from ww w.j  a  va 2s .co m
 * @return Whether c contains no elements.
 */

public static boolean isNullOrEmpty(@Nullable final Collection c) {
    return c == null || c.isEmpty();
}

From source file:Main.java

/**
 * Test if a {@link Collection} is empty
 *
 * @param <T>/*from w  w  w .  j a  va  2  s  .c o  m*/
 *            the class of the objects in the list
 * @param collection
 *            Collection to test
 * @return true if collection is empty or null
 * @since 4.2
 */
public static <T> boolean isEmpty(@Nullable final Collection<T> collection) {
    return (collection == null) || collection.isEmpty();
}

From source file:Main.java

/**
 * Returns <code>true</code> if <code>collection</code> is <code>null</code>
 * or its size <code>== 0</code>.
 *///from   w  ww  .  ja v a2s. c  o m
public static <T> boolean isNullOrEmpty(Collection<T> collection) {
    if ((collection == null) || collection.isEmpty()) {
        return true;
    }

    return false;
}

From source file:Main.java

public static boolean stringMatchesAnyRegex(String s, Collection<Pattern> regexes) {
    if (s == null || regexes == null || regexes.isEmpty()) {
        return false;
    }//from   ww  w.  j  a v a  2s  .c o  m

    for (Pattern regex : regexes) {
        if (regex.matcher(s).matches())
            return true;
    }

    return false;
}