Java Collection Empty nullOrEmptyToDefault(final Collection collection, final Collection defaultValue)

Here you can find the source of nullOrEmptyToDefault(final Collection collection, final Collection defaultValue)

Description

Returns the given collection or the given default collection if the collection is null or empty

License

Educational Community License

Parameter

Parameter Description
collection the collection to test null and empty for
defaultValue the collection to return if the given collection is null or empty
T the collection element type

Return

the given collection or the given default collection if the collection is null or empty

Declaration

public static <T> Collection<T> nullOrEmptyToDefault(final Collection<T> collection,
        final Collection<T> defaultValue) 

Method Source Code

//package com.java2s;
//License from project: Educational Community License 

import java.util.Collection;

public class Main {
    /**//from   w  w  w .jav  a  2 s . c om
     * Returns the given collection or the given default collection if the collection is null or empty
     *
     * @param collection   the collection to test null and empty for
     * @param defaultValue the collection to return if the given collection is null or empty
     * @param <T>          the collection element type
     * @return the given collection or the given default collection if the collection is null or empty
     */
    public static <T> Collection<T> nullOrEmptyToDefault(final Collection<T> collection,
            final Collection<T> defaultValue) {
        if (collection == null || collection.isEmpty()) {
            return defaultValue;
        }
        return collection;
    }
}

Related

  1. isNullOrEmpty(T collection)
  2. nullOrEmpty(Collection coll)
  3. nullOrEmpty(Collection tested)
  4. nullOrEmpty(Collection c)
  5. nullOrEmpty(final Collection in)
  6. nullToEmpty(Collection c)
  7. nullToEmpty(Collection coll)
  8. orEmpty(T collection)
  9. removeEmptyStrings(Collection data)