/** * Ensures that an {@code Iterable} object passed as a parameter to the * calling method is not null and contains no null elements. * * @param iterable the iterable to check the contents of * @return the non-null {@code iterable} reference just validated * @throws NullPointerException if {@code iterable} is null or contains at * least one null element */ public static <T extends Iterable<?>> T checkContentsNotNull(T iterable) { if (containsOrIsNull(iterable)) { throw new NullPointerException(); } return iterable; }
/** * Ensures that an {@code Iterable} object passed as a parameter to the * calling method is not null and contains no null elements. * * @param iterable the iterable to check the contents of * @param errorMessage the exception message to use if the check fails; will * be converted to a string using {@link String#valueOf(Object)} * @return the non-null {@code iterable} reference just validated * @throws NullPointerException if {@code iterable} is null or contains at * least one null element */ public static <T extends Iterable<?>> T checkContentsNotNull( T iterable, Object errorMessage) { if (containsOrIsNull(iterable)) { throw new NullPointerException(String.valueOf(errorMessage)); } return iterable; }
/** * Ensures that an {@code Iterable} object passed as a parameter to the * calling method is not null and contains no null elements. * * @param iterable the iterable to check the contents of * @param errorMessageTemplate a template for the exception message should the * check fail. The message is formed by replacing each {@code %s} * placeholder in the template with an argument. These are matched by * position - the first {@code %s} gets {@code errorMessageArgs[0]}, etc. * Unmatched arguments will be appended to the formatted message in square * braces. Unmatched placeholders will be left as-is. * @param errorMessageArgs the arguments to be substituted into the message * template. Arguments are converted to strings using * {@link String#valueOf(Object)}. * @return the non-null {@code iterable} reference just validated * @throws NullPointerException if {@code iterable} is null or contains at * least one null element */ public static <T extends Iterable<?>> T checkContentsNotNull(T iterable, String errorMessageTemplate, Object... errorMessageArgs) { if (containsOrIsNull(iterable)) { throw new NullPointerException( format(errorMessageTemplate, errorMessageArgs)); } return iterable; }