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 isCollectionEmpty(Collection<?> collection) {
    return collection == null || collection.isEmpty();
}

From source file:Main.java

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

From source file:Main.java

/**
 * Null-safe check if the specified collection is empty.
 * <p>/*from   w w w. ja v  a 2s  .com*/
 * Null returns true.
 * 
 * @param coll
 *            the collection to check, may be null
 * @return true if empty or null
 * @since Commons Collections 3.2
 */
public static <E> boolean isEmpty(Collection<E> coll) {
    return (coll == null || coll.isEmpty());
}

From source file:Main.java

/**
 * Remove all object from collection to other collection
 * @param <T>/* w w  w .  j  av a2  s.c o  m*/
 * @param from source collection
 * @param to target collection
 */
public static <T> void moveAllObject(Collection<T> from, Collection<T> to) {
    if (!from.isEmpty()) {
        to.addAll(from);
        from.clear();
    }
}

From source file:Main.java

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

}

From source file:Main.java

/**
 * Checks if an input collection contains a given value.
 *
 * @param <A> Key type//from w  w  w.ja  v a 2s . com
 * @param collection Input collection
 * @param value Value to search
 * @return {@code true} if {@code value} is present in {@code collection}, and {@code false} otherwise. If {@code collection} is empty, it will return {@code false}
 */
public static <A> boolean contains(Collection<A> collection, A value) {
    if (collection.isEmpty())
        return false;

    for (A item : collection)
        if (item == value)
            return true;

    return false;
}

From source file:Main.java

public static <E> boolean isEmpty(Collection<E> collection) {
    if (collection == null || collection.isEmpty()) {
        return true;
    }/*ww  w. ja  va2 s.co  m*/
    Iterator<E> it = collection.iterator();
    while (it.hasNext()) {
        E type = (E) it.next();
        if (type != null) {
            return false;
        }
    }
    return true;
}

From source file:Main.java

/**
 * Implementation of the OCL// w  ww  .jav a 2 s  . c  om
 * <ul>
 * <li><tt>OrderedSet::lset() : T</tt></li>
 * <li><tt>Sequence::lset() : T</tt></li>
 * </ul>
 * operations.
 * 
 * @param self the source collection
 * @return the last object in the source collection
 */
public static <E> E last(Collection<E> self) {
    if (self.isEmpty()) {
        return null; // undefined
    }
    E result = null;
    for (E next : self) {
        result = next;
    }
    return result;
}

From source file:Main.java

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

From source file:Main.java

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