/** * Checks if {@code value} is <code>null</code> providing an additional * message. * * @param name the name of the argument of error reporting. Not used if no * exception is thrown. May be <code>null</code>, although not * recommended. * @param value the value of the argument to check to be not <code>null</code> * . * @param message the message to pass to the exception as additional * information to the standard message being generated. * @throws NullPointerException if {@code value} is <code>null</code>. */ public static void checkNotNull(final String name, final Object value, final String message) throws NullPointerException { if (value == null) { throw new NullArgumentException(name, message); } }
/** * Checks if {@code value} is <code>null</code> providing an additional * message. * * @param name the name of the argument of error reporting. Not used if no * exception is thrown. May be <code>null</code>, although not * recommended. * @param value the value of the argument to check to be not {@code null}. * @param message the message to pass to the exception as additional * information to the standard message being generated. * @return the passed in {@code value}. * @throws NullPointerException if {@code value} is <code>null</code>. * @param <T> the type of the argument to check. */ public static <T> T checkNotNull(final String name, final T value, final String message) throws NullPointerException { if (value == null) { throw new NullArgumentException(name, message); } return value; }
/** * Checks if {@code value} is blank providing an additional message. * * @param name the name of the argument of error reporting. Not used if no * exception is thrown. May be <code>null</code>, although not * recommended. * @param value the value of the argument to check to be not blank. * @param message the message to pass to the exception as additional * information to the standard message being generated. * @return the passed in {@code value}. * @throws NullArgumentException if {@code value} is <code>null</code>. * @throws BlankArgumentException if {@code value} is blank. * @param <T> a character sequence like a {@link String}. */ public static <T extends CharSequence> T checkNotBlank(final String name, final T value, final String message) throws NullArgumentException, BlankArgumentException { if (value == null) { throw new NullArgumentException(name, message); } if (isBlank(value)) { throw new BlankArgumentException(name, message); } return value; }