Here you can find the source of nullOrEmptyToDefault(final Collection
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 |
public static <T> Collection<T> nullOrEmptyToDefault(final Collection<T> collection, final Collection<T> defaultValue)
//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; } }