From 3745c67bd2cbd80ccc59c4d31214a9bbecc8507a Mon Sep 17 00:00:00 2001 From: Henri Yandell Date: Thu, 10 Dec 2009 12:28:15 +0000 Subject: [PATCH] Making noNullElements methods take Iterable types rather than Collection types. LANG-548 git-svn-id: https://svn.apache.org/repos/asf/commons/proper/lang/trunk@889235 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/commons/lang3/Validate.java | 38 +++++++++---------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/java/org/apache/commons/lang3/Validate.java b/src/java/org/apache/commons/lang3/Validate.java index 36672315b..1b9838a60 100644 --- a/src/java/org/apache/commons/lang3/Validate.java +++ b/src/java/org/apache/commons/lang3/Validate.java @@ -553,61 +553,61 @@ public class Validate { //--------------------------------------------------------------------------------- /** - *

Validate that the specified argument collection is neither + *

Validate that the specified argument iterable is neither * null nor contains any elements that are null; * otherwise throwing an exception with the specified message. * *

Validate.noNullElements(myCollection, "The collection contains null at position %d");
* - *

If the collection is null, then the message in the exception + *

If the iterable is null, then the message in the exception * is "The validated object is null".

* - *

If the collection has a null element, then the iteration + *

If the iterable has a null element, then the iteration * index of the invalid element is appended to the values * argument.

* - * @param the collection type - * @param collection the collection to check - * @return the validated collection (never null method for chaining) + * @param the iterable type + * @param iterable the iterable to check + * @return the validated iterable (never null method for chaining) * @throws NullPointerException if the array is null * @throws IllegalArgumentException if an element is null - * @see #noNullElements(Collection, String, Object...) + * @see #noNullElements(Iterable) */ - public static > T noNullElements(T collection, String message, Object... values) { - Validate.notNull(collection); + public static > T noNullElements(T iterable, String message, Object... values) { + Validate.notNull(iterable); int i = 0; - for (Iterator it = collection.iterator(); it.hasNext(); i++) { + for (Iterator it = iterable.iterator(); it.hasNext(); i++) { if (it.next() == null) { Object[] values2 = ArrayUtils.addAll(values, i); throw new IllegalArgumentException(String.format(message, values2)); } } - return collection; + return iterable; } /** - *

Validate that the specified argument collection is neither + *

Validate that the specified argument iterable is neither * null nor contains any elements that are null; * otherwise throwing an exception. * *

Validate.noNullElements(myCollection);
* - *

If the collection is null, then the message in the exception + *

If the iterable is null, then the message in the exception * is "The validated object is null".

* *

If the array has a null element, then the message in the - * exception is "The validated collection contains null element at index: + * exception is "The validated iterable contains null element at index: * " followed by the index.

* - * @param the collection type - * @param collection the collection to check - * @return the validated collection (never null method for chaining) + * @param the iterable type + * @param iterable the iterable to check + * @return the validated iterable (never null method for chaining) * @throws NullPointerException if the array is null * @throws IllegalArgumentException if an element is null * @see #noNullElements(Collection, String, Object...) */ - public static > T noNullElements(T collection) { - return noNullElements(collection, DEFAULT_NO_NULL_ELEMENTS_COLLECTION_EXCEPTION_MESSAGE); + public static > T noNullElements(T iterable) { + return noNullElements(iterable, DEFAULT_NO_NULL_ELEMENTS_COLLECTION_EXCEPTION_MESSAGE); } // validIndex array