commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rafael Santini" <raf...@santini.eti.br>
Subject Re: ObjectUtils
Date Mon, 08 Jul 2013 17:01:44 GMT
Hi,

The proposed method is related to objects. As we have StringUtils.isBlank(), 
isNotBlank(), isEmpty() etc., the ObjectUtils.isNotNull(Object... objs) is 
intended to check if all objects are not null. So, instead of

if (obj1 != null && obj2 != null && obj3 != null && obj4 != null)
{
    // Do something...
}

we have

if (isNotNull(obj1, obj2, obj3, obj4) {
    // Do something...
}

The StringUtils.firstNonNull() returns the first object that is not null 
(equivalent to something that returns true if there is at least one object 
that is not null). The isNotNull() returns true if all objects are not null.

Rafael Santini

-----Mensagem Original----- 
From: Matt Benson
Sent: Monday, July 08, 2013 1:20 PM
To: Commons Developers List
Subject: Re: Lang: ObjectUtils

WRT #firstNonNull, I don't know why I couldn't find it before.  I do now,
and I agree it would seem to fit better in ArrayUtils.

Matt


On Mon, Jul 8, 2013 at 10:04 AM, Jörg Schaible
<Joerg.Schaible@scalaris.com>wrote:

> Hi Matt,
>
> Matt Benson wrote:
>
> > On Mon, Jul 8, 2013 at 8:22 AM, Jörg Schaible
> > <Joerg.Schaible@scalaris.com>wrote:
> >
> >> Hi Hen,
> >>
> >> Henri Yandell wrote:
> >>
> >> > I don't see any value having the first two methods - replacing the
> '=='
> >> > sign is a bit too far in the 'provide simple methods' direction I
> think
> >> :)
> >> >
> >> > I think the third method is already in Lang as:
> >> >
> >> >     ArrayUtils.contains(array, null);
> >>
> >>
> >> Well, no, this is not, what the method does!
> >
> >
> > Correct, but to be fair, it's simple enough to use this method to
> > implement
> > the desired check.  Negate the result.
> >
> >
> >> With Lang we could use now:
> >>
> >>     ObjectUtils.firstNotNull(array) != null
> >>
> >
> > I don't see such a method as this.
>
>
> http://commons.apache.org/proper/commons-lang/javadocs/api-release/org/apache/commons/lang3/ObjectUtils.html#firstNonNull(T..
> .)
>
> > If it did exist, it still wouldn't
> > implement the feature requested (check that no element of the array is
> > null).  I'm pretty sure !ArrayUtils.contains(array, null) is fine.
>
> I've re-read the original code and you're right.
>
> - Jörg
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message