You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2019/02/24 10:03:34 UTC

[GitHub] dekelpilli commented on a change in pull request #357: Proposal for LANG-1421

dekelpilli commented on a change in pull request #357: Proposal for LANG-1421
URL: https://github.com/apache/commons-lang/pull/357#discussion_r259612512
 
 

 ##########
 File path: src/main/java/org/apache/commons/lang3/ObjectUtils.java
 ##########
 @@ -275,6 +315,45 @@ public static boolean allNotNull(final Object... values) {
         return true;
     }
 
+    /**
+     * Checks if all values in the array are {@code nulls}.
+     *
+     * <p>
+     * If any value is not {@code null}, the array is {@code null} or the array is empty (contains no elements) then
+     * {@code false} is returned. If all elements in array are {@code null} {@code true} is returned.
+     * </p>
+     *
+     * <pre>
+     * ObjectUtils.allNull(*)                = false
+     * ObjectUtils.allNull(*, *)             = false
+     * ObjectUtils.allNull(null)             = true
+     * ObjectUtils.allNull(null, null)       = true
+     * ObjectUtils.allNull(null, *)          = false
+     * ObjectUtils.allNull(*, null)          = false
+     * ObjectUtils.allNull(*, *, null, *)    = false
+     * ObjectUtils.allNull()                 = false
+     * ObjectUtils.allNull((Object[]) null)  = false
+     * </pre>
+     *
+     * @param values  the values to test, may be {@code null} or empty
+     * @return {@code false} if there is at least one non {@code null} value in the array, the array is {@code null}
+     * or array contains no elements, {@code true} if all values in the array are {@code null}s .
+     * @since 3.9
+     */
+    public static boolean allNull(final Object... values) {
+        if (values == null || values.length == 0) {
+            return false;
+        }
+
+        for (final Object val : values) {
 
 Review comment:
   This can be replaced by `return firstNonNull(values) == null`, although then you're doubling up on the null check.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services