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 isNotEmpty(final Collection<?> c) {
    return c != null && c.isEmpty() == false;
}

From source file:Main.java

/**
 * Returns a collection with the common elements in c1 and c2
 * @param <T>/* w  w w .  ja  v a  2s  . com*/
 * @param c1
 * @param c2
 * @return
 */
public static <T> Collection<T> intersect(Collection<T> c1, Collection<T> c2) {

    if (c1.isEmpty() || c2.isEmpty()) {
        return Collections.emptySet();
    }

    if (!(c2 instanceof Set) && (c1 instanceof Set || c1.size() > c2.size())) {
        //swap
        Collection<T> tmp = c1;
        c1 = c2;
        c2 = tmp;
    }

    Collection<T> result = new HashSet<T>();
    for (T obj : c1) {
        if (c2.contains(obj)) {
            result.add(obj);
        }
    }

    return result;
}

From source file:Main.java

public static boolean isEmpty(Collection<?> collection) {
    boolean result = false;
    if (collection == null || collection.isEmpty()) {
        result = true;/*from  ww w. jav a2  s .  co m*/
    }
    return result;
}

From source file:Main.java

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

From source file:Main.java

/**
 * Enforce that a Collection contains no more than one element and return that element
 * if it exists./* ww  w. ja va  2  s.  c  o  m*/
 * 
 * @param collection the Collection to examine
 * @return null if the Collection is null or empty, the Collection's single object if
 *       its size is one, or throw if its size is greater than one.
 * @throws IllegalArgumentException if the Collection contains more than one element
 */
public static <T> T singleObject(Collection<T> collection) {
    if (collection == null || collection.isEmpty())
        return null;
    if (collection.size() > 1)
        throw new IllegalArgumentException("more than one element in collection");
    return collection.iterator().next();
}

From source file:Main.java

public static boolean isEmptyOrNull(Collection<?> collection) {
    boolean retorno = false;
    if (null == collection || collection.isEmpty()) {
        retorno = true;//from  w w w  .  ja v a2 s.  c o m
    }
    return retorno;
}

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

public static boolean isEmpty(Collection collection)
/*  58:    */ {//  w  w w . j  a v  a  2  s. c o m
    /*  59:132 */return (collection == null) || (collection.isEmpty());
    /*  60:    */}

From source file:Main.java

public static boolean isEmpty(Collection<?> paramCollection) {
    if ((paramCollection == null) || (paramCollection.isEmpty()))
        ;//from w  ww .  jav  a  2s .  c o  m
    for (boolean bool = true;; bool = false)
        return bool;
}