You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Guy Rouillier (JIRA)" <ji...@apache.org> on 2009/09/11 03:31:57 UTC

[jira] Created: (LANG-531) Add defaultIfEmpty or nullIfEmpty to ArrayUtils

Add defaultIfEmpty or nullIfEmpty to ArrayUtils
-----------------------------------------------

                 Key: LANG-531
                 URL: https://issues.apache.org/jira/browse/LANG-531
             Project: Commons Lang
          Issue Type: Improvement
    Affects Versions: 2.4
            Reporter: Guy Rouillier
            Priority: Minor


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.


[jira] Updated: (LANG-531) Add defaultIfEmpty or nullIfEmpty to ArrayUtils

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-531?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell updated LANG-531:
-------------------------------

    Attachment: LANG-531.patch

Adding patch.

> Add defaultIfEmpty or nullIfEmpty to ArrayUtils
> -----------------------------------------------
>
>                 Key: LANG-531
>                 URL: https://issues.apache.org/jira/browse/LANG-531
>             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.


[jira] Closed: (LANG-531) Add defaultIfEmpty or nullIfEmpty to ArrayUtils

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-531?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell closed LANG-531.
------------------------------

    Resolution: Won't Fix

Resolving as wontfix. No interest shown on list - I think the nullIfEmpty use case isn't a very common one. It's common to protect from null, rather than introduce null.

> Add defaultIfEmpty or nullIfEmpty to ArrayUtils
> -----------------------------------------------
>
>                 Key: LANG-531
>                 URL: https://issues.apache.org/jira/browse/LANG-531
>             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.


[jira] Updated: (LANG-531) Add defaultIfEmpty or nullIfEmpty to ArrayUtils

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-531?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell updated LANG-531:
-------------------------------

    Fix Version/s: 3.0

> Add defaultIfEmpty or nullIfEmpty to ArrayUtils
> -----------------------------------------------
>
>                 Key: LANG-531
>                 URL: https://issues.apache.org/jira/browse/LANG-531
>             Project: Commons Lang
>          Issue Type: Improvement
>    Affects Versions: 2.4
>            Reporter: Guy Rouillier
>            Priority: Minor
>             Fix For: 3.0
>
>
> 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.


[jira] Commented: (LANG-531) Add defaultIfEmpty or nullIfEmpty to ArrayUtils

Posted by "Guy Rouillier (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-531?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12766134#action_12766134 ] 

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: https://issues.apache.org/jira/browse/LANG-531
>             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.


[jira] Commented: (LANG-531) Add defaultIfEmpty or nullIfEmpty to ArrayUtils

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-531?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12765955#action_12765955 ] 

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: https://issues.apache.org/jira/browse/LANG-531
>             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.