commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Yandell (JIRA)" <>
Subject [jira] Commented: (LANG-531) Add defaultIfEmpty or nullIfEmpty to ArrayUtils
Date Thu, 15 Oct 2009 08:02:31 GMT


Henri Yandell commented on LANG-531:

On reflection, my patch isn't what you were asking for. I created:

+    public static <T> T[] defaultIfNull(T[] array, T[] defaultValue) {
+        return array != null ? array : defaultValue;
+    }

Thinking that that allows you to set a default value if array is null. I'm not sure you were
asking for that - feels more that you were asking for:

+    public static <T> T[] defaultIfEmpty(T[] array, T[] defaultValue) {
+        return (array != null && array.length != 0) ? array : defaultValue;
+    }

Which you would call as:   array = defaultIfEmpty(array, null)

That seems a little odd to me. To consider an empty array to be bad and want to override it
with something else (such as null as you're suggesting above). Am I understanding correctly
what you wanted?

> Add defaultIfEmpty or nullIfEmpty to ArrayUtils
> -----------------------------------------------
>                 Key: LANG-531
>                 URL:
>             Project: Commons Lang
>          Issue Type: Improvement
>    Affects Versions: 2.4
>            Reporter: Guy Rouillier
>            Priority: Minor
>             Fix For: 3.0
>         Attachments: LANG-531.patch
> StringUtils has method defaultIfEmpty and ObjectUtils has defaultIfNull.  A parallel
method is missing from ArrayUtils, and would provide a shorthand way of normalizing arrays.
 My first inclination was nullIfEmpty because no simple default value is readily available
or easy to specify.  But Henri mentioned that defaultIfEmpty might better parallel the other
implementations.  That option would work okay for me, as I can just specify null as the default.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message