commons-issues mailing list archives

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


Guy Rouillier commented on LANG-531:

Yes, you are understanding correctly.  For me, the benefit of these defaultIfEmpty() methods
is to scrub incoming data.  If I have a data bean and one of its members is an array, then
the set method needs to look something like this:

void setMyArray(Object[] array) {
   this.array = ArrayUtils.isEmpty(array) ? null, array;

Instead, the following is a little bit more intuitive:

   this.array = ArrayUtils.nullIfEmpty(array);

So, I originally suggested nullIfEmpty, but Henri thought defaultIfEmpty would better parallel
other Utils classes.

> 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