assert Collection Not Empty - Java java.util

Java examples for java.util:Collection Size

Description

assert Collection Not Empty

Demo Code


//package com.java2s;
import java.util.Collection;

public class Main {
    public static void main(String[] argv) {
        Collection collection = java.util.Arrays.asList("asdf",
                "java2s.com");
        assertNotEmpty(collection);//from w  w w. j av a 2  s . c  o m
    }

    /**
     *
     * @param collection
     */
    public static void assertNotEmpty(Collection<?> collection) {
        if (collection == null || collection.size() == 0) {
            throw new IllegalArgumentException(
                    "'collection' must not be null or empty");
        }
    }

    /**
     *
     * @param array
     */
    public static void assertNotEmpty(Object[] array) {
        if (array == null || array.length == 0) {
            throw new IllegalArgumentException(
                    "'array' must not be null or empty");
        }
    }
}

Related Tutorials