Here you can find the source of isNotEmpty(T collection, String exceptionMessage)
Parameter | Description |
---|---|
collection | The collection to be validated. |
exceptionMessage | The message of the exception that is thrown if the collection does not contain an element. |
T | The type of the collection. |
public static <T extends Collection<?>> T isNotEmpty(T collection, String exceptionMessage)
//package com.java2s; //License from project: Apache License import java.util.*; public class Main { /**// www. j ava 2s .com * Validates that a collection is not empty. * * @param collection The collection to be validated. * @param exceptionMessage The message of the exception that is thrown if the collection does not contain an element. * @param <T> The type of the collection. * @return The same collection that was validated. */ public static <T extends Collection<?>> T isNotEmpty(T collection, String exceptionMessage) { if (collection.size() == 0) { throw new IllegalArgumentException(exceptionMessage); } return collection; } }