Java Assert Not Null assertNotNullOrThrowException(final Object... objects)

Here you can find the source of assertNotNullOrThrowException(final Object... objects)

Description

assert Not Null Or Throw Exception

License

Open Source License

Parameter

Parameter Description
objects - The list of objects to check.

Exception

Parameter Description
IllegalArgumentException If at least one of the specified objectsis <tt>null</tt>.

Declaration

public static void assertNotNullOrThrowException(final Object... objects) throws IllegalArgumentException 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**/*  w  w w. ja  v a  2s  . com*/
     * @param objects - The list of objects to check.
     * @throws IllegalArgumentException If at least one of the specified objects
     *             is <tt>null</tt>.
     * @see #assertNotNull(Object...)
     * @throws IllegalArgumentException If at least one of the specified objects
     *             is <tt>null</tt>.
     */
    public static void assertNotNullOrThrowException(final Object... objects) throws IllegalArgumentException {
        if (!assertNotNull(objects))
            throw new IllegalArgumentException("Cannot be null !");
    }

    /**
     * @param objects - The list of objects to check.
     * @return <code>true</code> if none of the objects is <code>null</code>,
     *         <code>false</code> otherwise.
     */
    public static boolean assertNotNull(final Object... objects) {
        for (Object obj : objects) {
            if (obj == null) {
                return false;
            }
        }
        return true;
    }
}

Related

  1. assertNotNull(T value, String message)
  2. assertNotNullArg(Object value, String argName)
  3. assertNotNullArgument(Object obj, String argName)
  4. assertNotNullEightBytes(byte[] bytes)
  5. assertNotNullNotEmpty(String obj, String paramName)
  6. assertObjectNotNull(final Object object)
  7. assertObjectNotNull(Object o, String name)
  8. assertObjectNotNull(String variableName, Object value)
  9. assertObjectNotNull(String variableName, Object value)