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

From source file:Main.java

public static boolean isEmpty(Collection<?> collection) {

    if (null == collection || collection.isEmpty() || collection.size() <= 0)
        return true;
    return false;
}

From source file:Main.java

/**
 * Check if collection is null or empty.
 * @param collection The collection to check
 * @return true if collection is null or empty and false if isn't null <b>and</b> have one or more elements
 */// w w  w .  ja  va 2 s .  c  om
public static final boolean isEmpty(Collection<?> collection) {
    return (collection == null || collection.isEmpty());
}

From source file:Main.java

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

From source file:Main.java

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

From source file:Main.java

/**
 * Returns whether specified collection is empty or not.
 *
 * @param collection collection to process
 * @return true if specified collection is empty, false otherwise
 *///from w  w  w .ja  v a  2  s.c  o  m
public static boolean isEmpty(final Collection collection) {
    return collection == null || collection.isEmpty();
}

From source file:Main.java

/**
 * Provides a wrapper to create a list out of a collection
 * @param wrappedCollection nullable collection
 * @param <T> type parameter of collection and resulting list
 * @return list of Ts from wrappedCollection or empty list
 *//*from  www. j  a v  a2  s  .  c o m*/
public static <T> List<T> listFrom(Collection<T> wrappedCollection) {
    if (wrappedCollection == null || wrappedCollection.isEmpty()) {
        return new ArrayList<T>();
    } else {
        return new ArrayList<T>(wrappedCollection);
    }
}

From source file:Main.java

/**
 * get random elements from a collection
 *
 * @param <T>//ww w . j av  a  2 s  .  c o  m
 * @param elements
 * @return
 */
public static <T> T getRandomElement(Collection<T> elements) {
    if (elements == null || elements.isEmpty()) {
        throw new IllegalArgumentException(" collection must have element!");
    }
    random.setSeed(System.currentTimeMillis());
    int offset = random.nextInt() % elements.size();
    for (T element : elements) {
        if (offset == 0) {
            return element;
        }
        offset--;
    }

    return null;
}

From source file:Main.java

public static <I, T extends Collection<I>> T shallowCloneTo(Collection<I> srcCollection, T destCollection) {
    if (srcCollection == null || srcCollection.isEmpty())
        return destCollection;
    destCollection.addAll(srcCollection);
    return destCollection;
}

From source file:Main.java

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