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

/**
 * @return <code>coll</code> if it is non-null and non-empty. Otherwise,
 * returns a list with a single null value.
 *//*  w w w.  jav a  2 s. c o m*/
private static Collection<String> emptyAsSingletonNull(Collection<String> coll) {
    if (coll == null || coll.isEmpty()) {
        return Collections.singletonList(null);
    } else {
        return coll;
    }
}

From source file:Main.java

/**
 * *************************************************************
 *//*from w w  w .j a va  2s . c  o  m*/

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

From source file:Main.java

/**
 * Utility method to check if a collection is null or empty
 * /*from   w ww  .  j  a  va 2s.c o  m*/
 * @param collection
 * @return
 */
public static boolean isNullOrEmpty(Collection<?> collection) {
    if (collection == null || collection.isEmpty())
        return true;
    return false;
}

From source file:Main.java

@SuppressWarnings("rawtypes")
public static boolean isNotEmpty(Collection collection) {
    return (collection != null) && !(collection.isEmpty());
}

From source file:Main.java

/**
 * INTERNAL: Gets the first object in the collection. If the
 * collection does not contain any elements NoSuchElementException
 * is thrown.<p>/* w w w.  ja v a2 s  .c om*/
 *
 * @since 1.3.4
 */
public static <T> T getFirstElement(Collection<T> coll) {
    if ((coll == null) || coll.isEmpty())
        throw new NoSuchElementException();
    return coll.iterator().next();
}

From source file:Main.java

/**
 * Return the last element of a collection. This method iterates over the complete collection to found
 * the last element./*from   w ww .  j  ava 2 s.c om*/
 *
 * @param collection The collection to get the last element from.
 * @param <T> The type of value.
 * @return The last element of the collection. If there is no element, the method return null.
 */
public static <T> T last(Collection<T> collection) {
    if (collection.isEmpty()) {
        return null;
    }

    Iterator<T> iterator = collection.iterator();

    for (int i = 0; i < collection.size() - 1; i++) {
        iterator.next();
    }

    return iterator.next();
}

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

public static Collection Coalesce(Collection collection, Collection alternative) {
    if (collection != null && !collection.isEmpty())
        return collection;
    return alternative;
}